Le repo des sources pour le site web des JM2L
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

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