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

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

Applicants are not allowed to remove payment tickets.

  • Property svn:keywords set to Id
File size: 6.9 KB
Line 
1## $Id: browser.py 16664 2021-10-05 12:24:10Z 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    'jamb_age',
86    'jamb_subjects',
87    'jamb_score',
88    'jamb_reg_number',
89    'aggregate')
90
91class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
92    """A display view for applicant data.
93    """
94
95    @property
96    def form_fields(self):
97        if self.target is not None and self.target.startswith('pg'):
98            form_fields = grok.AutoFields(ICustomPGApplicant)
99            for field in PG_OMIT_DISPLAY_FIELDS:
100                form_fields = form_fields.omit(field)
101        else:
102            form_fields = grok.AutoFields(ICustomUGApplicant)
103            for field in UG_OMIT_DISPLAY_FIELDS:
104                form_fields = form_fields.omit(field)
105        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
106        form_fields['notice'].custom_widget = BytesDisplayWidget
107        if not getattr(self.context, 'student_id'):
108            form_fields = form_fields.omit('student_id')
109        if not getattr(self.context, 'screening_score'):
110            form_fields = form_fields.omit('screening_score')
111        if not getattr(self.context, 'screening_venue') or self._not_paid():
112            form_fields = form_fields.omit('screening_venue')
113        if not getattr(self.context, 'screening_date') or self._not_paid():
114            form_fields = form_fields.omit('screening_date')
115        return form_fields
116
117class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
118
119    @property
120    def form_fields(self):
121        if self.target is not None and self.target.startswith('pg'):
122            form_fields = grok.AutoFields(ICustomPGApplicant)
123            for field in PG_OMIT_PDF_FIELDS:
124                form_fields = form_fields.omit(field)
125        else:
126            form_fields = grok.AutoFields(ICustomUGApplicant)
127            for field in UG_OMIT_PDF_FIELDS:
128                form_fields = form_fields.omit(field)
129        if not getattr(self.context, 'student_id'):
130            form_fields = form_fields.omit('student_id')
131        if not getattr(self.context, 'screening_score'):
132            form_fields = form_fields.omit('screening_score')
133        if not getattr(self.context, 'screening_venue'):
134            form_fields = form_fields.omit('screening_venue')
135        if not getattr(self.context, 'screening_date'):
136            form_fields = form_fields.omit('screening_date')
137        return form_fields
138
139class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
140    """A full edit view for applicant data.
141    """
142
143    @property
144    def form_fields(self):
145        if self.target is not None and self.target.startswith('pg'):
146            form_fields = grok.AutoFields(ICustomPGApplicant)
147            for field in PG_OMIT_MANAGE_FIELDS:
148                form_fields = form_fields.omit(field)
149        else:
150            form_fields = grok.AutoFields(ICustomUGApplicant)
151            for field in UG_OMIT_MANAGE_FIELDS:
152                form_fields = form_fields.omit(field)
153        form_fields['student_id'].for_display = True
154        form_fields['applicant_id'].for_display = True
155        return form_fields
156
157class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
158    """An applicant-centered edit view for applicant data.
159    """
160
161    def unremovable(self, ticket):
162        return True
163
164    @property
165    def form_fields(self):
166        if self.target is not None and self.target.startswith('pg'):
167            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
168            for field in PG_OMIT_EDIT_FIELDS:
169                form_fields = form_fields.omit(field)
170        else:
171            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
172            for field in UG_OMIT_EDIT_FIELDS:
173                form_fields = form_fields.omit(field)
174        form_fields['applicant_id'].for_display = True
175        form_fields['reg_number'].for_display = True
176        return form_fields
Note: See TracBrowser for help on using the repository browser.