source: main/kofacustom.dspg/trunk/src/kofacustom/dspg/applicants/browser.py @ 14732

Last change on this file since 14732 was 14732, checked in by Henrik Bettermann, 7 years ago

Require uploading of picture before payment.

  • Property svn:keywords set to Id
File size: 8.1 KB
Line 
1## $Id: browser.py 14732 2017-07-27 05:22:28Z 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.interfaces import IExtFileStore, IKofaUtils
26from waeup.kofa.applicants.interfaces import (
27    IApplicant, IApplicantEdit, ISpecialApplicant)
28from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage,
29    ApplicantManageFormPage, ApplicantEditFormPage,
30    ApplicantsContainerPage, ApplicationFeePaymentAddPage)
31from waeup.kofa.applicants.viewlets import (
32    PaymentReceiptActionButton, PDFActionButton)
33from waeup.kofa.applicants.pdf import PDFApplicationSlip
34from kofacustom.nigeria.applicants.interfaces import (
35    UG_OMIT_DISPLAY_FIELDS,
36    UG_OMIT_PDF_FIELDS,
37    UG_OMIT_MANAGE_FIELDS,
38    UG_OMIT_EDIT_FIELDS
39    )
40from kofacustom.dspg.applicants.interfaces import (
41    ICustomUGApplicant, ICustomUGApplicantEdit,
42    ND_OMIT_DISPLAY_FIELDS,
43    ND_OMIT_PDF_FIELDS,
44    ND_OMIT_MANAGE_FIELDS,
45    ND_OMIT_EDIT_FIELDS
46    )
47
48from kofacustom.dspg.interfaces import MessageFactory as _
49
50UG_OMIT_EDIT_FIELDS = [
51    value for value in UG_OMIT_EDIT_FIELDS
52        if not value in ('jamb_subjects', 'jamb_score', 'jamb_reg_number')]
53
54PRE_OMIT_EDIT_FIELDS = UG_OMIT_EDIT_FIELDS + [
55    'firstname',
56    'middlename',
57    'lastname',
58    #'sex',
59    'jamb_score'
60    ]
61
62class CustomApplicantsContainerPage(ApplicantsContainerPage):
63    """The standard view for regular applicant containers.
64    """
65
66    @property
67    def form_fields(self):
68        form_fields = super(CustomApplicantsContainerPage, self).form_fields
69        if self.request.principal.id == 'zope.anybody':
70            return form_fields.omit('application_fee')
71        return form_fields
72
73class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage):
74    """A display view for applicant data.
75    """
76
77    @property
78    def form_fields(self):
79        if self.context.special:
80            return grok.AutoFields(ISpecialApplicant)
81        form_fields = grok.AutoFields(ICustomUGApplicant)
82        if self.context.is_nd:
83            for field in ND_OMIT_DISPLAY_FIELDS:
84                form_fields = form_fields.omit(field)
85        else:
86            form_fields = grok.AutoFields(ICustomUGApplicant)
87            for field in UG_OMIT_DISPLAY_FIELDS:
88                form_fields = form_fields.omit(field)
89        form_fields['notice'].custom_widget = BytesDisplayWidget
90        form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget
91        if not getattr(self.context, 'student_id'):
92            form_fields = form_fields.omit('student_id')
93        if not getattr(self.context, 'screening_score'):
94            form_fields = form_fields.omit('screening_score')
95        if not getattr(self.context, 'screening_venue'):
96            form_fields = form_fields.omit('screening_venue')
97        if not getattr(self.context, 'screening_date'):
98            form_fields = form_fields.omit('screening_date')
99        return form_fields
100
101class CustomPDFApplicationSlip(PDFApplicationSlip):
102
103    def _reduced_slip(self):
104        return getattr(self.context, 'result_uploaded', False)
105
106    @property
107    def note(self):
108        note = getattr(self.context.__parent__, 'application_slip_notice', None)
109        if note:
110            return '<br /><br />' + note
111        pronoun = 'S/he'
112        if self.context.sex == 'm':
113            pronoun = 'He'
114        else:
115            pronoun = 'She'
116        return '''<br /><br />
117The applicant has declared that:
118
119a) %s is not a member of any secret cult and will not join any.
120b) %s will not engage in any cult activities.
121c) %s will not be involved in any acts of terrorism, rape, robbery, fighting, illegal gathering and
122any activities that could disrupt peace on campus.
123d) %s does not have and will not acquire any form of weapon, fire arms, gun knife or any weapon
124that can cause damage to life and property.
125e) %s will strive to be worthy in character and learning at all times.
126
127The applicant has acknowledged that offences will automatically lead to the expulsion from the
128Polytechnic and also be dealt with in accordance with the law of the land.
129
130The applicant promises to abide by all the Rules and Regulations of the Polytechnic if offered
131admission.
132''' % (
133    pronoun, pronoun, pronoun, pronoun, pronoun)
134
135    @property
136    def form_fields(self):
137        form_fields = grok.AutoFields(ICustomUGApplicant)
138        if self.context.is_nd:
139            for field in ND_OMIT_PDF_FIELDS:
140                form_fields = form_fields.omit(field)
141        else:
142            form_fields = grok.AutoFields(ICustomUGApplicant)
143            for field in UG_OMIT_PDF_FIELDS:
144                form_fields = form_fields.omit(field)
145        if not getattr(self.context, 'student_id'):
146            form_fields = form_fields.omit('student_id')
147        if not getattr(self.context, 'screening_score'):
148            form_fields = form_fields.omit('screening_score')
149        if not getattr(self.context, 'screening_venue'):
150            form_fields = form_fields.omit('screening_venue')
151        if not getattr(self.context, 'screening_date'):
152            form_fields = form_fields.omit('screening_date')
153        return form_fields
154
155class CustomApplicantManageFormPage(ApplicantManageFormPage):
156    """A full edit view for applicant data.
157    """
158
159    @property
160    def form_fields(self):
161        if self.context.special:
162            form_fields = grok.AutoFields(ISpecialApplicant)
163            form_fields['applicant_id'].for_display = True
164            return form_fields
165        form_fields = grok.AutoFields(ICustomUGApplicant)
166        if self.context.is_nd:
167            for field in ND_OMIT_MANAGE_FIELDS:
168                form_fields = form_fields.omit(field)
169        else:
170            for field in UG_OMIT_MANAGE_FIELDS:
171                form_fields = form_fields.omit(field)
172        form_fields['student_id'].for_display = True
173        form_fields['applicant_id'].for_display = True
174        return form_fields
175
176class CustomApplicantEditFormPage(ApplicantEditFormPage):
177    """An applicant-centered edit view for applicant data.
178    """
179
180    @property
181    def form_fields(self):
182
183        if self.context.special:
184            form_fields = grok.AutoFields(ISpecialApplicant).omit(
185                'locked', 'suspended')
186            form_fields['applicant_id'].for_display = True
187            return form_fields
188        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
189        if self.context.is_nd:
190            for field in ND_OMIT_EDIT_FIELDS:
191                form_fields = form_fields.omit(field)
192        elif self.target is not None and self.target.startswith('pre'):
193            for field in PRE_OMIT_EDIT_FIELDS:
194                form_fields = form_fields.omit(field)
195        else:
196            for field in UG_OMIT_EDIT_FIELDS:
197                form_fields = form_fields.omit(field)
198        form_fields['applicant_id'].for_display = True
199        form_fields['reg_number'].for_display = True
200        return form_fields
201
202class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage):
203    """ Page to add an online payment ticket
204    """
205
206    @property
207    def custom_requirements(self):
208        store = getUtility(IExtFileStore)
209        if not store.getFileByContext(self.context, attr=u'passport.jpg'):
210            return _('Upload your passport photo before making payment.')
211        return ''
Note: See TracBrowser for help on using the repository browser.