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.
 
 
 
 
 

133 lines
6.2 KiB

  1. from pyramid.authentication import AuthTktAuthenticationPolicy
  2. from pyramid.authorization import ACLAuthorizationPolicy
  3. from pyramid.config import Configurator
  4. from pyramid.renderers import JSON, JSONP
  5. from pyramid.session import SignedCookieSessionFactory
  6. from pyramid.events import BeforeRender
  7. from sqlalchemy import engine_from_config
  8. from pyramid.renderers import render_to_response
  9. from .models import DBSession, get_user, get_sponsors, get_exposants
  10. from .security import EntryFactory, groupfinder
  11. from pyramid_mailer import mailer_factory_from_settings
  12. import locale
  13. from .helpers import Sejour_helpers
  14. def add_renderer_globals(event):
  15. event['mytrip'] = Sejour_helpers(event)
  16. def main(global_config, **settings):
  17. """ This function returns a Pyramid WSGI application.
  18. """
  19. locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8")
  20. engine = engine_from_config(settings, 'sqlalchemy.')
  21. DBSession.configure(bind=engine)
  22. # Extract secrets from configuration file if any
  23. CookiesPasswd = settings.get('secret_Cookies', 'itsthefirstseekreet')
  24. AuthTktPasswd = settings.get('secret_AuthTkt', 'itsthesecondseekreet')
  25. my_session_factory = SignedCookieSessionFactory(CookiesPasswd)
  26. authentication_policy = AuthTktAuthenticationPolicy(AuthTktPasswd,
  27. callback=groupfinder, hashalg='sha512', debug=True)
  28. authorization_policy = ACLAuthorizationPolicy()
  29. config = Configurator(settings=settings,
  30. root_factory='.security.RootFactory',
  31. authentication_policy=authentication_policy,
  32. authorization_policy=authorization_policy
  33. )
  34. config.add_subscriber(add_renderer_globals, BeforeRender)
  35. config.registry['mailer'] = mailer_factory_from_settings(settings)
  36. config.add_renderer('json', JSON(indent=4))
  37. config.add_renderer('jsonp', JSONP(param_name='callback'))
  38. config.set_session_factory(my_session_factory)
  39. config.add_request_method(get_user, 'user', reify=True)
  40. config.add_request_method(get_sponsors, 'sponsors', reify=False)
  41. config.add_request_method(get_exposants, 'exposants', reify=False)
  42. config.add_static_view('static', 'static', cache_max_age=3600)
  43. config.add_static_view('img', 'static/img', cache_max_age=3600)
  44. config.add_static_view('css', 'static/css', cache_max_age=3600)
  45. config.add_static_view('js', 'static/js', cache_max_age=3600)
  46. config.add_static_view('vendor', 'static/vendor', cache_max_age=3600)
  47. config.add_static_view('upload', 'upload', cache_max_age=3600)
  48. config.add_static_view('resources', 'resources', cache_max_age=3600)
  49. # ICal Routes
  50. config.add_route('progr_iCal', '/{year:\d+}/JM2L.ics')
  51. # JSON Routes
  52. config.add_route('users_json', '/json-users')
  53. config.add_route('tiers_json', '/json-tiers')
  54. config.add_route('progr_json', '/{year:\d+}/le-prog-json')
  55. config.add_route('timeline_json', '/{year:\d+}/timeline-json')
  56. # Session setting Routes
  57. config.add_route('year', '/year/{year:\d+}')
  58. config.add_route('vote_logo', '/vote_logo/{num:\d+}')
  59. # HTML Routes - Staff
  60. config.add_route('list_task', '/Staff')
  61. config.add_route('handle_pole', '/Staff/poles{sep:/*}{pole_id:(\d+)?}')
  62. config.add_route('handle_task', '/Staff/tasks{sep:/*}{task_id:(\d+)?}')
  63. config.add_route('action_task', '/Staff/{action:(\w+)}/{task_id:(\d+)}')
  64. config.add_route('action_task_area', '/Staff/pole/{action:(\w+)}/{pole_id:(\d+)}')
  65. config.add_route('list_salles', '/ListSalles')
  66. config.add_route('handle_salle', '/Salles{sep:/*}{salle_id:(\d+)?}')
  67. config.add_route('handle_salle_phy', '/PhySalles{sep:/*}{salle_id:(\d+)?}')
  68. config.add_route('action_salle', '/Salles/{action:(\w+)}/{salle_id:(\d+)}')
  69. config.add_route('pict_salle', '/salle_picture/{salle_id:(\d+)}')
  70. config.add_route('list_users', '/ListParticipant')
  71. # HTML Routes - Public
  72. config.add_route('home', '/{year:(\d+/)?}')
  73. config.add_route('edit_index', '/{year:\d+}/edit')
  74. config.add_route('presse', '/{year:\d+}/dossier-de-presse')
  75. config.add_route('edit_presse', '/{year:\d+}/dossier-de-presse/edit')
  76. config.add_route('programme', '/{year:\d+}/le-programme')
  77. config.add_route('plan', 'nous-rejoindre')
  78. config.add_route('participer', 'participer-l-evenement')
  79. config.add_route('captcha', '/captcha')
  80. ## Events
  81. config.add_route('event', '/event/{year:\d+}/{event_id:([\w-]+)?}')
  82. config.add_route('link_event_user', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/link_user')
  83. config.add_route('link_event_tiers', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}/link_tiers')
  84. config.add_route('edit_event', '/MesJM2L/{year:\d+}/{intervention:[\s\w]+}{sep:/*}{event_id:([\w-]+)?}')
  85. ## Entities
  86. config.add_route('entities', '/entities') #{sep:/*}{Nature:\w+?}')
  87. config.add_route('add_entity', '/entity')
  88. config.add_route('delete_entity', '/entity/{entity_id:(\d+)}/delete')
  89. config.add_route('show_entity', '/entity/{tiers_type:(\w+)}/{entity_id:([\w-]+)?}')
  90. config.add_route('edit_entity', '/entity/{tiers_type:(\w+)}/{entity_id:([\w-]+)}/edit')
  91. config.add_route('edit_entity_cat', '/categorie/entity')
  92. ## Users
  93. config.add_route('pict_user', '/user_picture')
  94. config.add_route('show_user', '/user/{user_slug:([\w-]+)?}')
  95. # HTML Routes - Logged
  96. #config.add_route('profil', 'MesJM2L')
  97. config.add_route('jm2l', '/MesJM2L')
  98. config.add_route('miam', '/MonMiam')
  99. config.add_route('sejour', '/MonSejour')
  100. config.add_route('modal', '/{year:\d+}/modal/{modtype:\w+}/{id:(\d+)}')
  101. # Handle exchanges
  102. config.add_route('exchange', '/{year:\d+}/exchange/{modtype:\w+}/{id:(\d+)}/{action:\w+}')
  103. # Handle authentication
  104. config.add_route('register', '/register')
  105. config.add_route('auth', '/sign/{action}')
  106. config.add_route('bymail', '/sign/jm2l/{hash}')
  107. # Handle Multimedia and Uploads
  108. config.add_route('media_view', '/image/{media_table:\w+}/{uid:\d+}/{name:.+}')
  109. config.add_route('media_upload', '/uploader/{media_table:\w+}/{uid:\d+}/proceed{sep:/*}{name:.*}')
  110. config.scan()
  111. return config.make_wsgi_app()