1 | ## $Id: browser.py 14807 2017-08-18 10:26:59Z 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 | """ |
---|
20 | import grok |
---|
21 | from zope.component import getUtility |
---|
22 | from zope.i18n import translate |
---|
23 | from hurry.workflow.interfaces import IWorkflowState |
---|
24 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
25 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
26 | from waeup.kofa.interfaces import IExtFileStore, IKofaUtils |
---|
27 | from waeup.kofa.applicants.interfaces import ( |
---|
28 | IApplicant, IApplicantEdit, ISpecialApplicant) |
---|
29 | from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage, |
---|
30 | ApplicantManageFormPage, ApplicantEditFormPage, |
---|
31 | ApplicantsContainerPage, ApplicationFeePaymentAddPage) |
---|
32 | from waeup.kofa.applicants.viewlets import ( |
---|
33 | PaymentReceiptActionButton, PDFActionButton) |
---|
34 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
35 | from waeup.kofa.applicants.workflow import ADMITTED, PAID, STARTED |
---|
36 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
37 | UG_OMIT_DISPLAY_FIELDS, |
---|
38 | UG_OMIT_PDF_FIELDS, |
---|
39 | UG_OMIT_MANAGE_FIELDS, |
---|
40 | UG_OMIT_EDIT_FIELDS |
---|
41 | ) |
---|
42 | from kofacustom.dspg.applicants.interfaces import ( |
---|
43 | ICustomUGApplicant, ICustomUGApplicantEdit, |
---|
44 | ND_OMIT_DISPLAY_FIELDS, |
---|
45 | ND_OMIT_PDF_FIELDS, |
---|
46 | ND_OMIT_MANAGE_FIELDS, |
---|
47 | ND_OMIT_EDIT_FIELDS |
---|
48 | ) |
---|
49 | |
---|
50 | from kofacustom.dspg.interfaces import MessageFactory as _ |
---|
51 | |
---|
52 | UG_OMIT_EDIT_FIELDS = [ |
---|
53 | value for value in UG_OMIT_EDIT_FIELDS |
---|
54 | if not value in ('jamb_subjects', 'jamb_score', 'jamb_reg_number')] |
---|
55 | |
---|
56 | PRE_OMIT_EDIT_FIELDS = UG_OMIT_EDIT_FIELDS + [ |
---|
57 | 'firstname', |
---|
58 | 'middlename', |
---|
59 | 'lastname', |
---|
60 | #'sex', |
---|
61 | 'jamb_score' |
---|
62 | ] |
---|
63 | |
---|
64 | class CustomApplicantsContainerPage(ApplicantsContainerPage): |
---|
65 | """The standard view for regular applicant containers. |
---|
66 | """ |
---|
67 | |
---|
68 | @property |
---|
69 | def form_fields(self): |
---|
70 | form_fields = super(CustomApplicantsContainerPage, self).form_fields |
---|
71 | if self.request.principal.id == 'zope.anybody': |
---|
72 | return form_fields.omit('application_fee') |
---|
73 | return form_fields |
---|
74 | |
---|
75 | class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage): |
---|
76 | """A display view for applicant data. |
---|
77 | """ |
---|
78 | |
---|
79 | @property |
---|
80 | def form_fields(self): |
---|
81 | if self.context.special: |
---|
82 | return grok.AutoFields(ISpecialApplicant) |
---|
83 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
84 | if self.context.is_nd: |
---|
85 | for field in ND_OMIT_DISPLAY_FIELDS: |
---|
86 | form_fields = form_fields.omit(field) |
---|
87 | else: |
---|
88 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
89 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
90 | form_fields = form_fields.omit(field) |
---|
91 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
92 | form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget |
---|
93 | if not getattr(self.context, 'student_id'): |
---|
94 | form_fields = form_fields.omit('student_id') |
---|
95 | if not getattr(self.context, 'screening_score'): |
---|
96 | form_fields = form_fields.omit('screening_score') |
---|
97 | if not getattr(self.context, 'screening_venue'): |
---|
98 | form_fields = form_fields.omit('screening_venue') |
---|
99 | if not getattr(self.context, 'screening_date'): |
---|
100 | form_fields = form_fields.omit('screening_date') |
---|
101 | return form_fields |
---|
102 | |
---|
103 | class CustomPDFApplicationSlip(PDFApplicationSlip): |
---|
104 | |
---|
105 | def _reduced_slip(self): |
---|
106 | return getattr(self.context, 'result_uploaded', False) |
---|
107 | |
---|
108 | @property |
---|
109 | def note(self): |
---|
110 | note = getattr(self.context.__parent__, 'application_slip_notice', None) |
---|
111 | if note: |
---|
112 | return '<br /><br />' + note |
---|
113 | pronoun = 'S/he' |
---|
114 | if self.context.sex == 'm': |
---|
115 | pronoun = 'He' |
---|
116 | else: |
---|
117 | pronoun = 'She' |
---|
118 | return '''<br /><br /> |
---|
119 | The applicant has declared that: |
---|
120 | |
---|
121 | a) %s is not a member of any secret cult and will not join any. |
---|
122 | b) %s will not engage in any cult activities. |
---|
123 | c) %s will not be involved in any acts of terrorism, rape, robbery, fighting, illegal gathering and |
---|
124 | any activities that could disrupt peace on campus. |
---|
125 | d) %s does not have and will not acquire any form of weapon, fire arms, gun knife or any weapon |
---|
126 | that can cause damage to life and property. |
---|
127 | e) %s will strive to be worthy in character and learning at all times. |
---|
128 | |
---|
129 | The applicant has acknowledged that offences will automatically lead to the expulsion from the |
---|
130 | Polytechnic and also be dealt with in accordance with the law of the land. |
---|
131 | |
---|
132 | The applicant promises to abide by all the Rules and Regulations of the Polytechnic if offered |
---|
133 | admission. |
---|
134 | ''' % ( |
---|
135 | pronoun, pronoun, pronoun, pronoun, pronoun) |
---|
136 | |
---|
137 | @property |
---|
138 | def form_fields(self): |
---|
139 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
140 | if self.context.is_nd: |
---|
141 | for field in ND_OMIT_PDF_FIELDS: |
---|
142 | form_fields = form_fields.omit(field) |
---|
143 | else: |
---|
144 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
145 | for field in UG_OMIT_PDF_FIELDS: |
---|
146 | form_fields = form_fields.omit(field) |
---|
147 | if not getattr(self.context, 'student_id'): |
---|
148 | form_fields = form_fields.omit('student_id') |
---|
149 | if not getattr(self.context, 'screening_score'): |
---|
150 | form_fields = form_fields.omit('screening_score') |
---|
151 | if not getattr(self.context, 'screening_venue'): |
---|
152 | form_fields = form_fields.omit('screening_venue') |
---|
153 | if not getattr(self.context, 'screening_date'): |
---|
154 | form_fields = form_fields.omit('screening_date') |
---|
155 | return form_fields |
---|
156 | |
---|
157 | class CustomApplicantManageFormPage(ApplicantManageFormPage): |
---|
158 | """A full edit view for applicant data. |
---|
159 | """ |
---|
160 | |
---|
161 | @property |
---|
162 | def form_fields(self): |
---|
163 | if self.context.special: |
---|
164 | form_fields = grok.AutoFields(ISpecialApplicant) |
---|
165 | form_fields['applicant_id'].for_display = True |
---|
166 | return form_fields |
---|
167 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
168 | if self.context.is_nd: |
---|
169 | for field in ND_OMIT_MANAGE_FIELDS: |
---|
170 | form_fields = form_fields.omit(field) |
---|
171 | else: |
---|
172 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
173 | form_fields = form_fields.omit(field) |
---|
174 | form_fields['student_id'].for_display = True |
---|
175 | form_fields['applicant_id'].for_display = True |
---|
176 | return form_fields |
---|
177 | |
---|
178 | class CustomApplicantEditFormPage(ApplicantEditFormPage): |
---|
179 | """An applicant-centered edit view for applicant data. |
---|
180 | """ |
---|
181 | |
---|
182 | def unremovable(self, ticket): |
---|
183 | return True |
---|
184 | |
---|
185 | @property |
---|
186 | def form_fields(self): |
---|
187 | if self.context.special: |
---|
188 | form_fields = grok.AutoFields(ISpecialApplicant).omit( |
---|
189 | 'locked', 'suspended') |
---|
190 | form_fields['applicant_id'].for_display = True |
---|
191 | return form_fields |
---|
192 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
193 | if self.context.is_nd: |
---|
194 | for field in ND_OMIT_EDIT_FIELDS: |
---|
195 | form_fields = form_fields.omit(field) |
---|
196 | elif self.target is not None and self.target.startswith('pre'): |
---|
197 | for field in PRE_OMIT_EDIT_FIELDS: |
---|
198 | form_fields = form_fields.omit(field) |
---|
199 | else: |
---|
200 | for field in UG_OMIT_EDIT_FIELDS: |
---|
201 | form_fields = form_fields.omit(field) |
---|
202 | form_fields['applicant_id'].for_display = True |
---|
203 | form_fields['reg_number'].for_display = True |
---|
204 | return form_fields |
---|
205 | |
---|
206 | @property |
---|
207 | def display_actions(self): |
---|
208 | state = IWorkflowState(self.context).getState() |
---|
209 | # If the form is unlocked, applicants are allowed to save the form |
---|
210 | # and remove unused tickets. |
---|
211 | actions = [[_('Save')], []] |
---|
212 | # Only in state started they can also add tickets. |
---|
213 | if state == STARTED: |
---|
214 | actions = [[_('Save')], |
---|
215 | [_('Add online payment ticket'),]] |
---|
216 | # In state paid, they can submit the data and further add tickets |
---|
217 | # if the application is special. |
---|
218 | elif self.context.special and state == PAID: |
---|
219 | actions = [[_('Save'), _('Finally Submit')], |
---|
220 | [_('Add online payment ticket'),]] |
---|
221 | elif state == PAID: |
---|
222 | actions = [[_('Save'), _('Finally Submit')], []] |
---|
223 | return actions |
---|
224 | |
---|
225 | class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage): |
---|
226 | """ Page to add an online payment ticket |
---|
227 | """ |
---|
228 | |
---|
229 | @property |
---|
230 | def custom_requirements(self): |
---|
231 | store = getUtility(IExtFileStore) |
---|
232 | if not store.getFileByContext(self.context, attr=u'passport.jpg'): |
---|
233 | return _('Upload your passport photo before making payment.') |
---|
234 | return '' |
---|