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.
 
 
 
 
 

113 lines
4.8 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 sqlalchemy import engine_from_config
  7. from .models import DBSession, get_user
  8. from .security import EntryFactory, groupfinder
  9. import locale
  10. def main(global_config, **settings):
  11. """ This function returns a Pyramid WSGI application.
  12. """
  13. locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8")
  14. engine = engine_from_config(settings, 'sqlalchemy.')
  15. DBSession.configure(bind=engine)
  16. my_session_factory = SignedCookieSessionFactory('itsaseekreet')
  17. authentication_policy = AuthTktAuthenticationPolicy('somesecret',
  18. callback=groupfinder, hashalg='sha512', debug=True)
  19. authorization_policy = ACLAuthorizationPolicy()
  20. config = Configurator(settings=settings,
  21. root_factory='.security.RootFactory',
  22. authentication_policy=authentication_policy,
  23. authorization_policy=authorization_policy
  24. )
  25. config.add_renderer('json', JSON(indent=4))
  26. config.add_renderer('jsonp', JSONP(param_name='callback'))
  27. config.set_session_factory(my_session_factory)
  28. config.add_request_method(get_user, 'user', reify=True)
  29. config.add_static_view('static', 'static', cache_max_age=3600)
  30. config.add_static_view('img', 'static/img', cache_max_age=3600)
  31. config.add_static_view('upload', 'upload', cache_max_age=3600)
  32. config.add_route('tester', '/tester')
  33. # ICal Routes
  34. config.add_route('progr_iCal', '/{year:\d+}/JM2L.ics')
  35. # JSON Routes
  36. config.add_route('users_json', '/json-users')
  37. config.add_route('tiers_json', '/json-tiers')
  38. config.add_route('progr_json', '/{year:\d+}/le-prog-json')
  39. config.add_route('timeline_json', '/{year:\d+}/timeline-json')
  40. # Session setting Routes
  41. config.add_route('year', '/year/{year:\d+}')
  42. # HTML Routes - Staff
  43. config.add_route('list_task', '/Staff')
  44. config.add_route('handle_task', '/Staff/tasks{sep:/*}{task_id:(\d+)?}')
  45. config.add_route('action_task', '/Staff/{action:(\w+)}/{task_id:(\d+)}')
  46. # HTML Routes - Public
  47. config.add_route('home', '/')
  48. config.add_route('presse', '/{year:\d+}/dossier-de-presse')
  49. config.add_route('edit_presse', '/{year:\d+}/dossier-de-presse/edit')
  50. config.add_route('programme', '/{year:\d+}/le-programme')
  51. config.add_route('plan', 'nous-rejoindre')
  52. config.add_route('participer', 'participer-l-evenement')
  53. config.add_route('captcha', '/captcha')
  54. ## Events
  55. config.add_route('event', '/event/{year:\d+}/{event_id:([\w-]+)?}')
  56. config.add_route('link_event', '/MesJM2L/{year:\d+}/{intervention:\w+}/link')
  57. config.add_route('edit_event', '/MesJM2L/{year:\d+}/{intervention:\w+}{sep:/*}{event_id:([\w-]+)?}')
  58. ## Entities
  59. config.add_route('entities', '/entities') #{sep:/*}{Nature:\w+?}')
  60. config.add_route('add_entity', '/entity')
  61. config.add_route('show_entity', '/entity/{tiers_type:(\w+)}/{entity_id:([\w-]+)?}')
  62. config.add_route('edit_entity', '/entity/{tiers_type:(\w+)}/{entity_id:([\w-]+)}/edit')
  63. config.add_route('edit_entity_cat', '/categorie/entity')
  64. ## Users
  65. config.add_route('show_user', '/user/{user_slug:([\w-]+)?}')
  66. # HTML Routes - Logged
  67. #config.add_route('profil', 'MesJM2L')
  68. config.add_route('jm2l', '/MesJM2L')
  69. config.add_route('modal', '/{year:\d+}/modal/{modtype:\w+}/{id:(\d+)}')
  70. # Handle exchanges
  71. config.add_route('exchange', '/{year:\d+}/exchange/{modtype:\w+}/{id:(\d+)}/{action:\w+}')
  72. # Handle authentication
  73. config.add_route('register', '/register')
  74. config.add_route('auth', '/sign/{action}')
  75. config.add_route('bymail', '/sign/jm2l/{hash}')
  76. # Handle Multimedia and Uploads
  77. config.add_route('media_uploadform', '/test2')
  78. config.add_route('media_view', '/image/{media_table:\w+}/{uid:\d+}/{name:.+}')
  79. config.add_route('media_upload', '/uploader/{media_table:\w+}/{uid:\d+}/proceed{sep:/*}{name:.*}')
  80. # To Trash routes
  81. config.add_route('test', '/test')
  82. config.add_route('test2', '/toast{sep:/*}{uid:(\d+)?}')
  83. #config.add_route('link_user_entity', '/entity/{uid:(\d+)}/{year:\d+}/user/{user_id:(\d+)}')
  84. #config.add_route('link_role_entity', '/entity/{uid:(\d+)}/{year:\d+}/role/{role_id:(\d+)}')
  85. config.add_route('IntAdd', '/IntAdd/{modtype:\w+}')
  86. config.add_route('IntProp', '/IntProp/{modtype:\w+}')
  87. config.add_route('blog', '/blog/{id:\d+}/{slug}')
  88. config.add_route('blog_action', '/blog/{action}',
  89. factory='jm2l.security.EntryFactory')
  90. config.scan()
  91. return config.make_wsgi_app()