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

Last change on this file since 17387 was 17340, checked in by Henrik Bettermann, 21 months ago

Do not display transcript charge. This might have changed.

  • Property svn:keywords set to Id
File size: 10.9 KB
Line 
1## $Id: browser.py 17340 2023-02-10 17:36:00Z 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_list', 'programme_type')
76UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',)
77UG_OMIT_MANAGE_FIELDS = (
78    'special_application',
79    'jamb_subjects_list',
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    'jamb_subjects',
94    'jamb_score',
95    'jamb_reg_number',
96    'aggregate')
97
98TSC_OMIT_FIELDS = ('locked', 'suspended',
99    )
100   
101
102TSC_OMIT_EDIT_FIELDS = TSC_OMIT_FIELDS + (
103    'applicant_id',
104    'proc_date',
105    'courier_tno',
106    )
107
108TSC_OMIT_MANAGE_FIELDS = TSC_OMIT_FIELDS + (
109    'applicant_id',)     
110
111class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
112    """A display view for applicant data.
113    """
114
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)
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:
124                form_fields = form_fields.omit(field)
125            form_fields = form_fields.omit('charge')
126            return form_fields
127        else:
128            form_fields = grok.AutoFields(ICustomUGApplicant)
129            for field in UG_OMIT_DISPLAY_FIELDS:
130                form_fields = form_fields.omit(field)
131            form_fields['notice'].custom_widget = BytesDisplayWidget
132        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
133        if not getattr(self.context, 'student_id'):
134            form_fields = form_fields.omit('student_id')
135        if not getattr(self.context, 'screening_score'):
136            form_fields = form_fields.omit('screening_score')
137        if not getattr(self.context, 'screening_venue') or self._not_paid():
138            form_fields = form_fields.omit('screening_venue')
139        if not getattr(self.context, 'screening_date') or self._not_paid():
140            form_fields = form_fields.omit('screening_date')
141        if not getattr(self.context, 'cbt_score'):
142            form_fields = form_fields.omit('cbt_score')
143        if not getattr(self.context, 'cbt_venue') or self._not_paid():
144            form_fields = form_fields.omit('cbt_venue')
145        if not getattr(self.context, 'cbt_date') or self._not_paid():
146            form_fields = form_fields.omit('cbt_date')
147        return form_fields
148
149class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
150
151    @property
152    def form_fields(self):
153        if self.target is not None and self.target.startswith('pg'):
154            form_fields = grok.AutoFields(ICustomPGApplicant)
155            for field in PG_OMIT_PDF_FIELDS:
156                form_fields = form_fields.omit(field)
157        elif self.target is not None and self.target.startswith('tsc'):
158            form_fields = grok.AutoFields(ITranscriptApplicant)
159            for field in TSC_OMIT_FIELDS:
160                form_fields = form_fields.omit(field)
161            form_fields = form_fields.omit('charge')
162            return form_fields
163        else:
164            form_fields = grok.AutoFields(ICustomUGApplicant)
165            for field in UG_OMIT_PDF_FIELDS:
166                form_fields = form_fields.omit(field)
167        if not getattr(self.context, 'student_id'):
168            form_fields = form_fields.omit('student_id')
169        if not getattr(self.context, 'screening_score'):
170            form_fields = form_fields.omit('screening_score')
171        if not getattr(self.context, 'screening_venue'):
172            form_fields = form_fields.omit('screening_venue')
173        if not getattr(self.context, 'screening_date'):
174            form_fields = form_fields.omit('screening_date')
175        if not getattr(self.context, 'cbt_score'):
176            form_fields = form_fields.omit('cbt_score')
177        if not getattr(self.context, 'cbt_venue'):
178            form_fields = form_fields.omit('cbt_venue')
179        if not getattr(self.context, 'cbt_date'):
180            form_fields = form_fields.omit('cbt_date')
181        return form_fields
182
183class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
184    """A full edit view for applicant data.
185    """
186
187    def display_fileupload(self, filename):
188        if self.target is not None and not self.target.startswith('tsc'):
189            return False
190        return True
191
192    @property
193    def form_fields(self):
194        if self.target is not None and self.target.startswith('pg'):
195            form_fields = grok.AutoFields(ICustomPGApplicant)
196            for field in PG_OMIT_MANAGE_FIELDS:
197                form_fields = form_fields.omit(field)
198        elif self.target is not None and self.target.startswith('tsc'):
199            form_fields = grok.AutoFields(ITranscriptApplicant)
200            for field in TSC_OMIT_MANAGE_FIELDS:
201                form_fields = form_fields.omit(field)             
202            return form_fields
203        else:
204            form_fields = grok.AutoFields(ICustomUGApplicant)
205            for field in UG_OMIT_MANAGE_FIELDS:
206                form_fields = form_fields.omit(field)
207        form_fields['student_id'].for_display = True
208        form_fields['applicant_id'].for_display = True
209        return form_fields
210
211class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
212    """An applicant-centered edit view for applicant data.
213    """
214
215    def unremovable(self, ticket):
216        return True
217
218    def display_fileupload(self, filename):
219        if self.target is not None and not self.target.startswith('tsc'):
220            return False
221        return True
222
223    @property
224    def form_fields(self):
225        if self.target is not None and self.target.startswith('pg'):
226            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
227            for field in PG_OMIT_EDIT_FIELDS:
228                form_fields = form_fields.omit(field)
229        elif self.target is not None and self.target.startswith('tsc'):
230            form_fields = grok.AutoFields(ITranscriptApplicant)
231            for field in TSC_OMIT_EDIT_FIELDS:
232                form_fields = form_fields.omit(field)           
233            return form_fields
234        else:
235            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
236            for field in UG_OMIT_EDIT_FIELDS:
237                form_fields = form_fields.omit(field)
238        form_fields['applicant_id'].for_display = True
239        form_fields['reg_number'].for_display = True
240        return form_fields
241
242    def dataNotComplete(self, data):
243        store = getUtility(IExtFileStore)
244        if self.context.__parent__.with_picture \
245            and self.context.__parent__.picture_editable:
246            store = getUtility(IExtFileStore)
247            if not store.getFileByContext(self.context, attr=u'passport.jpg'):
248                return _('No passport picture uploaded.')
249        if self.target is not None \
250            and self.target.startswith('tscf') \
251            and not store.getFileByContext(self.context, attr=u'res_stat.pdf'):
252            return _('No statement of result pdf file uploaded.')
253        if self.target is not None \
254            and self.target.startswith('tscf') \
255            and not store.getFileByContext(self.context, attr=u'not_reg.pdf'):
256            return _('No notification of result pdf file uploaded.')
257        #if self.target is not None \
258        #    and self.target.startswith('tsc') \
259        #    and not store.getFileByContext(self.context, attr=u'testimonial.pdf'):
260        #    return _('No testimonial pdf file uploaded.')
261        return False
262
263class ResultStatement(AdditionalFile):
264    grok.name('res_stat')
265   
266class Testimonial(AdditionalFile):
267    grok.name('testimonial')
268
269class NotificationResult(AdditionalFile):
270    grok.name('not_res')     
271   
272class DocumentUploadForm(AdditionalFile):
273    grok.name('docupload')
274
275class OtherDocument1(AdditionalFile):
276    grok.name('doc_1')   
277
278class OtherDocument2(AdditionalFile):
279    grok.name('doc_2')           
Note: See TracBrowser for help on using the repository browser.