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

Last change on this file since 16838 was 16769, checked in by Henrik Bettermann, 3 years ago

Adjust form.

  • Property svn:keywords set to Id
File size: 7.6 KB
Line 
1## $Id: browser.py 16769 2022-02-02 07:21:42Z 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.widgets.datewidget import FriendlyDatetimeDisplayWidget
24from zope.formlib.textwidgets import BytesDisplayWidget
25from waeup.kofa.students.interfaces import IStudentsUtils
26from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage,
27    ApplicantManageFormPage, ApplicantEditFormPage,
28    ApplicantRegistrationPage,
29    OnlinePaymentDisplayFormPage,
30    OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage,
31    )
32from waeup.kofa.applicants.viewlets import (
33    PDFActionButton, PaymentReceiptActionButton)
34from waeup.kofa.applicants.pdf import PDFApplicationSlip
35from kofacustom.nigeria.applicants.browser import (
36    NigeriaApplicantDisplayFormPage,
37    NigeriaApplicantManageFormPage,
38    NigeriaApplicantEditFormPage,
39    NigeriaPDFApplicationSlip)
40from kofacustom.nigeria.applicants.interfaces import (
41    INigeriaPGApplicant, INigeriaUGApplicant,
42    INigeriaPGApplicantEdit, INigeriaUGApplicantEdit,
43    INigeriaApplicantOnlinePayment,
44    #UG_OMIT_DISPLAY_FIELDS,
45    #UG_OMIT_PDF_FIELDS,
46    #UG_OMIT_MANAGE_FIELDS,
47    #UG_OMIT_EDIT_FIELDS,
48    PG_OMIT_DISPLAY_FIELDS,
49    PG_OMIT_PDF_FIELDS,
50    PG_OMIT_MANAGE_FIELDS,
51    PG_OMIT_EDIT_FIELDS,
52    )
53from kofacustom.edocons.applicants.interfaces import (
54    ICustomPGApplicant, ICustomUGApplicant, ICustomApplicant,
55    ICustomPGApplicantEdit, ICustomUGApplicantEdit,
56    ICustomApplicantOnlinePayment,
57    )
58from kofacustom.nigeria.interfaces import MessageFactory as _
59
60# Fields to be omitted in all display forms. course_admitted is
61# rendered separately.
62
63OMIT_DISPLAY_FIELDS = ('locked', 'course_admitted',
64    'result_uploaded', 'suspended', 'special_application',
65    'bank_account_number',
66    'bank_account_name',
67    'bank_name',
68    'course1', 'course2') # these 2 have been added
69
70# UG students are all undergraduate students.
71UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
72    'jamb_subjects_list', 'programme_type')
73UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',)
74UG_OMIT_MANAGE_FIELDS = (
75    'special_application',
76    'jamb_subjects_list',
77    'programme_type',
78    'course1', 'course2') # these 2 have been added
79UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
80    'student_id',
81    'notice',
82    'screening_score',
83    'screening_venue',
84    'screening_date',
85    'cbt_score',
86    'cbt_venue',
87    'cbt_date',
88    'jamb_age',
89    'jamb_subjects',
90    'jamb_score',
91    'jamb_reg_number',
92    'aggregate')
93
94class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
95    """A display view for applicant data.
96    """
97
98    @property
99    def form_fields(self):
100        if self.target is not None and self.target.startswith('pg'):
101            form_fields = grok.AutoFields(ICustomPGApplicant)
102            for field in PG_OMIT_DISPLAY_FIELDS:
103                form_fields = form_fields.omit(field)
104        else:
105            form_fields = grok.AutoFields(ICustomUGApplicant)
106            for field in UG_OMIT_DISPLAY_FIELDS:
107                form_fields = form_fields.omit(field)
108        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
109        form_fields['notice'].custom_widget = BytesDisplayWidget
110        if not getattr(self.context, 'student_id'):
111            form_fields = form_fields.omit('student_id')
112        if not getattr(self.context, 'screening_score'):
113            form_fields = form_fields.omit('screening_score')
114        if not getattr(self.context, 'screening_venue') or self._not_paid():
115            form_fields = form_fields.omit('screening_venue')
116        if not getattr(self.context, 'screening_date') or self._not_paid():
117            form_fields = form_fields.omit('screening_date')
118        if not getattr(self.context, 'cbt_score'):
119            form_fields = form_fields.omit('cbt_score')
120        if not getattr(self.context, 'cbt_venue') or self._not_paid():
121            form_fields = form_fields.omit('cbt_venue')
122        if not getattr(self.context, 'cbt_date') or self._not_paid():
123            form_fields = form_fields.omit('cbt_date')
124        return form_fields
125
126class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
127
128    @property
129    def form_fields(self):
130        if self.target is not None and self.target.startswith('pg'):
131            form_fields = grok.AutoFields(ICustomPGApplicant)
132            for field in PG_OMIT_PDF_FIELDS:
133                form_fields = form_fields.omit(field)
134        else:
135            form_fields = grok.AutoFields(ICustomUGApplicant)
136            for field in UG_OMIT_PDF_FIELDS:
137                form_fields = form_fields.omit(field)
138        if not getattr(self.context, 'student_id'):
139            form_fields = form_fields.omit('student_id')
140        if not getattr(self.context, 'screening_score'):
141            form_fields = form_fields.omit('screening_score')
142        if not getattr(self.context, 'screening_venue'):
143            form_fields = form_fields.omit('screening_venue')
144        if not getattr(self.context, 'screening_date'):
145            form_fields = form_fields.omit('screening_date')
146        if not getattr(self.context, 'cbt_score'):
147            form_fields = form_fields.omit('cbt_score')
148        if not getattr(self.context, 'cbt_venue'):
149            form_fields = form_fields.omit('cbt_venue')
150        if not getattr(self.context, 'cbt_date'):
151            form_fields = form_fields.omit('cbt_date')
152        return form_fields
153
154class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
155    """A full edit view for applicant data.
156    """
157
158    @property
159    def form_fields(self):
160        if self.target is not None and self.target.startswith('pg'):
161            form_fields = grok.AutoFields(ICustomPGApplicant)
162            for field in PG_OMIT_MANAGE_FIELDS:
163                form_fields = form_fields.omit(field)
164        else:
165            form_fields = grok.AutoFields(ICustomUGApplicant)
166            for field in UG_OMIT_MANAGE_FIELDS:
167                form_fields = form_fields.omit(field)
168        form_fields['student_id'].for_display = True
169        form_fields['applicant_id'].for_display = True
170        return form_fields
171
172class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
173    """An applicant-centered edit view for applicant data.
174    """
175
176    def unremovable(self, ticket):
177        return True
178
179    @property
180    def form_fields(self):
181        if self.target is not None and self.target.startswith('pg'):
182            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
183            for field in PG_OMIT_EDIT_FIELDS:
184                form_fields = form_fields.omit(field)
185        else:
186            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
187            for field in UG_OMIT_EDIT_FIELDS:
188                form_fields = form_fields.omit(field)
189        form_fields['applicant_id'].for_display = True
190        form_fields['reg_number'].for_display = True
191        return form_fields
Note: See TracBrowser for help on using the repository browser.