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

Last change on this file since 17465 was 17465, checked in by Henrik Bettermann, 15 months ago

Adjust application forms and add application categories.

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