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