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

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

Revert previous revision.

  • Property svn:keywords set to Id
File size: 6.2 KB
Line 
1## $Id: browser.py 17420 2023-05-24 14:59:43Z 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
57# UG students are all undergraduate students.
58UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + (
59    'jamb_subjects_list',
60    'programme_type',)
61UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',)
62UG_OMIT_MANAGE_FIELDS = (
63    'special_application',
64    'jamb_subjects_list',
65    'programme_type',)
66UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + (
67    'student_id',
68    'notice',
69    'screening_score',
70    'screening_venue',
71    'screening_date',
72    'jamb_age',
73    #'jamb_subjects',
74    #'jamb_score',
75    #'jamb_reg_number',
76    'aggregate',)
77
78
79class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
80    """A display view for applicant data.
81    """
82
83    @property
84    def form_fields(self):
85        if self.target is not None and self.target.startswith('pg'):
86            form_fields = grok.AutoFields(ICustomPGApplicant)
87            for field in PG_OMIT_DISPLAY_FIELDS:
88                form_fields = form_fields.omit(field)
89        else:
90            form_fields = grok.AutoFields(ICustomUGApplicant)
91            for field in UG_OMIT_DISPLAY_FIELDS:
92                form_fields = form_fields.omit(field)
93        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
94        form_fields['notice'].custom_widget = BytesDisplayWidget
95        if not getattr(self.context, 'student_id'):
96            form_fields = form_fields.omit('student_id')
97        if not getattr(self.context, 'screening_score'):
98            form_fields = form_fields.omit('screening_score')
99        if not getattr(self.context, 'screening_venue') or self._not_paid():
100            form_fields = form_fields.omit('screening_venue')
101        if not getattr(self.context, 'screening_date') or self._not_paid():
102            form_fields = form_fields.omit('screening_date')
103        return form_fields
104
105class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
106
107    @property
108    def form_fields(self):
109        if self.target is not None and self.target.startswith('pg'):
110            form_fields = grok.AutoFields(ICustomPGApplicant)
111            for field in PG_OMIT_PDF_FIELDS:
112                form_fields = form_fields.omit(field)
113        else:
114            form_fields = grok.AutoFields(ICustomUGApplicant)
115            for field in UG_OMIT_PDF_FIELDS:
116                form_fields = form_fields.omit(field)
117        if not getattr(self.context, 'student_id'):
118            form_fields = form_fields.omit('student_id')
119        if not getattr(self.context, 'screening_score'):
120            form_fields = form_fields.omit('screening_score')
121        if not getattr(self.context, 'screening_venue'):
122            form_fields = form_fields.omit('screening_venue')
123        if not getattr(self.context, 'screening_date'):
124            form_fields = form_fields.omit('screening_date')
125        return form_fields
126
127class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
128    """A full edit view for applicant data.
129    """
130
131    @property
132    def form_fields(self):
133        if self.target is not None and self.target.startswith('pg'):
134            form_fields = grok.AutoFields(ICustomPGApplicant)
135            for field in PG_OMIT_MANAGE_FIELDS:
136                form_fields = form_fields.omit(field)
137        else:
138            form_fields = grok.AutoFields(ICustomUGApplicant)
139            for field in UG_OMIT_MANAGE_FIELDS:
140                form_fields = form_fields.omit(field)
141        form_fields['student_id'].for_display = True
142        form_fields['applicant_id'].for_display = True
143        return form_fields
144
145class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
146    """An applicant-centered edit view for applicant data.
147    """
148
149    def unremovable(self, ticket):
150        return True
151
152    @property
153    def form_fields(self):
154        if self.target is not None and self.target.startswith('pg'):
155            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
156            for field in PG_OMIT_EDIT_FIELDS:
157                form_fields = form_fields.omit(field)
158        else:
159            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
160            for field in UG_OMIT_EDIT_FIELDS:
161                form_fields = form_fields.omit(field)
162        form_fields['applicant_id'].for_display = True
163        form_fields['reg_number'].for_display = True
164        return form_fields
Note: See TracBrowser for help on using the repository browser.