source: main/waeup.fceokene/trunk/src/waeup/fceokene/applicants/browser.py @ 13627

Last change on this file since 13627 was 13238, checked in by Henrik Bettermann, 9 years ago

Make jamb_reg_number editable by applicants.

  • Property svn:keywords set to Id
File size: 6.8 KB
Line 
1## $Id: browser.py 13238 2015-09-03 20:03:22Z 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.applicants.viewlets import (
26    PaymentReceiptActionButton, PDFActionButton)
27from waeup.kofa.applicants.pdf import PDFApplicationSlip
28from waeup.kofa.interfaces import IKofaUtils
29from waeup.kofa.browser.interfaces import IPDFCreator
30
31from kofacustom.nigeria.applicants.browser import (
32    NigeriaExportPDFPaymentSlipPage, NigeriaApplicantManageFormPage,
33    NigeriaApplicantDisplayFormPage, NigeriaApplicantEditFormPage)
34
35from waeup.fceokene.interfaces import MessageFactory as _
36
37from kofacustom.nigeria.applicants.interfaces import (
38    UG_OMIT_DISPLAY_FIELDS,
39    UG_OMIT_PDF_FIELDS,
40    UG_OMIT_MANAGE_FIELDS,
41    UG_OMIT_EDIT_FIELDS
42    )
43from waeup.fceokene.applicants.interfaces import (
44    ICustomUGApplicant, ICustomUGApplicantEdit,
45    BEC_OMIT_DISPLAY_FIELDS,
46    BEC_OMIT_PDF_FIELDS,
47    BEC_OMIT_MANAGE_FIELDS,
48    BEC_OMIT_EDIT_FIELDS
49    )
50
51UG_OMIT_EDIT_FIELDS = [
52    value for value in UG_OMIT_EDIT_FIELDS
53        if not value in ('jamb_subjects', 'jamb_score', 'jamb_reg_number')]
54
55class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
56    """A display view for applicant data.
57    """
58
59    @property
60    def form_fields(self):
61        target = getattr(self.context.__parent__, 'prefix', None)
62        form_fields = grok.AutoFields(ICustomUGApplicant)
63        if target is not None and target.startswith('bec'):
64            for field in BEC_OMIT_DISPLAY_FIELDS:
65                form_fields = form_fields.omit(field)
66        else:
67            form_fields = grok.AutoFields(ICustomUGApplicant)
68            for field in UG_OMIT_DISPLAY_FIELDS:
69                form_fields = form_fields.omit(field)
70        form_fields['notice'].custom_widget = BytesDisplayWidget
71        form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget
72        if not getattr(self.context, 'student_id'):
73            form_fields = form_fields.omit('student_id')
74        if not getattr(self.context, 'screening_score'):
75            form_fields = form_fields.omit('screening_score')
76        if not getattr(self.context, 'screening_venue'):
77            form_fields = form_fields.omit('screening_venue')
78        if not getattr(self.context, 'screening_date'):
79            form_fields = form_fields.omit('screening_date')
80        return form_fields
81
82class CustomPDFApplicationSlip(PDFApplicationSlip):
83
84    def _reduced_slip(self):
85        return getattr(self.context, 'result_uploaded', False)
86
87    def _getPDFCreator(self):
88        if 'putme' in self.target or 'pude' in self.target:
89            return getUtility(IPDFCreator, name='ibadan_pdfcreator')
90        return getUtility(IPDFCreator)
91
92    @property
93    def title(self):
94        container_title = self.context.__parent__.title
95        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
96        ar_translation = translate(_('Application Record'),
97            'waeup.kofa', target_language=portal_language)
98        if 'putme' in self.target or 'pude' in self.target:
99            return 'IN AFFILIATION WITH UNIVERSITY OF IBADAN - %s %s %s' % (
100                container_title, ar_translation,
101                self.context.application_number)
102        return '%s - %s %s' % (container_title,
103            ar_translation, self.context.application_number)
104
105
106    @property
107    def form_fields(self):
108        target = getattr(self.context.__parent__, 'prefix', None)
109        form_fields = grok.AutoFields(ICustomUGApplicant)
110        if target is not None and target.startswith('bec'):
111            for field in BEC_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 CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
128    """Deliver a PDF slip of the context.
129    """
130
131    note = '''
132
133
134The total authorized amount includes an Interswitch transaction charge of 150 Nairas.
135'''
136
137class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
138    """A full edit view for applicant data.
139    """
140   
141    @property
142    def form_fields(self):
143        target = getattr(self.context.__parent__, 'prefix', None)
144        form_fields = grok.AutoFields(ICustomUGApplicant)
145        if target is not None and target.startswith('bec'):
146            for field in BEC_OMIT_MANAGE_FIELDS:
147                form_fields = form_fields.omit(field)
148        else:
149            for field in UG_OMIT_MANAGE_FIELDS:
150                form_fields = form_fields.omit(field)
151        form_fields['student_id'].for_display = True
152        form_fields['applicant_id'].for_display = True
153        return form_fields
154
155class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
156    """An applicant-centered edit view for applicant data.
157    """
158
159    @property
160    def form_fields(self):
161        target = getattr(self.context.__parent__, 'prefix', None)
162        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
163        if target is not None and target.startswith('bec'):
164            for field in BEC_OMIT_EDIT_FIELDS:
165                form_fields = form_fields.omit(field)
166        else:
167            for field in UG_OMIT_EDIT_FIELDS:
168                form_fields = form_fields.omit(field)
169        form_fields['applicant_id'].for_display = True
170        form_fields['reg_number'].for_display = True
171        return form_fields
Note: See TracBrowser for help on using the repository browser.