1 | ## $Id: browser.py 10847 2013-12-15 07:12:58Z 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 waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
24 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
25 | from waeup.kofa.applicants.interfaces import ( |
---|
26 | IApplicant, IApplicantEdit, ISpecialApplicant) |
---|
27 | from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage, |
---|
28 | ApplicantManageFormPage, ApplicantEditFormPage, |
---|
29 | ApplicantsContainerPage) |
---|
30 | from waeup.kofa.applicants.viewlets import ( |
---|
31 | PaymentReceiptActionButton, PDFActionButton) |
---|
32 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
33 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
34 | UG_OMIT_DISPLAY_FIELDS, |
---|
35 | UG_OMIT_PDF_FIELDS, |
---|
36 | UG_OMIT_MANAGE_FIELDS, |
---|
37 | UG_OMIT_EDIT_FIELDS |
---|
38 | ) |
---|
39 | from waeup.kwarapoly.applicants.interfaces import ( |
---|
40 | ICustomUGApplicant, ICustomUGApplicantEdit, |
---|
41 | ND_OMIT_DISPLAY_FIELDS, |
---|
42 | ND_OMIT_PDF_FIELDS, |
---|
43 | ND_OMIT_MANAGE_FIELDS, |
---|
44 | ND_OMIT_EDIT_FIELDS |
---|
45 | ) |
---|
46 | |
---|
47 | UG_OMIT_EDIT_FIELDS = [ |
---|
48 | value for value in UG_OMIT_EDIT_FIELDS |
---|
49 | if not value in ('jamb_subjects', 'jamb_score')] |
---|
50 | |
---|
51 | PRE_OMIT_EDIT_FIELDS = UG_OMIT_EDIT_FIELDS + [ |
---|
52 | 'firstname', |
---|
53 | 'middlename', |
---|
54 | 'lastname', |
---|
55 | 'sex', |
---|
56 | 'jamb_score' |
---|
57 | ] |
---|
58 | |
---|
59 | class CustomApplicantsContainerPage(ApplicantsContainerPage): |
---|
60 | """The standard view for regular applicant containers. |
---|
61 | """ |
---|
62 | |
---|
63 | @property |
---|
64 | def form_fields(self): |
---|
65 | form_fields = super(CustomApplicantsContainerPage, self).form_fields |
---|
66 | if self.request.principal.id == 'zope.anybody': |
---|
67 | return form_fields.omit('application_fee') |
---|
68 | return form_fields |
---|
69 | |
---|
70 | class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage): |
---|
71 | """A display view for applicant data. |
---|
72 | """ |
---|
73 | |
---|
74 | @property |
---|
75 | def form_fields(self): |
---|
76 | if self.context.special: |
---|
77 | return grok.AutoFields(ISpecialApplicant) |
---|
78 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
79 | if self.context.is_nd: |
---|
80 | for field in ND_OMIT_DISPLAY_FIELDS: |
---|
81 | form_fields = form_fields.omit(field) |
---|
82 | else: |
---|
83 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
84 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
85 | form_fields = form_fields.omit(field) |
---|
86 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
87 | form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget |
---|
88 | if not getattr(self.context, 'student_id'): |
---|
89 | form_fields = form_fields.omit('student_id') |
---|
90 | if not getattr(self.context, 'screening_score'): |
---|
91 | form_fields = form_fields.omit('screening_score') |
---|
92 | if not getattr(self.context, 'screening_venue'): |
---|
93 | form_fields = form_fields.omit('screening_venue') |
---|
94 | if not getattr(self.context, 'screening_date'): |
---|
95 | form_fields = form_fields.omit('screening_date') |
---|
96 | return form_fields |
---|
97 | |
---|
98 | class CustomPDFApplicationSlip(PDFApplicationSlip): |
---|
99 | |
---|
100 | def _reduced_slip(self): |
---|
101 | return getattr(self.context, 'result_uploaded', False) |
---|
102 | |
---|
103 | @property |
---|
104 | def form_fields(self): |
---|
105 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
106 | if self.context.is_nd: |
---|
107 | for field in ND_OMIT_PDF_FIELDS: |
---|
108 | form_fields = form_fields.omit(field) |
---|
109 | else: |
---|
110 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
111 | for field in UG_OMIT_PDF_FIELDS: |
---|
112 | form_fields = form_fields.omit(field) |
---|
113 | if not getattr(self.context, 'student_id'): |
---|
114 | form_fields = form_fields.omit('student_id') |
---|
115 | if not getattr(self.context, 'screening_score'): |
---|
116 | form_fields = form_fields.omit('screening_score') |
---|
117 | if not getattr(self.context, 'screening_venue'): |
---|
118 | form_fields = form_fields.omit('screening_venue') |
---|
119 | if not getattr(self.context, 'screening_date'): |
---|
120 | form_fields = form_fields.omit('screening_date') |
---|
121 | return form_fields |
---|
122 | |
---|
123 | class CustomApplicantManageFormPage(ApplicantManageFormPage): |
---|
124 | """A full edit view for applicant data. |
---|
125 | """ |
---|
126 | |
---|
127 | @property |
---|
128 | def form_fields(self): |
---|
129 | if self.context.special: |
---|
130 | return grok.AutoFields(ISpecialApplicant) |
---|
131 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
132 | if self.context.is_nd: |
---|
133 | for field in ND_OMIT_MANAGE_FIELDS: |
---|
134 | form_fields = form_fields.omit(field) |
---|
135 | else: |
---|
136 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
137 | form_fields = form_fields.omit(field) |
---|
138 | form_fields['student_id'].for_display = True |
---|
139 | form_fields['applicant_id'].for_display = True |
---|
140 | return form_fields |
---|
141 | |
---|
142 | class CustomApplicantEditFormPage(ApplicantEditFormPage): |
---|
143 | """An applicant-centered edit view for applicant data. |
---|
144 | """ |
---|
145 | |
---|
146 | @property |
---|
147 | def form_fields(self): |
---|
148 | |
---|
149 | if self.context.special: |
---|
150 | return grok.AutoFields(ISpecialApplicant) |
---|
151 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
152 | if self.context.is_nd: |
---|
153 | for field in ND_OMIT_EDIT_FIELDS: |
---|
154 | form_fields = form_fields.omit(field) |
---|
155 | elif self.target is not None and self.target.startswith('pre'): |
---|
156 | for field in PRE_OMIT_EDIT_FIELDS: |
---|
157 | form_fields = form_fields.omit(field) |
---|
158 | else: |
---|
159 | for field in UG_OMIT_EDIT_FIELDS: |
---|
160 | form_fields = form_fields.omit(field) |
---|
161 | form_fields['applicant_id'].for_display = True |
---|
162 | form_fields['reg_number'].for_display = True |
---|
163 | return form_fields |
---|