source: main/kofacustom.unidel/trunk/src/kofacustom/unidel/applicants/browser.py @ 17647

Last change on this file since 17647 was 17479, checked in by Henrik Bettermann, 18 months ago

Change fields.

  • Property svn:keywords set to Id
File size: 6.4 KB
Line 
1## $Id: browser.py 17479 2023-07-10 17:28:32Z 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.formlib.textwidgets import BytesDisplayWidget
22from waeup.kofa.applicants.browser import (
23    ApplicantRegistrationPage, ApplicantsContainerPage)
24from kofacustom.nigeria.applicants.browser import (
25    NigeriaApplicantDisplayFormPage,
26    NigeriaApplicantManageFormPage,
27    NigeriaApplicantEditFormPage,
28    NigeriaPDFApplicationSlip)
29
30from 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    )
43from kofacustom.unidel.applicants.interfaces import (
44    ICustomPGApplicant, ICustomUGApplicant, ICustomApplicant,
45    ICustomPGApplicantEdit, ICustomUGApplicantEdit,
46    ICustomApplicantOnlinePayment,
47    )
48
49from kofacustom.unidel.interfaces import MessageFactory as _
50
51OMIT_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.
59UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
60    'jamb_subjects_list',
61    'programme_type',)
62UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',)
63UG_OMIT_MANAGE_FIELDS = (
64    'special_application',
65    'jamb_subjects_list',
66    'programme_type',)
67UG_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
80
81class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
82    """A display view for applicant data.
83    """
84
85    @property
86    def form_fields(self):
87        if self.target is not None and self.target.startswith('pg'):
88            form_fields = grok.AutoFields(ICustomPGApplicant)
89            for field in PG_OMIT_DISPLAY_FIELDS:
90                form_fields = form_fields.omit(field)
91        else:
92            form_fields = grok.AutoFields(ICustomUGApplicant)
93            for field in UG_OMIT_DISPLAY_FIELDS:
94                form_fields = form_fields.omit(field)
95        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
96        form_fields['notice'].custom_widget = BytesDisplayWidget
97        if not getattr(self.context, 'student_id'):
98            form_fields = form_fields.omit('student_id')
99        if not getattr(self.context, 'screening_score'):
100            form_fields = form_fields.omit('screening_score')
101        if not getattr(self.context, 'screening_venue') or self._not_paid():
102            form_fields = form_fields.omit('screening_venue')
103        if not getattr(self.context, 'screening_date') or self._not_paid():
104            form_fields = form_fields.omit('screening_date')
105        return form_fields
106
107class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
108
109    @property
110    def form_fields(self):
111        if self.target is not None and self.target.startswith('pg'):
112            form_fields = grok.AutoFields(ICustomPGApplicant)
113            for field in PG_OMIT_PDF_FIELDS:
114                form_fields = form_fields.omit(field)
115        else:
116            form_fields = grok.AutoFields(ICustomUGApplicant)
117            for field in UG_OMIT_PDF_FIELDS:
118                form_fields = form_fields.omit(field)
119        if not getattr(self.context, 'student_id'):
120            form_fields = form_fields.omit('student_id')
121        if not getattr(self.context, 'screening_score'):
122            form_fields = form_fields.omit('screening_score')
123        if not getattr(self.context, 'screening_venue'):
124            form_fields = form_fields.omit('screening_venue')
125        if not getattr(self.context, 'screening_date'):
126            form_fields = form_fields.omit('screening_date')
127        return form_fields
128
129class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
130    """A full edit view for applicant data.
131    """
132
133    @property
134    def form_fields(self):
135        if self.target is not None and self.target.startswith('pg'):
136            form_fields = grok.AutoFields(ICustomPGApplicant)
137            for field in PG_OMIT_MANAGE_FIELDS:
138                form_fields = form_fields.omit(field)
139        else:
140            form_fields = grok.AutoFields(ICustomUGApplicant)
141            for field in UG_OMIT_MANAGE_FIELDS:
142                form_fields = form_fields.omit(field)
143        form_fields['student_id'].for_display = True
144        form_fields['applicant_id'].for_display = True
145        return form_fields
146
147class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
148    """An applicant-centered edit view for applicant data.
149    """
150
151    def unremovable(self, ticket):
152        return True
153
154    @property
155    def form_fields(self):
156        if self.target is not None and self.target.startswith('pg'):
157            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
158            for field in PG_OMIT_EDIT_FIELDS:
159                form_fields = form_fields.omit(field)
160        else:
161            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
162            for field in UG_OMIT_EDIT_FIELDS:
163                form_fields = form_fields.omit(field)
164        form_fields['applicant_id'].for_display = True
165        form_fields['reg_number'].for_display = True
166        form_fields['firstname'].for_display = True
167        form_fields['middlename'].for_display = True
168        form_fields['lastname'].for_display = True
169        return form_fields
Note: See TracBrowser for help on using the repository browser.