source: main/waeup.aaue/trunk/src/waeup/aaue/applicants/browser.py @ 14049

Last change on this file since 14049 was 14029, checked in by Henrik Bettermann, 9 years ago

display_actions must contain 2 elements.

  • Property svn:keywords set to Id
File size: 15.8 KB
Line 
1## $Id: browser.py 14029 2016-07-13 09:47:28Z 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"""UI components for basic applicants and related components.
19"""
20import grok
21import os
22from zope.component import getUtility, getAdapter
23from zope.i18n import translate
24from hurry.workflow.interfaces import IWorkflowState
25from waeup.kofa.interfaces import (
26    IExtFileStore, IFileStoreNameChooser, IKofaUtils)
27from zope.formlib.textwidgets import BytesDisplayWidget
28from waeup.kofa.utils.helpers import string_from_bytes, file_size
29from waeup.kofa.applicants.browser import (
30    ApplicantCheckStatusPage, ApplicantBaseDisplayFormPage)
31from waeup.kofa.applicants.workflow import STARTED, PAID
32from waeup.kofa.applicants.viewlets import PDFActionButton
33from waeup.kofa.browser.layout import UtilityView
34from waeup.kofa.students.interfaces import IStudentsUtils
35from waeup.kofa.interfaces import IPDF
36from waeup.kofa.browser.viewlets import ManageActionButton
37from waeup.aaue.interfaces import MessageFactory as _
38from kofacustom.nigeria.applicants.browser import (
39    NigeriaApplicantDisplayFormPage,
40    NigeriaApplicantManageFormPage,
41    NigeriaApplicantEditFormPage,
42    NigeriaPDFApplicationSlip,
43    NigeriaApplicantRegistrationPage,
44    NigeriaExportPDFPaymentSlipPage,
45    )
46from kofacustom.nigeria.applicants.interfaces import OMIT_DISPLAY_FIELDS
47from waeup.aaue.applicants.interfaces import (
48    ICustomUGApplicant,
49    ICustomUGApplicantEdit,
50    ITranscriptApplicant,
51    ICustomApplicant
52    )
53
54UG_OMIT_FIELDS = (
55      'hq_type', 'hq_fname', 'hq_matric_no',
56      'hq_degree', 'hq_school', 'hq_session', 'hq_disc',
57      'hq_type2', 'hq_fname2', 'hq_matric_no2',
58      'hq_degree2', 'hq_school2', 'hq_session2', 'hq_disc2',
59      'hq_type3', 'hq_fname3', 'hq_matric_no3',
60      'hq_degree3', 'hq_school3', 'hq_session3', 'hq_disc3',
61      'nysc_year',
62      'nysc_location',
63      'nysc_lga',
64      'employer',
65      'emp_position',
66      'emp_start',
67      'emp_end',
68      'emp_reason',
69      'employer2',
70      'emp2_position',
71      'emp2_start',
72      'emp2_end',
73      'emp2_reason',
74      'former_matric',
75      )
76UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
77    'jamb_subjects_list', 'master_sheet_number') + UG_OMIT_FIELDS
78UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + UG_OMIT_FIELDS + (
79      'reg_number','alr_fname', 'alr_no', 'alr_date',
80      'alr_results', 'notice')
81UG_OMIT_MANAGE_FIELDS = (
82    'special_application','jamb_subjects_list',) + UG_OMIT_FIELDS
83UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
84    'student_id',
85    'notice',
86    'jamb_age',
87    'jamb_subjects',
88    'jamb_score',
89    'jamb_reg_number',
90    'aggregate',
91
92    'firstname',
93    'middlename',
94    'lastname',
95    'sex',
96    'lga',
97    'course1',
98    'master_sheet_number',
99    'screening_venue',
100    'screening_score',
101    'screening_date'
102    )
103
104#UG_OMIT_PDF_FIELDS = tuple([
105#    element for element in UG_OMIT_PDF_FIELDS if not element == 'phone'])
106
107#UG_OMIT_PDF_FIELDS += (
108#      'reg_number','alr_fname', 'alr_no', 'alr_date',
109#      'alr_results', 'notice'
110#      )
111
112PG_OMIT_FIELDS = (
113    'fst_sit_fname',
114    'fst_sit_no',
115    'fst_sit_date',
116    'fst_sit_type',
117    'fst_sit_results',
118    'scd_sit_fname',
119    'scd_sit_no',
120    'scd_sit_date',
121    'scd_sit_type',
122    'scd_sit_results',
123    #'programme_type',
124    'jamb_age',
125    'jamb_subjects',
126    'jamb_score',
127    'jamb_reg_number',
128    'aggregate'
129    )
130PG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
131    'jamb_subjects_list',) + PG_OMIT_FIELDS
132PG_OMIT_PDF_FIELDS = PG_OMIT_DISPLAY_FIELDS + PG_OMIT_FIELDS + (
133      'reg_number','alr_fname', 'alr_no', 'alr_date',
134      'alr_results', 'notice',
135      'nysc_year',
136      'nysc_location',
137      'nysc_lga',
138      'former_matric',
139      )
140PG_OMIT_MANAGE_FIELDS = (
141    'special_application','jamb_subjects_list',) + PG_OMIT_FIELDS
142PG_OMIT_EDIT_FIELDS = PG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
143    'student_id',
144    'notice',
145    )
146
147PTEE_OMIT_FIELDS = (
148    'jamb_age',
149    'jamb_subjects',
150    'jamb_score',
151    'jamb_reg_number',
152    'aggregate'
153    )
154PTEE_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
155    'jamb_subjects_list',) + PTEE_OMIT_FIELDS
156PTEE_OMIT_PDF_FIELDS = PTEE_OMIT_DISPLAY_FIELDS + PTEE_OMIT_FIELDS + (
157      'reg_number','alr_fname', 'alr_no', 'alr_date',
158      'alr_results', 'notice',
159      'nysc_year',
160      'nysc_location',
161      'nysc_lga',
162      'employer',
163      'emp_position',
164      'emp_start',
165      'emp_end',
166      'emp_reason',
167      'employer2',
168      'emp2_position',
169      'emp2_start',
170      'emp2_end',
171      'emp2_reason',
172      'former_matric',
173    )
174PTEE_OMIT_MANAGE_FIELDS = (
175    'special_application','jamb_subjects_list',) + PTEE_OMIT_FIELDS
176PTEE_OMIT_EDIT_FIELDS = PTEE_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
177    'student_id',
178    'notice',
179    )
180
181class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
182    """A display view for applicant data.
183    """
184
185    @property
186    def form_fields(self):
187        if self.target is not None and self.target == 'trans':
188            form_fields = grok.AutoFields(ITranscriptApplicant).omit(
189                'locked', 'suspended')
190            form_fields['dispatch_address'].custom_widget = BytesDisplayWidget
191            form_fields['perm_address'].custom_widget = BytesDisplayWidget
192            return form_fields
193        # AAUE is using the same interface for all regular applications.
194        form_fields = grok.AutoFields(ICustomUGApplicant)
195        if self.target is not None and self.target.startswith('pg'):
196            for field in PG_OMIT_DISPLAY_FIELDS:
197                form_fields = form_fields.omit(field)
198        elif self.target is not None and self.target in ('ptee', 'ude'):
199            for field in PTEE_OMIT_DISPLAY_FIELDS:
200                form_fields = form_fields.omit(field)
201        else:
202            for field in UG_OMIT_DISPLAY_FIELDS:
203                form_fields = form_fields.omit(field)
204        form_fields['perm_address'].custom_widget = BytesDisplayWidget
205        form_fields['notice'].custom_widget = BytesDisplayWidget
206        if not getattr(self.context, 'student_id'):
207            form_fields = form_fields.omit('student_id')
208        if not getattr(self.context, 'screening_score'):
209            form_fields = form_fields.omit('screening_score')
210        if not getattr(self.context, 'screening_venue'):
211            form_fields = form_fields.omit('screening_venue')
212        if not getattr(self.context, 'screening_date'):
213            form_fields = form_fields.omit('screening_date')
214        return form_fields
215
216class CustomPDFActionButton(PDFActionButton):
217
218    @property
219    def target_url(self):
220        if self.context.state in ('initialized', 'started', 'paid') \
221            or self.context.special or self.view.target == 'trans':
222            return
223        return self.view.url(self.view.context, self.target)
224
225
226class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
227
228    column_two_fields = ('applicant_id', 'reg_number',
229        'firstname', 'middlename', 'lastname', 'sex', 'date_of_birth')
230    #two_columns_design_fields = [
231    #    'fst_sit_fname', 'fst_sit_no', 'fst_sit_date',
232    #    'fst_sit_type', 'fst_sit_results',
233    #    'scd_sit_fname', 'scd_sit_no', 'scd_sit_date',
234    #    'scd_sit_type', 'scd_sit_results']
235
236    @property
237    def note(self):
238        if self.context.sex == 'm':
239            pronoun = 'he'
240        else:
241            pronoun = 'she'
242        return '''
243The applicant has acknowledged that, if discovered at any time that %s does not possess
244any of the qualifications which %s claims %s has obtained, %s will be expelled from the
245University not be re-admitted for the same or any other programme, even if %s has
246upgraded previous and shall qualifications or possess additional qualifications.
247''' % (
248    pronoun, pronoun, pronoun, pronoun, pronoun)
249
250    @property
251    def form_fields(self):
252        # AAUE is using the same interface for all regular applications.
253        form_fields = grok.AutoFields(ICustomUGApplicant)
254        if self.target is not None and self.target.startswith('pg'):
255            for field in PG_OMIT_PDF_FIELDS:
256                form_fields = form_fields.omit(field)
257        elif self.target is not None and self.target in ('ptee', 'ude'):
258            for field in PTEE_OMIT_PDF_FIELDS:
259                form_fields = form_fields.omit(field)
260        else:
261            for field in UG_OMIT_PDF_FIELDS:
262                form_fields = form_fields.omit(field)
263        if not getattr(self.context, 'student_id'):
264            form_fields = form_fields.omit('student_id')
265        if not getattr(self.context, 'screening_score'):
266            form_fields = form_fields.omit('screening_score')
267        if not getattr(self.context, 'screening_venue'):
268            form_fields = form_fields.omit('screening_venue')
269        if not getattr(self.context, 'screening_date'):
270            form_fields = form_fields.omit('screening_date')
271        return form_fields
272
273class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
274    """A full edit view for applicant data.
275    """
276
277    @property
278    def form_fields(self):
279        if self.target is not None and self.target == 'trans':
280            form_fields = grok.AutoFields(ITranscriptApplicant)
281            form_fields['applicant_id'].for_display = True
282            return form_fields
283        # AAUE is using the same interface for all regular applications.
284        form_fields = grok.AutoFields(ICustomUGApplicant)
285        if self.target is not None and self.target.startswith('pg'):
286            for field in PG_OMIT_MANAGE_FIELDS:
287                form_fields = form_fields.omit(field)
288        elif self.target is not None and self.target in ('ptee', 'ude'):
289            for field in PTEE_OMIT_MANAGE_FIELDS:
290                form_fields = form_fields.omit(field)
291        else:
292            for field in UG_OMIT_MANAGE_FIELDS:
293                form_fields = form_fields.omit(field)
294        form_fields['student_id'].for_display = True
295        form_fields['applicant_id'].for_display = True
296        return form_fields
297
298class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
299    """An applicant-centered edit view for applicant data.
300    """
301
302    grok.template('applicanteditpage')
303
304    def unremovable(self, ticket):
305        return True
306
307    # AAUE applicants never see the 'Remove Selected Tickets' button.
308    @property
309    def display_actions(self):
310        state = IWorkflowState(self.context).getState()
311        # If the form is unlocked, applicants are allowed to save the form
312        # and remove unused tickets.
313        actions = [[_('Save')], []]
314        # Only in state started they can also add tickets.
315        if state == STARTED:
316            actions = [[_('Save')],
317                [_('Add online payment ticket')]]
318        # In state paid, they can submit the data and further add tickets
319        # if the application is special.
320        elif self.context.special and state == PAID:
321            actions = [[_('Save'), _('Finally Submit')],
322                [_('Add online payment ticket')]]
323        elif state == PAID:
324            actions = [[_('Save'), _('Finally Submit')], []]
325        return actions
326
327    @property
328    def form_fields(self):
329        if self.target is not None and self.target == 'trans':
330            form_fields = grok.AutoFields(ITranscriptApplicant).omit(
331                'locked', 'suspended')
332            form_fields['applicant_id'].for_display = True
333            return form_fields
334        # AAUE is using the same interface for all regular applications.
335        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
336        if self.target is not None and self.target.startswith('pg'):
337            for field in PG_OMIT_EDIT_FIELDS:
338                form_fields = form_fields.omit(field)
339        elif self.target is not None and self.target in ('ptee', 'ude'):
340            for field in PTEE_OMIT_EDIT_FIELDS:
341                form_fields = form_fields.omit(field)
342        else:
343            for field in UG_OMIT_EDIT_FIELDS:
344                form_fields = form_fields.omit(field)
345        form_fields['applicant_id'].for_display = True
346        form_fields['reg_number'].for_display = True
347        return form_fields
348
349class CustomApplicantRegistrationPage(NigeriaApplicantRegistrationPage):
350    """Captcha'd registration page for applicants.
351    """
352
353    def _redirect(self, email, password, applicant_id):
354        # Forward email and credentials to landing page.
355        self.redirect(self.url(self.context, 'registration_complete',
356            data = dict(email=email, password=password,
357            applicant_id=applicant_id)))
358        return
359
360class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
361
362    @property
363    def payment_slip_download_warning(self):
364        return ''
365
366class CustomApplicantCheckStatusPage(ApplicantCheckStatusPage):
367    """Captcha'd status checking page for applicants.
368    """
369    grok.template('applicantcheckstatus')
370
371class PaymentReceiptActionButton(ManageActionButton):
372    grok.order(8) # This button should always be the last one.
373    grok.context(ICustomApplicant)
374    grok.view(CustomApplicantDisplayFormPage)
375    grok.require('waeup.viewApplication')
376    icon = 'actionicon_pdf.png'
377    text = _('Download screening invitation letter')
378    target = 'screening_invitation.pdf'
379
380    @property
381    def target_url(self):
382        if not self.context.screening_date:
383            return ''
384        return self.view.url(self.view.context, self.target)
385
386class ExportScreeningInvitationLetter(UtilityView, grok.View):
387    """Deliver a slip with only screening data.
388    This form page is available only in AAUE.
389    """
390    grok.context(ICustomApplicant)
391    grok.name('screening_invitation.pdf')
392    grok.require('waeup.viewApplication')
393    prefix = 'form'
394
395    label = u'Screening Invitation Letter'
396
397    form_fields = []
398
399    @property
400    def note(self):
401        if self.context.screening_date:
402            year = self.context.__parent__.year
403            session = '%s/%s' % (year, year + 1)
404            sdate = self.context.screening_date
405            stime = ''
406            if '@' in self.context.screening_date:
407                sdate = self.context.screening_date.split('@')[0].strip()
408                stime = self.context.screening_date.split('@')[1].strip()
409            return """
410<br /><br /><br /><br /><font size='12'>
411Dear %s,
412<br /><br />
413You are invited to the Ambrose Alli University %s Admissions Screening Exercise.
414<br /><br />
415<strong>Date: %s
416<br /><br />
417Time: %s
418<br /><br />
419Venue: %s
420</strong>
421<br /><br />
422Please bring this letter of invitation and the downloaded application form along with you on your screening date.
423<br /><br />
424You are expected to be available 30 minutes before the commencement of your Screening.
425</font>
426
427""" % (
428       self.context.display_fullname,
429       session,
430       sdate,
431       stime,
432       self.context.screening_venue)
433        return
434
435    @property
436    def title(self):
437        return None
438
439    def update(self):
440        if not self.context.screening_date:
441            self.flash(_('Forbidden'), type="warning")
442            self.redirect(self.url(self.context))
443
444    def render(self):
445        applicantview = ApplicantBaseDisplayFormPage(self.context, self.request)
446        students_utils = getUtility(IStudentsUtils)
447        return students_utils.renderPDF(self,'screening_data.pdf',
448            self.context, applicantview, note=self.note)
Note: See TracBrowser for help on using the repository browser.