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

Last change on this file since 10533 was 10533, checked in by Henrik Bettermann, 11 years ago

UG applicants: make jamb_subjects' and jamb_score editable.

  • Property svn:keywords set to Id
File size: 5.8 KB
Line 
1## $Id: browser.py 10533 2013-08-25 06:11:19Z 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
28
29from kofacustom.nigeria.applicants.browser import (
30    NigeriaExportPDFPaymentSlipPage, NigeriaApplicantManageFormPage,
31    NigeriaApplicantDisplayFormPage, NigeriaApplicantEditFormPage)
32
33from kofacustom.nigeria.applicants.interfaces import (
34    UG_OMIT_DISPLAY_FIELDS,
35    UG_OMIT_PDF_FIELDS,
36    UG_OMIT_MANAGE_FIELDS,
37    UG_OMIT_EDIT_FIELDS
38    )
39from waeup.fceokene.applicants.interfaces import (
40    ICustomUGApplicant, ICustomUGApplicantEdit,
41    BEC_OMIT_DISPLAY_FIELDS,
42    BEC_OMIT_PDF_FIELDS,
43    BEC_OMIT_MANAGE_FIELDS,
44    BEC_OMIT_EDIT_FIELDS
45    )
46
47UG_OMIT_EDIT_FIELDS = [
48    value for value in UG_OMIT_EDIT_FIELDS
49        if not value in ('jamb_subjects', 'jamb_score')]
50
51class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
52    """A display view for applicant data.
53    """
54
55    @property
56    def form_fields(self):
57        target = getattr(self.context.__parent__, 'prefix', None)
58        form_fields = grok.AutoFields(ICustomUGApplicant)
59        if target is not None and target.startswith('bec'):
60            for field in BEC_OMIT_DISPLAY_FIELDS:
61                form_fields = form_fields.omit(field)
62        else:
63            form_fields = grok.AutoFields(ICustomUGApplicant)
64            for field in UG_OMIT_DISPLAY_FIELDS:
65                form_fields = form_fields.omit(field)
66        form_fields['notice'].custom_widget = BytesDisplayWidget
67        form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget
68        if not getattr(self.context, 'student_id'):
69            form_fields = form_fields.omit('student_id')
70        if not getattr(self.context, 'screening_score'):
71            form_fields = form_fields.omit('screening_score')
72        if not getattr(self.context, 'screening_venue'):
73            form_fields = form_fields.omit('screening_venue')
74        if not getattr(self.context, 'screening_date'):
75            form_fields = form_fields.omit('screening_date')
76        return form_fields
77
78class CustomPDFApplicationSlip(PDFApplicationSlip):
79
80    def _reduced_slip(self):
81        return getattr(self.context, 'result_uploaded', False)
82
83    @property
84    def form_fields(self):
85        target = getattr(self.context.__parent__, 'prefix', None)
86        form_fields = grok.AutoFields(ICustomUGApplicant)
87        if target is not None and target.startswith('bec'):
88            for field in BEC_OMIT_PDF_FIELDS:
89                form_fields = form_fields.omit(field)
90        else:
91            form_fields = grok.AutoFields(ICustomUGApplicant)
92            for field in UG_OMIT_PDF_FIELDS:
93                form_fields = form_fields.omit(field)
94        if not getattr(self.context, 'student_id'):
95            form_fields = form_fields.omit('student_id')
96        if not getattr(self.context, 'screening_score'):
97            form_fields = form_fields.omit('screening_score')
98        if not getattr(self.context, 'screening_venue'):
99            form_fields = form_fields.omit('screening_venue')
100        if not getattr(self.context, 'screening_date'):
101            form_fields = form_fields.omit('screening_date')
102        return form_fields
103
104class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
105    """Deliver a PDF slip of the context.
106    """
107
108    note = '''
109
110
111The total authorized amount includes an Interswitch transaction charge of 150 Nairas.
112'''
113
114class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
115    """A full edit view for applicant data.
116    """
117   
118    @property
119    def form_fields(self):
120        target = getattr(self.context.__parent__, 'prefix', None)
121        form_fields = grok.AutoFields(ICustomUGApplicant)
122        if target is not None and target.startswith('bec'):
123            for field in BEC_OMIT_MANAGE_FIELDS:
124                form_fields = form_fields.omit(field)
125        else:
126            for field in UG_OMIT_MANAGE_FIELDS:
127                form_fields = form_fields.omit(field)
128        form_fields['student_id'].for_display = True
129        form_fields['applicant_id'].for_display = True
130        return form_fields
131
132class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
133    """An applicant-centered edit view for applicant data.
134    """
135
136    @property
137    def form_fields(self):
138        target = getattr(self.context.__parent__, 'prefix', None)
139        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
140        if target is not None and target.startswith('bec'):
141            for field in BEC_OMIT_EDIT_FIELDS:
142                form_fields = form_fields.omit(field)
143        else:
144            for field in UG_OMIT_EDIT_FIELDS:
145                form_fields = form_fields.omit(field)
146        form_fields['applicant_id'].for_display = True
147        form_fields['reg_number'].for_display = True
148        return form_fields
Note: See TracBrowser for help on using the repository browser.