source: main/waeup.kofa/trunk/src/waeup/kofa/applicants/viewlets.py @ 17055

Last change on this file since 17055 was 16231, checked in by Henrik Bettermann, 4 years ago

Implement ContactApplicantFormPage.

  • Property svn:keywords set to Id
File size: 11.8 KB
Line 
1## $Id: viewlets.py 16231 2020-09-10 07:22:19Z 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##
18import grok
19from waeup.kofa.interfaces import IKofaObject
20from waeup.kofa.students.viewlets import PrimaryStudentNavTab
21from waeup.kofa.browser.viewlets import (
22    ManageActionButton, PrimaryNavTab, AddActionButton)
23from waeup.kofa.applicants.interfaces import (
24    IApplicant, IApplicantsRoot, IApplicantsContainer,
25    IApplicantOnlinePayment, IApplicantRefereeReport
26    )
27from waeup.kofa.applicants.browser import (
28    ApplicantsRootPage, ApplicantsContainerPage, ApplicantManageFormPage,
29    ApplicantDisplayFormPage, OnlinePaymentDisplayFormPage,
30    ApplicantsContainerManageFormPage, ApplicantsStatisticsPage,
31    RefereeReportDisplayFormPage
32    )
33
34from waeup.kofa.interfaces import MessageFactory as _
35
36grok.context(IKofaObject) # Make IKofaObject the default context
37grok.templatedir('browser_templates')
38
39class 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
52class 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
69class 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
86class 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
95class 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
102class 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
111class 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
119class 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
128class 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
137class 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
146class ApplicantsContainerStatisticsActionButton2(
147        ApplicantsContainerStatisticsActionButton):
148    grok.order(5)
149    grok.view(ApplicantsContainerPage)
150
151class 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
159class 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
170creation_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
179class 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
192class 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
205class 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
213class 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
221class 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
239class PDFActionButton(ManageActionButton):
240    grok.order(3)
241    grok.context(IApplicant)
242    grok.require('waeup.viewApplication')
243    grok.name('pdfactionbutton')
244    grok.view(ApplicantDisplayFormPage)
245    icon = 'actionicon_pdf.png'
246    text = _('Download application slip')
247    target = 'application_slip.pdf'
248
249    @property
250    def target_url(self):
251        """Get a URL to the target...
252        """
253        if self.context.state in ('initialized', 'started', 'paid') \
254            or self.context.special:
255            return
256        return self.view.url(self.view.context, self.target)
257
258class StudentCreateActionButton(ManageActionButton):
259    grok.order(4)
260    grok.context(IApplicant)
261    grok.require('waeup.createStudents')
262    icon = 'actionicon_entrance.png'
263    text = _('Create student')
264    target ='createstudent'
265
266    @property
267    def target_url(self):
268        """Get a URL to the target...
269        """
270        if self.context.state != 'admitted':
271            return
272        return self.view.url(self.view.context, self.target)
273
274class RemindRefereesActionButton(ManageActionButton):
275    grok.order(5)
276    grok.context(IApplicant)
277    grok.require('waeup.manageApplication')
278    grok.view(ApplicantDisplayFormPage)
279    icon = 'actionicon_alarm.png'
280    text = _('Remind referees')
281    target ='remind_referees'
282
283    @property
284    def onclick(self):
285        return "return window.confirm(%s);" % _(
286            "'Those referees, who have not yet submitted their report, will be reminded by email. Are you sure?'")
287
288    @property
289    def target_url(self):
290        """Get a URL to the target...
291        """
292        if self.context.state != 'submitted':
293            return
294        if not self.context.referees:
295            return
296        return self.view.url(self.view.context, self.target)
297
298class ContactActionButton(ManageActionButton):
299    grok.order(6)
300    grok.context(IApplicant)
301    grok.view(ApplicantDisplayFormPage)
302    grok.require('waeup.viewApplication')
303    icon = 'actionicon_mail.png'
304    text = _('Send email')
305    target = 'contactapplicant'
306
307class PaymentReceiptActionButton(ManageActionButton):
308    grok.order(9) # This button should always be the last one.
309    grok.context(IApplicantOnlinePayment)
310    grok.view(OnlinePaymentDisplayFormPage)
311    grok.require('waeup.viewApplication')
312    icon = 'actionicon_pdf.png'
313    text = _('Download payment slip')
314    target = 'payment_slip.pdf'
315
316    @property
317    def target_url(self):
318        #if self.context.p_state != 'paid':
319        #    return ''
320        return self.view.url(self.view.context, self.target)
321
322class ApprovePaymentActionButton(ManageActionButton):
323    grok.order(8)
324    grok.context(IApplicantOnlinePayment)
325    grok.view(OnlinePaymentDisplayFormPage)
326    grok.require('waeup.managePortal')
327    icon = 'actionicon_accept.png'
328    text = _('Approve payment')
329    target = 'approve'
330
331    @property
332    def target_url(self):
333        if self.context.p_state in ('paid', 'waived', 'scholarship'):
334            return ''
335        return self.view.url(self.view.context, self.target)
336
337class ReportSlipActionButton(ManageActionButton):
338    grok.order(1)
339    grok.context(IApplicantRefereeReport)
340    grok.view(RefereeReportDisplayFormPage)
341    grok.require('waeup.manageApplication')
342    icon = 'actionicon_pdf.png'
343    text = _('Download referee report slip')
344    target = 'referee_report_slip.pdf'
345
346    @property
347    def target_url(self):
348        return self.view.url(self.view.context, self.target)
349
350deletion_warning = _(
351    "'The report will be irrevocably deleted. Are you sure?'")
352
353class ReportRemoveActionButton(ManageActionButton):
354    grok.order(2)
355    grok.context(IApplicantRefereeReport)
356    grok.view(RefereeReportDisplayFormPage)
357    grok.require('waeup.manageApplication')
358    icon = 'actionicon_reject.png'
359    text = _('Delete referee report')
360    target = 'remove'
361
362    @property
363    def onclick(self):
364        return "return window.confirm(%s);" % deletion_warning
Note: See TracBrowser for help on using the repository browser.