1 | ## $Id: browser.py 17476 2023-07-10 01:17:02Z 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.formlib.textwidgets import BytesDisplayWidget |
---|
22 | from waeup.kofa.applicants.browser import ( |
---|
23 | ApplicantRegistrationPage, ApplicantsContainerPage) |
---|
24 | from kofacustom.nigeria.applicants.browser import ( |
---|
25 | NigeriaApplicantDisplayFormPage, |
---|
26 | NigeriaApplicantManageFormPage, |
---|
27 | NigeriaApplicantEditFormPage, |
---|
28 | NigeriaPDFApplicationSlip) |
---|
29 | |
---|
30 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
31 | INigeriaPGApplicant, INigeriaUGApplicant, |
---|
32 | INigeriaPGApplicantEdit, INigeriaUGApplicantEdit, |
---|
33 | INigeriaApplicantOnlinePayment, |
---|
34 | #UG_OMIT_DISPLAY_FIELDS, |
---|
35 | #UG_OMIT_PDF_FIELDS, |
---|
36 | #UG_OMIT_MANAGE_FIELDS, |
---|
37 | #UG_OMIT_EDIT_FIELDS, |
---|
38 | PG_OMIT_DISPLAY_FIELDS, |
---|
39 | PG_OMIT_PDF_FIELDS, |
---|
40 | PG_OMIT_MANAGE_FIELDS, |
---|
41 | PG_OMIT_EDIT_FIELDS, |
---|
42 | ) |
---|
43 | from kofacustom.unidel.applicants.interfaces import ( |
---|
44 | ICustomPGApplicant, ICustomUGApplicant, ICustomApplicant, |
---|
45 | ICustomPGApplicantEdit, ICustomUGApplicantEdit, |
---|
46 | ICustomApplicantOnlinePayment, |
---|
47 | ) |
---|
48 | |
---|
49 | from kofacustom.unidel.interfaces import MessageFactory as _ |
---|
50 | |
---|
51 | OMIT_DISPLAY_FIELDS = ('locked', 'course_admitted', |
---|
52 | 'result_uploaded', 'suspended', 'special_application', |
---|
53 | 'bank_account_number', |
---|
54 | 'bank_account_name', |
---|
55 | 'bank_name', |
---|
56 | 'jamb_subjects_list') |
---|
57 | |
---|
58 | # UG students are all undergraduate students. |
---|
59 | UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + ( |
---|
60 | 'jamb_subjects_list', |
---|
61 | 'programme_type',) |
---|
62 | UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',) |
---|
63 | UG_OMIT_MANAGE_FIELDS = ( |
---|
64 | 'special_application', |
---|
65 | 'jamb_subjects_list', |
---|
66 | 'programme_type',) |
---|
67 | UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + ( |
---|
68 | 'student_id', |
---|
69 | 'notice', |
---|
70 | 'screening_score', |
---|
71 | 'screening_venue', |
---|
72 | 'screening_date', |
---|
73 | 'jamb_age', |
---|
74 | 'jamb_subjects', |
---|
75 | 'jamb_score', |
---|
76 | 'jamb_reg_number', |
---|
77 | 'aggregate', |
---|
78 | 'lga', |
---|
79 | 'date_of_birth') |
---|
80 | |
---|
81 | |
---|
82 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
83 | """A display view for applicant data. |
---|
84 | """ |
---|
85 | |
---|
86 | @property |
---|
87 | def form_fields(self): |
---|
88 | if self.target is not None and self.target.startswith('pg'): |
---|
89 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
90 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
91 | form_fields = form_fields.omit(field) |
---|
92 | else: |
---|
93 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
94 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
95 | form_fields = form_fields.omit(field) |
---|
96 | #form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
97 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
98 | if not getattr(self.context, 'student_id'): |
---|
99 | form_fields = form_fields.omit('student_id') |
---|
100 | if not getattr(self.context, 'screening_score'): |
---|
101 | form_fields = form_fields.omit('screening_score') |
---|
102 | if not getattr(self.context, 'screening_venue') or self._not_paid(): |
---|
103 | form_fields = form_fields.omit('screening_venue') |
---|
104 | if not getattr(self.context, 'screening_date') or self._not_paid(): |
---|
105 | form_fields = form_fields.omit('screening_date') |
---|
106 | return form_fields |
---|
107 | |
---|
108 | class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): |
---|
109 | |
---|
110 | @property |
---|
111 | def form_fields(self): |
---|
112 | if self.target is not None and self.target.startswith('pg'): |
---|
113 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
114 | for field in PG_OMIT_PDF_FIELDS: |
---|
115 | form_fields = form_fields.omit(field) |
---|
116 | else: |
---|
117 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
118 | for field in UG_OMIT_PDF_FIELDS: |
---|
119 | form_fields = form_fields.omit(field) |
---|
120 | if not getattr(self.context, 'student_id'): |
---|
121 | form_fields = form_fields.omit('student_id') |
---|
122 | if not getattr(self.context, 'screening_score'): |
---|
123 | form_fields = form_fields.omit('screening_score') |
---|
124 | if not getattr(self.context, 'screening_venue'): |
---|
125 | form_fields = form_fields.omit('screening_venue') |
---|
126 | if not getattr(self.context, 'screening_date'): |
---|
127 | form_fields = form_fields.omit('screening_date') |
---|
128 | return form_fields |
---|
129 | |
---|
130 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
131 | """A full edit view for applicant data. |
---|
132 | """ |
---|
133 | |
---|
134 | @property |
---|
135 | def form_fields(self): |
---|
136 | if self.target is not None and self.target.startswith('pg'): |
---|
137 | form_fields = grok.AutoFields(ICustomPGApplicant) |
---|
138 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
139 | form_fields = form_fields.omit(field) |
---|
140 | else: |
---|
141 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
142 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
143 | form_fields = form_fields.omit(field) |
---|
144 | form_fields['student_id'].for_display = True |
---|
145 | form_fields['applicant_id'].for_display = True |
---|
146 | return form_fields |
---|
147 | |
---|
148 | class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): |
---|
149 | """An applicant-centered edit view for applicant data. |
---|
150 | """ |
---|
151 | |
---|
152 | def unremovable(self, ticket): |
---|
153 | return True |
---|
154 | |
---|
155 | @property |
---|
156 | def form_fields(self): |
---|
157 | if self.target is not None and self.target.startswith('pg'): |
---|
158 | form_fields = grok.AutoFields(ICustomPGApplicantEdit) |
---|
159 | for field in PG_OMIT_EDIT_FIELDS: |
---|
160 | form_fields = form_fields.omit(field) |
---|
161 | else: |
---|
162 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
163 | for field in UG_OMIT_EDIT_FIELDS: |
---|
164 | form_fields = form_fields.omit(field) |
---|
165 | form_fields['applicant_id'].for_display = True |
---|
166 | form_fields['reg_number'].for_display = True |
---|
167 | return form_fields |
---|