A webapp/form for people to join pEp coop. Fork of Cultural Commons Collecting Society (C3S) SCE
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.

__init__.py 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. # -*- coding: utf-8 -*-
  2. """
  3. This module holds the main method: config and route declarations
  4. """
  5. import os
  6. from pyramid.authentication import AuthTktAuthenticationPolicy
  7. from pyramid.authorization import ACLAuthorizationPolicy
  8. from pyramid.config import Configurator
  9. from pyramid_beaker import session_factory_from_settings
  10. from sqlalchemy import engine_from_config
  11. from c3smembership.data.model.base import Base
  12. from c3smembership.security.request import RequestWithUserAttribute
  13. from c3smembership.security import (
  14. Root,
  15. groupfinder
  16. )
  17. from c3smembership.presentation.views.dashboard import (
  18. dashboard_content_size_provider
  19. )
  20. from c3smembership.presentation.views.membership_listing import (
  21. membership_content_size_provider
  22. )
  23. from c3smembership.i18n import enforcing_locale_negotiator
  24. __version__ = open(os.path.join(os.path.abspath(
  25. os.path.dirname(__file__)), '../VERSION')).read()
  26. def main(global_config, **settings):
  27. """ This function returns a Pyramid WSGI application.
  28. """
  29. engine = engine_from_config(settings, 'sqlalchemy.')
  30. session_factory = session_factory_from_settings(settings)
  31. authn_policy = AuthTktAuthenticationPolicy(
  32. 's0secret!!',
  33. callback=groupfinder,)
  34. authz_policy = ACLAuthorizationPolicy()
  35. Base.metadata.bind = engine
  36. config = Configurator(settings=settings,
  37. authentication_policy=authn_policy,
  38. authorization_policy=authz_policy,
  39. session_factory=session_factory,
  40. root_factory=Root)
  41. # using a custom request with user information
  42. config.set_request_factory(RequestWithUserAttribute)
  43. config.set_locale_negotiator(enforcing_locale_negotiator)
  44. config.include('pyramid_mailer')
  45. config.include('pyramid_chameleon')
  46. config.include('cornice')
  47. config.include('c3smembership.presentation.pagination')
  48. config.add_translation_dirs(
  49. 'colander:locale/',
  50. 'deform:locale/',
  51. 'c3smembership:../customization/locale/')
  52. config.add_static_view('static_deform', 'deform:static')
  53. config.add_static_view(
  54. 'static',
  55. 'c3smembership:static', cache_max_age=3600)
  56. config.add_static_view(
  57. 'docs',
  58. '../docs/_build/html/', cache_max_age=3600)
  59. config.add_subscriber('c3smembership.subscribers.add_base_template',
  60. 'pyramid.events.BeforeRender')
  61. config.add_subscriber(
  62. 'c3smembership.subscribers.add_base_bootstrap_template',
  63. 'pyramid.events.BeforeRender')
  64. config.add_subscriber('c3smembership.subscribers.add_backend_template',
  65. 'pyramid.events.BeforeRender')
  66. config.add_subscriber('c3smembership.subscribers.add_locale_to_cookie',
  67. 'pyramid.events.NewRequest')
  68. config.add_renderer(name='csv',
  69. factory='c3smembership.renderers.CSVRenderer')
  70. from c3smembership.data.repository.share_repository import ShareRepository
  71. from c3smembership.business.share_acquisition import ShareAcquisition
  72. share_acquisition = ShareAcquisition(ShareRepository)
  73. config.registry.share_acquisition = share_acquisition
  74. from pyramid_mailer import get_mailer
  75. config.registry.get_mailer = get_mailer
  76. # Membership application process
  77. # Step 1 (join.pt): home is /, the membership application form
  78. config.add_route('join', '/')
  79. # Step 2 (success.pt): check and edit data
  80. config.add_route('success', '/success')
  81. # Step 3 email was sent (check-mail.pt): send verification email address
  82. config.add_route('success_check_email', '/check_email')
  83. # Still step 3 (verify_password.pt): enter password
  84. # and step 4 (verify_password.pt): download form
  85. config.add_route('verify_email_password', '/verify/{email}/{code}') # PDF
  86. # PDF download of Step 4.
  87. config.add_route('success_pdf', '/C3S_SCE_AFM_{namepart}.pdf') # download
  88. # confirm email address later (30c3 cases)
  89. config.add_route(
  90. 'verify_afm_email',
  91. '/vae/{refcode}/{token}/{email}') # verify afm email
  92. # applications for membership
  93. config.add_route('dashboard', '/dashboard')
  94. config.make_pagination_route(
  95. 'dashboard',
  96. dashboard_content_size_provider,
  97. sort_property_default='id',
  98. page_size_default=int(
  99. settings.get('c3smembership.dashboard_number', 30)))
  100. config.add_route('dash', '/dash/{number}/{orderby}/{order}')
  101. config.add_route('toolbox', '/toolbox')
  102. config.add_route('stats', '/stats')
  103. config.add_route('staff', '/staff')
  104. config.add_route('new_member', '/new_member')
  105. config.add_route('detail', '/detail/{memberid}')
  106. config.add_route('edit', '/edit/{_id}')
  107. # TODO: move application layer setup to separate module
  108. from c3smembership.data.repository.member_repository import (
  109. MemberRepository
  110. )
  111. from c3smembership.business.membership_application import (
  112. MembershipApplication
  113. )
  114. membership_application = MembershipApplication(MemberRepository)
  115. config.registry.membership_application = membership_application
  116. config.add_route('switch_sig', '/switch_sig/{memberid}')
  117. config.add_route('switch_pay', '/switch_pay/{memberid}')
  118. config.add_route('mail_sig_confirmation', '/mail_sig_conf/{memberid}')
  119. config.add_route('regenerate_pdf', '/re_C3S_SCE_AFM_{code}.pdf')
  120. config.add_route('mail_pay_confirmation', '/mail_pay_conf/{member_id}')
  121. config.add_route('mail_mail_confirmation', '/mail_mail_conf/{memberid}')
  122. config.add_route('mail_sig_reminder', '/mail_sig_reminder/{memberid}')
  123. config.add_route('mail_pay_reminder', '/mail_pay_reminder/{memberid}')
  124. config.add_route('delete_entry', '/delete/{memberid}')
  125. config.add_route('delete_afms', '/delete_afms')
  126. config.add_route('login', '/login')
  127. config.add_route('logout', '/logout')
  128. # gather missing information
  129. config.add_route('mail_mtype_form', '/mtype/{afmid}') # mail link to form
  130. config.add_route('mtype_form', '/mtype/{refcode}/{token}/{email}') # form
  131. config.add_route('mtype_thanks', '/mtype_thanks') # thanks
  132. # applications for membership
  133. config.add_route('afms_awaiting_approval', '/afms_awaiting_approval')
  134. # memberships
  135. config.add_route('make_member', '/make_member/{afm_id}')
  136. config.add_route('merge_member', '/merge_member/{afm_id}/{mid}')
  137. config.add_route('membership_listing_backend',
  138. '/memberships')
  139. config.make_pagination_route(
  140. 'membership_listing_backend',
  141. membership_content_size_provider,
  142. sort_property_default='id',
  143. page_size_default=int(
  144. settings.get('c3smembership.membership_number', 30)))
  145. config.add_route('membership_listing_alphabetical',
  146. '/aml')
  147. # membership list
  148. from c3smembership.data.repository.member_repository import (
  149. MemberRepository
  150. )
  151. from c3smembership.business.member_information import MemberInformation
  152. config.registry.member_information = MemberInformation(MemberRepository)
  153. config.add_route('membership_listing_date_pdf',
  154. '/aml-{date}.pdf')
  155. config.add_route('membership_listing_aufstockers',
  156. '/aml_aufstockers')
  157. # membership dues 2015
  158. config.add_route('send_dues15_invoice_email',
  159. '/dues15_invoice/{member_id}')
  160. config.add_route('send_dues15_invoice_batch', '/dues15_invoice_batch')
  161. config.add_route('make_dues15_invoice_no_pdf',
  162. '/dues15_invoice_no/{code}/C3S-dues15-{i}.pdf')
  163. # for backward compatibility
  164. config.add_route('make_dues15_invoice_no_pdf_email',
  165. '/dues15_invoice_no/{email}/{code}/C3S-dues15-{i}.pdf')
  166. config.add_route('dues15_reduction',
  167. '/dues15_reduction/{member_id}')
  168. config.add_route('make_dues15_reversal_invoice_pdf',
  169. '/dues15_reversal/{code}/C3S-dues15-{no}-S.pdf')
  170. # for backward compatibility
  171. config.add_route('make_dues15_reversal_invoice_pdf_email',
  172. '/dues15_reversal/{email}/{code}/C3S-dues15-{no}-S.pdf')
  173. config.add_route('dues15_notice', '/dues15_notice/{member_id}')
  174. config.add_route('dues15_listing', '/dues15_listing')
  175. # membership dues 2016
  176. config.add_route('send_dues16_invoice_email',
  177. '/dues16_invoice/{member_id}')
  178. config.add_route('send_dues16_invoice_batch', '/dues16_invoice_batch')
  179. config.add_route('make_dues16_invoice_no_pdf',
  180. '/dues16_invoice_no/{code}/C3S-dues16-{i}.pdf')
  181. # for backward compatibility
  182. config.add_route('make_dues16_invoice_no_pdf_email',
  183. '/dues16_invoice_no/{email}/{code}/C3S-dues16-{i}.pdf')
  184. config.add_route('dues16_reduction',
  185. '/dues16_reduction/{member_id}')
  186. config.add_route('make_dues16_reversal_invoice_pdf',
  187. '/dues16_reversal/{code}/C3S-dues16-{no}-S.pdf')
  188. # for backward compatibility
  189. config.add_route('make_dues16_reversal_invoice_pdf_email',
  190. '/dues16_reversal/{email}/{code}/C3S-dues16-{no}-S.pdf')
  191. config.add_route('dues16_notice', '/dues16_notice/{member_id}')
  192. config.add_route('dues16_listing', '/dues16_listing')
  193. # membership dues 2017
  194. config.add_route('send_dues17_invoice_email',
  195. '/dues17_invoice/{member_id}')
  196. config.add_route('send_dues17_invoice_batch', '/dues17_invoice_batch')
  197. config.add_route('make_dues17_invoice_no_pdf',
  198. '/dues17_invoice_no/{code}/C3S-dues17-{i}.pdf')
  199. config.add_route('dues17_reduction',
  200. '/dues17_reduction/{member_id}')
  201. config.add_route('make_dues17_reversal_invoice_pdf',
  202. '/dues17_reversal/{code}/C3S-dues17-{no}-S.pdf')
  203. config.add_route('dues17_notice', '/dues17_notice/{member_id}')
  204. config.add_route('dues17_listing', '/dues17_listing')
  205. # TODO: move application layer setup to separate module
  206. from c3smembership.models import C3sMember
  207. from c3smembership.models import Dues15Invoice
  208. from c3smembership.data.model.base import DBSession
  209. from c3smembership.business.dues_invoice_archiving import (
  210. DuesInvoiceArchiving
  211. )
  212. from c3smembership.views.membership_dues import (
  213. make_invoice_pdf_pdflatex,
  214. make_reversal_pdf_pdflatex,
  215. )
  216. invoices_archive_path = os.path.abspath(
  217. os.path.join(
  218. os.path.dirname(os.path.abspath(__file__)),
  219. '../invoices/'))
  220. config.registry.dues_invoice_archiving = DuesInvoiceArchiving(
  221. DBSession,
  222. C3sMember,
  223. Dues15Invoice,
  224. make_invoice_pdf_pdflatex,
  225. make_reversal_pdf_pdflatex,
  226. invoices_archive_path)
  227. config.add_route(
  228. 'batch_archive_pdf_invoices',
  229. '/batch_archive_pdf_invoices')
  230. # utilities & wizardry
  231. config.add_route('plz_dist', '/plz_dist')
  232. config.add_route('get_member', '/members/{member_id}')
  233. config.add_route('error_page', '/error') # generic error view
  234. # shares
  235. config.add_route('shares_detail', '/shares_detail/{id}')
  236. config.add_route('shares_edit', '/shares_edit/{id}')
  237. config.add_route('shares_delete', '/shares_delete/{id}')
  238. # membership_certificate
  239. config.add_route('certificate_mail', '/cert_mail/{id}')
  240. config.add_route('certificate_pdf', '/cert/{id}/C3S_{name}_{token}.pdf')
  241. config.add_route('certificate_pdf_staff', '/cert/{id}/C3S_{name}.pdf')
  242. # annual reports
  243. from c3smembership.data.repository.share_repository import ShareRepository
  244. from c3smembership.business.share_information import ShareInformation
  245. config.registry.share_information = ShareInformation(ShareRepository)
  246. config.add_route('annual_reporting', '/annual_reporting')
  247. # invite people
  248. config.add_route('invite_member', '/invite_member/{m_id}')
  249. config.add_route('invite_batch', '/invite_batch/{number}')
  250. # search for people
  251. config.add_route('search_people', '/search_people')
  252. config.add_route('autocomplete_people_search', '/aps/')
  253. # search for codes
  254. config.add_route('search_codes', '/search_codes')
  255. config.add_route('autocomplete_input_values', '/aiv/')
  256. config.scan()
  257. return config.make_wsgi_app()