source: main/kofacustom.edocons/trunk/src/kofacustom/edocons/applicants/browser.py @ 17930

Last change on this file since 17930 was 17683, checked in by Henrik Bettermann, 11 months ago

Modify application form. Upon application, the candidate must be seventeen years old (17).

  • Property svn:keywords set to Id
File size: 11.9 KB
Line 
1## $Id: browser.py 17683 2024-01-29 11:38:51Z 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
21from zope.component import getUtility
22from zope.i18n import translate
23from waeup.kofa.interfaces import IExtFileStore, IKofaUtils
24from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
25from zope.formlib.textwidgets import BytesDisplayWidget
26from waeup.kofa.students.interfaces import IStudentsUtils
27from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage,
28    ApplicantManageFormPage, ApplicantEditFormPage,
29    ApplicantRegistrationPage,
30    OnlinePaymentDisplayFormPage,
31    OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage,
32    AdditionalFile
33    )
34from waeup.kofa.applicants.viewlets import (
35    PDFActionButton, PaymentReceiptActionButton)
36from waeup.kofa.applicants.pdf import PDFApplicationSlip
37from kofacustom.nigeria.applicants.browser import (
38    NigeriaApplicantDisplayFormPage,
39    NigeriaApplicantManageFormPage,
40    NigeriaApplicantEditFormPage,
41    NigeriaPDFApplicationSlip)
42from kofacustom.nigeria.applicants.interfaces import (
43    INigeriaPGApplicant, INigeriaUGApplicant,
44    INigeriaPGApplicantEdit, INigeriaUGApplicantEdit,
45    INigeriaApplicantOnlinePayment,
46    #UG_OMIT_DISPLAY_FIELDS,
47    #UG_OMIT_PDF_FIELDS,
48    #UG_OMIT_MANAGE_FIELDS,
49    #UG_OMIT_EDIT_FIELDS,
50    PG_OMIT_DISPLAY_FIELDS,
51    PG_OMIT_PDF_FIELDS,
52    PG_OMIT_MANAGE_FIELDS,
53    PG_OMIT_EDIT_FIELDS,
54    )
55from kofacustom.edocons.applicants.interfaces import (
56    ICustomPGApplicant, ICustomUGApplicant, ICustomApplicant,
57    ICustomPGApplicantEdit, ICustomUGApplicantEdit,
58    ICustomApplicantOnlinePayment, ITranscriptApplicant,
59    )
60from kofacustom.nigeria.interfaces import MessageFactory as _
61
62# Fields to be omitted in all display forms. course_admitted is
63# rendered separately.
64
65OMIT_DISPLAY_FIELDS = ('locked', 'course_admitted',
66    'result_uploaded', 'suspended', 'special_application',
67    'bank_account_number',
68    'bank_account_name',
69    'bank_name',
70    #'course1', 'course2' # these 2 have been added and later removed again
71    )
72
73# UG students are all undergraduate students.
74UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
75    'jamb_subjects', 'programme_type')
76UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',)
77UG_OMIT_MANAGE_FIELDS = (
78    'special_application',
79    'jamb_subjects',
80    'programme_type',
81    #'course1', 'course2', # these 2 have been added and later removed again
82    )
83UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
84    'student_id',
85    'notice',
86    'screening_score',
87    'screening_venue',
88    'screening_date',
89    'cbt_score',
90    'cbt_venue',
91    'cbt_date',
92    'jamb_age',
93    'aggregate')
94
95TSC_OMIT_FIELDS = ('locked', 'suspended',
96    )
97   
98
99TSC_OMIT_EDIT_FIELDS = TSC_OMIT_FIELDS + (
100    'applicant_id',
101    'proc_date',
102    'courier_tno',
103    )
104
105TSC_OMIT_MANAGE_FIELDS = TSC_OMIT_FIELDS + (
106    'applicant_id',)     
107
108class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
109    """A display view for applicant data.
110    """
111
112    @property
113    def form_fields(self):
114        if self.target is not None and self.target.startswith('pg'):
115            form_fields = grok.AutoFields(ICustomPGApplicant)
116            for field in PG_OMIT_DISPLAY_FIELDS:
117                form_fields = form_fields.omit(field)
118        elif self.target is not None and self.target.startswith('tsc'):
119            form_fields = grok.AutoFields(ITranscriptApplicant)
120            for field in TSC_OMIT_FIELDS:
121                form_fields = form_fields.omit(field)
122            form_fields = form_fields.omit('charge')
123            return form_fields
124        else:
125            form_fields = grok.AutoFields(ICustomUGApplicant)
126            for field in UG_OMIT_DISPLAY_FIELDS:
127                form_fields = form_fields.omit(field)
128            form_fields['notice'].custom_widget = BytesDisplayWidget
129        if self.context.__parent__.application_category == 'rnnurse':
130            form_fields = form_fields.omit('jamb_reg_number', 'jamb_subjects_list', 'jamb_score', 'course2')
131        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
132        if not getattr(self.context, 'student_id'):
133            form_fields = form_fields.omit('student_id')
134        if not getattr(self.context, 'screening_score'):
135            form_fields = form_fields.omit('screening_score')
136        if not getattr(self.context, 'screening_venue') or self._not_paid():
137            form_fields = form_fields.omit('screening_venue')
138        if not getattr(self.context, 'screening_date') or self._not_paid():
139            form_fields = form_fields.omit('screening_date')
140        if not getattr(self.context, 'cbt_score'):
141            form_fields = form_fields.omit('cbt_score')
142        if not getattr(self.context, 'cbt_venue') or self._not_paid():
143            form_fields = form_fields.omit('cbt_venue')
144        if not getattr(self.context, 'cbt_date') or self._not_paid():
145            form_fields = form_fields.omit('cbt_date')
146        return form_fields
147
148class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
149
150    @property
151    def form_fields(self):
152        if self.target is not None and self.target.startswith('pg'):
153            form_fields = grok.AutoFields(ICustomPGApplicant)
154            for field in PG_OMIT_PDF_FIELDS:
155                form_fields = form_fields.omit(field)
156        elif self.target is not None and self.target.startswith('tsc'):
157            form_fields = grok.AutoFields(ITranscriptApplicant)
158            for field in TSC_OMIT_FIELDS:
159                form_fields = form_fields.omit(field)
160            form_fields = form_fields.omit('charge')
161            return form_fields
162        else:
163            form_fields = grok.AutoFields(ICustomUGApplicant)
164            for field in UG_OMIT_PDF_FIELDS:
165                form_fields = form_fields.omit(field)
166        if self.context.__parent__.application_category == 'rnnurse':
167            form_fields = form_fields.omit('jamb_reg_number', 'jamb_subjects_list', 'jamb_score', 'course2')
168        if self.context.__parent__.application_category == 'ndnurse':
169            form_fields = form_fields.omit('course2')
170        if not getattr(self.context, 'student_id'):
171            form_fields = form_fields.omit('student_id')
172        if not getattr(self.context, 'screening_score'):
173            form_fields = form_fields.omit('screening_score')
174        if not getattr(self.context, 'screening_venue'):
175            form_fields = form_fields.omit('screening_venue')
176        if not getattr(self.context, 'screening_date'):
177            form_fields = form_fields.omit('screening_date')
178        if not getattr(self.context, 'cbt_score'):
179            form_fields = form_fields.omit('cbt_score')
180        if not getattr(self.context, 'cbt_venue'):
181            form_fields = form_fields.omit('cbt_venue')
182        if not getattr(self.context, 'cbt_date'):
183            form_fields = form_fields.omit('cbt_date')
184        return form_fields
185
186class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
187    """A full edit view for applicant data.
188    """
189
190    def display_fileupload(self, filename):
191        if self.target is not None and not self.target.startswith('tsc'):
192            return False
193        return True
194
195    @property
196    def form_fields(self):
197        if self.target is not None and self.target.startswith('pg'):
198            form_fields = grok.AutoFields(ICustomPGApplicant)
199            for field in PG_OMIT_MANAGE_FIELDS:
200                form_fields = form_fields.omit(field)
201        elif self.target is not None and self.target.startswith('tsc'):
202            form_fields = grok.AutoFields(ITranscriptApplicant)
203            for field in TSC_OMIT_MANAGE_FIELDS:
204                form_fields = form_fields.omit(field)             
205            return form_fields
206        else:
207            form_fields = grok.AutoFields(ICustomUGApplicant)
208            for field in UG_OMIT_MANAGE_FIELDS:
209                form_fields = form_fields.omit(field)
210        if self.context.__parent__.application_category == 'rnnurse':
211            form_fields = form_fields.omit('jamb_reg_number', 'jamb_subjects_list', 'jamb_score', 'course2')
212        if self.context.__parent__.application_category == 'ndnurse':
213            form_fields = form_fields.omit('course2')
214        form_fields['student_id'].for_display = True
215        form_fields['applicant_id'].for_display = True
216        return form_fields
217
218class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
219    """An applicant-centered edit view for applicant data.
220    """
221
222    def unremovable(self, ticket):
223        return True
224
225    def display_fileupload(self, filename):
226        if self.target is not None and not self.target.startswith('tsc'):
227            return False
228        return True
229
230    @property
231    def form_fields(self):
232        if self.target is not None and self.target.startswith('pg'):
233            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
234            for field in PG_OMIT_EDIT_FIELDS:
235                form_fields = form_fields.omit(field)
236        elif self.target is not None and self.target.startswith('tsc'):
237            form_fields = grok.AutoFields(ITranscriptApplicant)
238            for field in TSC_OMIT_EDIT_FIELDS:
239                form_fields = form_fields.omit(field)           
240            return form_fields
241        else:
242            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
243            for field in UG_OMIT_EDIT_FIELDS:
244                form_fields = form_fields.omit(field)
245        if self.context.__parent__.application_category == 'rnnurse':
246            form_fields = form_fields.omit('jamb_reg_number', 'jamb_subjects_list', 'jamb_score', 'course2')
247        if self.context.__parent__.application_category == 'ndnurse':
248            form_fields = form_fields.omit('course2')
249        form_fields['applicant_id'].for_display = True
250        form_fields['reg_number'].for_display = True
251        return form_fields
252
253    def dataNotComplete(self, data):
254        store = getUtility(IExtFileStore)
255        if self.context.__parent__.with_picture \
256            and self.context.__parent__.picture_editable:
257            store = getUtility(IExtFileStore)
258            if not store.getFileByContext(self.context, attr=u'passport.jpg'):
259                return _('No passport picture uploaded.')
260        if self.target is not None \
261            and self.target.startswith('tscf') \
262            and not store.getFileByContext(self.context, attr=u'res_stat.pdf'):
263            return _('No statement of result pdf file uploaded.')
264        if self.target is not None \
265            and self.target.startswith('tscf') \
266            and not store.getFileByContext(self.context, attr=u'not_reg.pdf'):
267            return _('No notification of result pdf file uploaded.')
268        #if self.target is not None \
269        #    and self.target.startswith('tsc') \
270        #    and not store.getFileByContext(self.context, attr=u'testimonial.pdf'):
271        #    return _('No testimonial pdf file uploaded.')
272        return False
273
274class ResultStatement(AdditionalFile):
275    grok.name('res_stat')
276   
277class Testimonial(AdditionalFile):
278    grok.name('testimonial')
279
280class NotificationResult(AdditionalFile):
281    grok.name('not_res')     
282   
283class DocumentUploadForm(AdditionalFile):
284    grok.name('docupload')
285
286class OtherDocument1(AdditionalFile):
287    grok.name('doc_1')   
288
289class OtherDocument2(AdditionalFile):
290    grok.name('doc_2')           
Note: See TracBrowser for help on using the repository browser.