1 | ## $Id: viewlets.py 16214 2020-08-26 15:39:36Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | import grok |
---|
19 | from waeup.kofa.interfaces import IKofaObject |
---|
20 | from waeup.kofa.students.viewlets import PrimaryStudentNavTab |
---|
21 | from waeup.kofa.browser.viewlets import ( |
---|
22 | ManageActionButton, PrimaryNavTab, AddActionButton) |
---|
23 | from waeup.kofa.applicants.interfaces import ( |
---|
24 | IApplicant, IApplicantsRoot, IApplicantsContainer, |
---|
25 | IApplicantOnlinePayment, IApplicantRefereeReport |
---|
26 | ) |
---|
27 | from waeup.kofa.applicants.browser import ( |
---|
28 | ApplicantsRootPage, ApplicantsContainerPage, ApplicantManageFormPage, |
---|
29 | ApplicantDisplayFormPage, OnlinePaymentDisplayFormPage, |
---|
30 | ApplicantsContainerManageFormPage, ApplicantsStatisticsPage, |
---|
31 | RefereeReportDisplayFormPage |
---|
32 | ) |
---|
33 | |
---|
34 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
35 | |
---|
36 | grok.context(IKofaObject) # Make IKofaObject the default context |
---|
37 | grok.templatedir('browser_templates') |
---|
38 | |
---|
39 | class ApplicantsAuthTab(PrimaryNavTab): |
---|
40 | """Applicants tab in primary navigation. |
---|
41 | """ |
---|
42 | grok.context(IKofaObject) |
---|
43 | grok.order(3) |
---|
44 | grok.require('waeup.viewApplicantsTab') |
---|
45 | pnav = 3 |
---|
46 | tab_title = _(u'Applicants') |
---|
47 | |
---|
48 | @property |
---|
49 | def link_target(self): |
---|
50 | return self.view.application_url('applicants') |
---|
51 | |
---|
52 | class ApplicantsAnonTab(ApplicantsAuthTab): |
---|
53 | """Applicants tab in primary navigation. |
---|
54 | |
---|
55 | Display tab only for anonymous. Authenticated users can call the |
---|
56 | form from the user navigation bar. |
---|
57 | """ |
---|
58 | grok.require('waeup.Anonymous') |
---|
59 | tab_title = _(u'Application') |
---|
60 | |
---|
61 | # Also zope.manager has role Anonymous. |
---|
62 | # To avoid displaying this tab, we have to check the principal id too. |
---|
63 | @property |
---|
64 | def link_target(self): |
---|
65 | if self.request.principal.id == 'zope.anybody': |
---|
66 | return self.view.application_url('applicants') |
---|
67 | return |
---|
68 | |
---|
69 | class MyApplicationDataTab(PrimaryStudentNavTab): |
---|
70 | """MyData-tab in primary navigation. |
---|
71 | """ |
---|
72 | grok.order(3) |
---|
73 | grok.require('waeup.viewMyApplicationDataTab') |
---|
74 | pnav = 3 |
---|
75 | tab_title = _(u'My Data') |
---|
76 | |
---|
77 | @property |
---|
78 | def link_target(self): |
---|
79 | try: |
---|
80 | container, application_number = self.request.principal.id.split('_') |
---|
81 | except ValueError: |
---|
82 | return |
---|
83 | rel_link = '/applicants/%s/%s' % (container, application_number) |
---|
84 | return self.view.application_url() + rel_link |
---|
85 | |
---|
86 | class ApplicantsRootSearchActionButton(ManageActionButton): |
---|
87 | grok.order(1) |
---|
88 | grok.context(IApplicantsRoot) |
---|
89 | grok.view(ApplicantsRootPage) |
---|
90 | grok.require('waeup.viewApplication') |
---|
91 | text = _('Find applicants') |
---|
92 | icon = 'actionicon_search.png' |
---|
93 | target = '@@search' |
---|
94 | |
---|
95 | class ApplicantsRootManageActionButton(ManageActionButton): |
---|
96 | grok.order(2) |
---|
97 | grok.context(IApplicantsRoot) |
---|
98 | grok.view(ApplicantsRootPage) |
---|
99 | grok.require('waeup.manageApplication') |
---|
100 | text = _('Manage applicants section') |
---|
101 | |
---|
102 | class ApplicantRegisterActionButton(ManageActionButton): |
---|
103 | grok.order(1) |
---|
104 | grok.context(IApplicantsContainer) |
---|
105 | grok.view(ApplicantsContainerPage) |
---|
106 | grok.require('waeup.Anonymous') |
---|
107 | icon = 'actionicon_login.png' |
---|
108 | text = _('Register for application') |
---|
109 | target = 'register' |
---|
110 | |
---|
111 | class ApplicantsContainerAddActionButton(AddActionButton): |
---|
112 | grok.order(1) |
---|
113 | grok.context(IApplicantsContainer) |
---|
114 | grok.view(ApplicantsContainerManageFormPage) |
---|
115 | grok.require('waeup.manageApplication') |
---|
116 | text = _('Add applicant') |
---|
117 | target = 'addapplicant' |
---|
118 | |
---|
119 | class ApplicantsContainerPrefillActionButton(ManageActionButton): |
---|
120 | grok.order(2) |
---|
121 | grok.context(IApplicantsContainer) |
---|
122 | grok.view(ApplicantsContainerManageFormPage) |
---|
123 | grok.require('waeup.manageApplication') |
---|
124 | icon = 'actionicon_bucketfill.png' |
---|
125 | text = _('Pre-fill container') |
---|
126 | target = 'prefill' |
---|
127 | |
---|
128 | class ApplicantsContainerPurgeActionButton(ManageActionButton): |
---|
129 | grok.order(3) |
---|
130 | grok.context(IApplicantsContainer) |
---|
131 | grok.view(ApplicantsContainerManageFormPage) |
---|
132 | grok.require('waeup.manageApplication') |
---|
133 | icon = 'actionicon_sweep.png' |
---|
134 | text = _('Purge container') |
---|
135 | target = 'purge' |
---|
136 | |
---|
137 | class ApplicantsContainerStatisticsActionButton(ManageActionButton): |
---|
138 | grok.order(4) |
---|
139 | grok.context(IApplicantsContainer) |
---|
140 | grok.view(ApplicantsContainerManageFormPage) |
---|
141 | grok.require('waeup.viewApplicationStatistics') |
---|
142 | icon = 'actionicon_statistics.png' |
---|
143 | text = _('Container statistics') |
---|
144 | target = 'statistics' |
---|
145 | |
---|
146 | class ApplicantsContainerStatisticsActionButton2( |
---|
147 | ApplicantsContainerStatisticsActionButton): |
---|
148 | grok.order(5) |
---|
149 | grok.view(ApplicantsContainerPage) |
---|
150 | |
---|
151 | class ApplicantsContainerManageActionButton(ManageActionButton): |
---|
152 | grok.order(2) |
---|
153 | grok.context(IApplicantsContainer) |
---|
154 | grok.view(ApplicantsContainerPage) |
---|
155 | grok.require('waeup.manageApplication') |
---|
156 | text = _('Manage container') |
---|
157 | target = 'manage' |
---|
158 | |
---|
159 | class ExportApplicantsActionButton(ManageActionButton): |
---|
160 | """ 'Export data' button for faculties. |
---|
161 | """ |
---|
162 | grok.context(IApplicantsContainer) |
---|
163 | grok.view(ApplicantsContainerPage) |
---|
164 | grok.require('waeup.manageApplication') |
---|
165 | icon = 'actionicon_down.png' |
---|
166 | text = _('Export application data') |
---|
167 | target = 'exports' |
---|
168 | grok.order(4) |
---|
169 | |
---|
170 | creation_warning = _( |
---|
171 | "'The creation process may take a considerably long time " |
---|
172 | "depending on the number of student records to be created " |
---|
173 | "(appr. 0.5s per student). " |
---|
174 | "All users will be logged out and the portal will be in " |
---|
175 | "maintenance mode during record creation. You will be automatically " |
---|
176 | "logged in when the creation process is finished. " |
---|
177 | "Do you really want to start now?'") |
---|
178 | |
---|
179 | class ApplicantsRootCreateStudentsActionButton(ManageActionButton): |
---|
180 | grok.order(3) |
---|
181 | grok.context(IApplicantsRoot) |
---|
182 | grok.view(ApplicantsRootPage) |
---|
183 | grok.require('waeup.createStudents') |
---|
184 | icon = 'actionicon_entrance.png' |
---|
185 | text = _('Create students') |
---|
186 | target ='createallstudents' |
---|
187 | |
---|
188 | @property |
---|
189 | def onclick(self): |
---|
190 | return "return window.confirm(%s);" % creation_warning |
---|
191 | |
---|
192 | class ApplicantsContainerCreateStudentsActionButton(ManageActionButton): |
---|
193 | grok.order(5) |
---|
194 | grok.context(IApplicantsContainer) |
---|
195 | grok.view(ApplicantsContainerPage) |
---|
196 | grok.require('waeup.createStudents') |
---|
197 | icon = 'actionicon_entrance.png' |
---|
198 | text = _('Create students') |
---|
199 | target ='createallstudents' |
---|
200 | |
---|
201 | @property |
---|
202 | def onclick(self): |
---|
203 | return "return window.confirm(%s);" % creation_warning |
---|
204 | |
---|
205 | class ApplicantViewActionButton(ManageActionButton): |
---|
206 | grok.context(IApplicant) |
---|
207 | grok.view(ApplicantManageFormPage) |
---|
208 | grok.require('waeup.viewApplication') |
---|
209 | icon = 'actionicon_view.png' |
---|
210 | text = _('View application record') |
---|
211 | target = 'index' |
---|
212 | |
---|
213 | class ApplicantManageActionButton(ManageActionButton): |
---|
214 | grok.order(1) |
---|
215 | grok.context(IApplicant) |
---|
216 | grok.view(ApplicantDisplayFormPage) |
---|
217 | grok.require('waeup.manageApplication') |
---|
218 | text = _('Manage application record') |
---|
219 | target = 'manage' |
---|
220 | |
---|
221 | class ApplicantEditActionButton(ManageActionButton): |
---|
222 | grok.order(2) |
---|
223 | grok.context(IApplicant) |
---|
224 | grok.view(ApplicantDisplayFormPage) |
---|
225 | grok.require('waeup.handleApplication') |
---|
226 | text = _('Edit application record') |
---|
227 | target ='edit' |
---|
228 | |
---|
229 | @property |
---|
230 | def target_url(self): |
---|
231 | """Get a URL to the target... |
---|
232 | """ |
---|
233 | if self.context.locked or ( |
---|
234 | self.context.__parent__.expired and |
---|
235 | self.context.__parent__.strict_deadline): |
---|
236 | return |
---|
237 | return self.view.url(self.view.context, self.target) |
---|
238 | |
---|
239 | class PDFActionButton(ManageActionButton): |
---|
240 | grok.order(3) |
---|
241 | grok.context(IApplicant) |
---|
242 | grok.require('waeup.viewApplication') |
---|
243 | grok.name('pdfactionbutton') |
---|
244 | icon = 'actionicon_pdf.png' |
---|
245 | text = _('Download application slip') |
---|
246 | target = 'application_slip.pdf' |
---|
247 | |
---|
248 | @property |
---|
249 | def target_url(self): |
---|
250 | """Get a URL to the target... |
---|
251 | """ |
---|
252 | if self.context.state in ('initialized', 'started', 'paid') \ |
---|
253 | or self.context.special: |
---|
254 | return |
---|
255 | return self.view.url(self.view.context, self.target) |
---|
256 | |
---|
257 | class StudentCreateActionButton(ManageActionButton): |
---|
258 | grok.order(4) |
---|
259 | grok.context(IApplicant) |
---|
260 | grok.require('waeup.createStudents') |
---|
261 | icon = 'actionicon_entrance.png' |
---|
262 | text = _('Create student') |
---|
263 | target ='createstudent' |
---|
264 | |
---|
265 | @property |
---|
266 | def target_url(self): |
---|
267 | """Get a URL to the target... |
---|
268 | """ |
---|
269 | if self.context.state != 'admitted': |
---|
270 | return |
---|
271 | return self.view.url(self.view.context, self.target) |
---|
272 | |
---|
273 | class RemindRefereesActionButton(ManageActionButton): |
---|
274 | grok.order(5) |
---|
275 | grok.context(IApplicant) |
---|
276 | grok.require('waeup.manageApplication') |
---|
277 | icon = 'actionicon_alarm.png' |
---|
278 | text = _('Remind referees') |
---|
279 | target ='remind_referees' |
---|
280 | |
---|
281 | @property |
---|
282 | def onclick(self): |
---|
283 | return "return window.confirm(%s);" % _( |
---|
284 | "'Those referees, who have not yet submitted their report, will be reminded by email. Are you sure?'") |
---|
285 | |
---|
286 | @property |
---|
287 | def target_url(self): |
---|
288 | """Get a URL to the target... |
---|
289 | """ |
---|
290 | if self.context.state != 'submitted': |
---|
291 | return |
---|
292 | if not self.context.referees: |
---|
293 | return |
---|
294 | return self.view.url(self.view.context, self.target) |
---|
295 | |
---|
296 | class PaymentReceiptActionButton(ManageActionButton): |
---|
297 | grok.order(9) # This button should always be the last one. |
---|
298 | grok.context(IApplicantOnlinePayment) |
---|
299 | grok.view(OnlinePaymentDisplayFormPage) |
---|
300 | grok.require('waeup.viewApplication') |
---|
301 | icon = 'actionicon_pdf.png' |
---|
302 | text = _('Download payment slip') |
---|
303 | target = 'payment_slip.pdf' |
---|
304 | |
---|
305 | @property |
---|
306 | def target_url(self): |
---|
307 | #if self.context.p_state != 'paid': |
---|
308 | # return '' |
---|
309 | return self.view.url(self.view.context, self.target) |
---|
310 | |
---|
311 | class ApprovePaymentActionButton(ManageActionButton): |
---|
312 | grok.order(8) |
---|
313 | grok.context(IApplicantOnlinePayment) |
---|
314 | grok.view(OnlinePaymentDisplayFormPage) |
---|
315 | grok.require('waeup.managePortal') |
---|
316 | icon = 'actionicon_accept.png' |
---|
317 | text = _('Approve payment') |
---|
318 | target = 'approve' |
---|
319 | |
---|
320 | @property |
---|
321 | def target_url(self): |
---|
322 | if self.context.p_state in ('paid', 'waived', 'scholarship'): |
---|
323 | return '' |
---|
324 | return self.view.url(self.view.context, self.target) |
---|
325 | |
---|
326 | class ReportSlipActionButton(ManageActionButton): |
---|
327 | grok.order(1) |
---|
328 | grok.context(IApplicantRefereeReport) |
---|
329 | grok.view(RefereeReportDisplayFormPage) |
---|
330 | grok.require('waeup.manageApplication') |
---|
331 | icon = 'actionicon_pdf.png' |
---|
332 | text = _('Download referee report slip') |
---|
333 | target = 'referee_report_slip.pdf' |
---|
334 | |
---|
335 | @property |
---|
336 | def target_url(self): |
---|
337 | return self.view.url(self.view.context, self.target) |
---|
338 | |
---|
339 | deletion_warning = _( |
---|
340 | "'The report will be irrevocably deleted. Are you sure?'") |
---|
341 | |
---|
342 | class ReportRemoveActionButton(ManageActionButton): |
---|
343 | grok.order(2) |
---|
344 | grok.context(IApplicantRefereeReport) |
---|
345 | grok.view(RefereeReportDisplayFormPage) |
---|
346 | grok.require('waeup.manageApplication') |
---|
347 | icon = 'actionicon_reject.png' |
---|
348 | text = _('Delete referee report') |
---|
349 | target = 'remove' |
---|
350 | |
---|
351 | @property |
---|
352 | def onclick(self): |
---|
353 | return "return window.confirm(%s);" % deletion_warning |
---|