Le repo des sources pour le site web des JM2L
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

187 lines
8.9 KiB

  1. # -*- coding: utf8 -*-
  2. from pyramid.authentication import AuthTktAuthenticationPolicy
  3. from pyramid.authorization import ACLAuthorizationPolicy
  4. from pyramid.config import Configurator
  5. from pyramid.renderers import JSON, JSONP
  6. from pyramid.session import SignedCookieSessionFactory
  7. from pyramid.events import BeforeRender
  8. from sqlalchemy import engine_from_config
  9. from pyramid.renderers import render_to_response
  10. from .models import DBSession, get_user, get_sponsors, get_exposants
  11. from .security import EntryFactory, groupfinder
  12. from pyramid_mailer import mailer_factory_from_settings
  13. from pyramid_mailer.message import Attachment, Message
  14. import locale
  15. from .helpers import Sejour_helpers, Orga_helpers
  16. from apscheduler.schedulers.background import BackgroundScheduler
  17. # Database access imports
  18. from pyramid.request import Request
  19. from mako.template import Template
  20. from .models import User
  21. import logging
  22. def add_renderer_globals(event):
  23. event['mytrip'] = Sejour_helpers(event)
  24. event['myorga'] = Orga_helpers(event)
  25. #@sched.scheduled_job('cron', day_of_week='sun', hour=22, minute=07)
  26. def mailer_tasks(config):
  27. # Send the Welcome Mail
  28. mailer = config.registry['mailer']
  29. Contact = DBSession.query(User).filter(User.uid==1).one()
  30. request = Request.blank('/', base_url='http://jm2l.linux-azur.org')
  31. request.registry = config.registry
  32. for StaffUser in DBSession.query(User).filter(User.Staff == True):
  33. # Skip mail to contact
  34. if StaffUser==Contact:
  35. continue
  36. # Skip those that have no task assigned
  37. if len(filter(lambda k:not k.closed, StaffUser.task_assoc))==0:
  38. continue
  39. # Prepare Plain Text Message :
  40. Mail_template = Template(filename='jm2l/templates/mail_plain.mako')
  41. mail_plain = Mail_template.render(request=request, User=StaffUser, Contact=Contact, action="Tasks")
  42. # Prepare HTML Message :
  43. Mail_template = Template(filename='jm2l/templates/mail_html.mako')
  44. mail_html = Mail_template.render(request=request, User=StaffUser, Contact=Contact, action="Tasks")
  45. # Prepare Message
  46. message = Message(subject="[JM2L] Le mail de rappel pour les JM2L !",
  47. sender="contact@jm2l.linux-azur.org",
  48. recipients=[StaffUser.mail],
  49. body=mail_plain, html=mail_html)
  50. message.add_bcc("spam@style-python.fr")
  51. mailer.send_immediately(message)
  52. def main(global_config, **settings):
  53. """ This function returns a Pyramid WSGI application.
  54. """
  55. locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8")
  56. engine = engine_from_config(settings, 'sqlalchemy.')
  57. DBSession.configure(bind=engine)
  58. # Extract secrets from configuration file if any
  59. CookiesPasswd = settings.get('secret_Cookies', 'itsthefirstseekreet')
  60. AuthTktPasswd = settings.get('secret_AuthTkt', 'itsthesecondseekreet')
  61. my_session_factory = SignedCookieSessionFactory(CookiesPasswd)
  62. authentication_policy = AuthTktAuthenticationPolicy(AuthTktPasswd,
  63. callback=groupfinder, hashalg='sha512', debug=True)
  64. authorization_policy = ACLAuthorizationPolicy()
  65. config = Configurator(settings=settings,
  66. root_factory='.security.RootFactory',
  67. authentication_policy=authentication_policy,
  68. authorization_policy=authorization_policy
  69. )
  70. config.add_subscriber(add_renderer_globals, BeforeRender)
  71. config.registry['mailer'] = mailer_factory_from_settings(settings)
  72. sched = BackgroundScheduler()
  73. sched.add_job(mailer_tasks, 'cron', day_of_week='fri', hour=18, args=[ config ])
  74. sched.start() # start the scheduler
  75. config.add_renderer('json', JSON(indent=4))
  76. config.add_renderer('jsonp', JSONP(param_name='callback'))
  77. config.set_session_factory(my_session_factory)
  78. config.add_request_method(get_user, 'user', reify=True)
  79. config.add_request_method(get_sponsors, 'sponsors', reify=False)
  80. config.add_request_method(get_exposants, 'exposants', reify=False)
  81. config.add_static_view('static', 'static', cache_max_age=3600)
  82. config.add_static_view('img', 'static/img', cache_max_age=3600)
  83. config.add_static_view('css', 'static/css', cache_max_age=3600)
  84. config.add_static_view('js', 'static/js', cache_max_age=3600)
  85. config.add_static_view('vendor', 'static/vendor', cache_max_age=3600)
  86. config.add_static_view('upload', 'upload', cache_max_age=3600)
  87. config.add_static_view('resources', 'resources', cache_max_age=3600)
  88. # ICal Routes
  89. config.add_route('progr_iCal', '/{year:\d+}/JM2L.ics')
  90. config.add_route('progr_dyn_iCal', '/{year:\d+}/JM2L_dyn.ics')
  91. # JSON Routes
  92. config.add_route('users_json', '/json-users')
  93. config.add_route('tiers_json', '/json-tiers')
  94. config.add_route('progr_json', '/{year:\d+}/le-prog-json')
  95. config.add_route('timeline_json', '/{year:\d+}/timeline-json')
  96. # Session setting Routes
  97. config.add_route('year', '/year/{year:\d+}')
  98. config.add_route('vote_logo', '/vote_logo/{num:\d+}')
  99. # HTML Routes - Staff
  100. config.add_route('Live', '/Live')
  101. config.add_route('list_expenses', '/Staff/compta')
  102. config.add_route('list_task', '/Staff')
  103. config.add_route('handle_pole', '/Staff/poles{sep:/*}{pole_id:(\d+)?}')
  104. config.add_route('handle_task', '/Staff/tasks{sep:/*}{task_id:(\d+)?}')
  105. config.add_route('action_task', '/Staff/{action:(\w+)}/{task_id:(\d+)}')
  106. config.add_route('action_task_area', '/Staff/pole/{action:(\w+)}/{pole_id:(\d+)}')
  107. config.add_route('list_salles', '/ListSalles')
  108. config.add_route('handle_salle', '/Salles{sep:/*}{salle_id:(\d+)?}')
  109. config.add_route('handle_salle_phy', '/PhySalles{sep:/*}{salle_id:(\d+)?}')
  110. config.add_route('action_salle', '/Salles/{action:(\w+)}/{salle_id:(\d+)}')
  111. config.add_route('pict_salle', '/salle_picture/{salle_id:(\d+)}')
  112. config.add_route('list_users', '/ListParticipant')
  113. config.add_route('list_orga', '/ListOrga')
  114. # HTML Routes - Public
  115. config.add_route('home', '/{year:(\d+/)?}')
  116. config.add_route('edit_index', '/{year:\d+}/edit')
  117. config.add_route('presse', '/{year:\d+}/dossier-de-presse')
  118. config.add_route('edit_presse', '/{year:\d+}/dossier-de-presse/edit')
  119. config.add_route('programme', '/{year:\d+}/le-programme')
  120. config.add_route('plan', 'nous-rejoindre')
  121. config.add_route('participer', 'participer-l-evenement')
  122. config.add_route('captcha', '/captcha')
  123. ## Events
  124. config.add_route('event', '/event/{year:\d+}/{event_id:([\w-]+)?}')
  125. config.add_route('link_event_user', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/link_user')
  126. config.add_route('delete_link_u', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/delete_link_user')
  127. config.add_route('link_event_tiers', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/link_tiers')
  128. config.add_route('delete_link_t', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/delete_link_tiers')
  129. config.add_route('edit_event', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}{sep:/*}{event_id:([\w-]+)?}')
  130. config.add_route('delete_event', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}{sep:/*}{event_id:([\w-]+)?}/delete')
  131. ## Entities
  132. config.add_route('entities', '/entities') #{sep:/*}{Nature:\w+?}')
  133. config.add_route('add_entity', '/entity')
  134. config.add_route('delete_entity', '/entity/{entity_id:(\d+)}/delete')
  135. config.add_route('show_entity', '/entity/{tiers_type:(\w+)}/{entity_id:([\w-]+)?}')
  136. config.add_route('edit_entity', '/entity/{tiers_type:(\w+)}/{entity_id:([\w-]+)}/edit')
  137. config.add_route('edit_entity_cat', '/categorie/entity')
  138. ## Users
  139. config.add_route('pict_user', '/user_picture')
  140. config.add_route('show_user', '/user/{user_slug:([\w-]+)?}')
  141. config.add_route('badge_user', '/user/{user_slug:([\w-]+)?}/badge')
  142. config.add_route('all_badges', '/badges')
  143. config.add_route('place_print', '/place_print')
  144. config.add_route('stand_print', '/stand_print')
  145. # HTML Routes - Logged
  146. #config.add_route('profil', 'MesJM2L')
  147. config.add_route('jm2l', '/MesJM2L')
  148. config.add_route('miam', '/MonMiam')
  149. config.add_route('sejour', '/MonSejour')
  150. config.add_route('orga', '/MonOrga')
  151. config.add_route('modal', '/{year:\d+}/modal/{modtype:\w+}/{id:(\d+)}')
  152. # Handle exchanges
  153. config.add_route('exchange', '/{year:\d+}/exchange/{modtype:\w+}/{id:(\d+)}/{action:\w+}')
  154. # Handle authentication
  155. config.add_route('register', '/register')
  156. config.add_route('auth', '/sign/{action}')
  157. config.add_route('bymail', '/sign/jm2l/{hash}')
  158. # Handle Multimedia and Uploads
  159. config.add_route('media_view', '/image/{media_table:\w+}/{uid:\d+}/{name:.+}')
  160. config.add_route('media_upload', '/uploader/{media_table:\w+}/{uid:\d+}/proceed{sep:/*}{name:.*}')
  161. config.scan()
  162. return config.make_wsgi_app()