source: main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/applicants/browser.py @ 10628

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

PREJAMBITES must not edit 'firstname', 'middlename', 'lastname', 'sex', 'jamb_score'

  • Property svn:keywords set to Id
File size: 5.8 KB
Line 
1## $Id: browser.py 10628 2013-09-20 16:51:08Z 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.browser import (ApplicantDisplayFormPage,
26    ApplicantManageFormPage, ApplicantEditFormPage,
27    ApplicantsContainerPage)
28from waeup.kofa.applicants.viewlets import (
29    PaymentReceiptActionButton, PDFActionButton)
30from waeup.kofa.applicants.pdf import PDFApplicationSlip
31from kofacustom.nigeria.applicants.interfaces import (
32    UG_OMIT_DISPLAY_FIELDS,
33    UG_OMIT_PDF_FIELDS,
34    UG_OMIT_MANAGE_FIELDS,
35    UG_OMIT_EDIT_FIELDS
36    )
37from waeup.kwarapoly.applicants.interfaces import (
38    ICustomUGApplicant, ICustomUGApplicantEdit,
39    ND_OMIT_DISPLAY_FIELDS,
40    ND_OMIT_PDF_FIELDS,
41    ND_OMIT_MANAGE_FIELDS,
42    ND_OMIT_EDIT_FIELDS
43    )
44
45UG_OMIT_EDIT_FIELDS = [
46    value for value in UG_OMIT_EDIT_FIELDS
47        if not value in ('jamb_subjects', 'jamb_score')]
48
49PREJAMBITES_OMIT_EDIT_FIELDS = UG_OMIT_EDIT_FIELDS + [
50    'firstname',
51    'middlename',
52    'lastname',
53    'sex', 'jamb_score'
54    ]
55
56class CustomApplicantsContainerPage(ApplicantsContainerPage):
57    """The standard view for regular applicant containers.
58    """
59
60    @property
61    def form_fields(self):
62        form_fields = super(CustomApplicantsContainerPage, self).form_fields
63        if self.request.principal.id == 'zope.anybody':
64            return form_fields.omit('application_fee')
65        return form_fields
66
67class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage):
68    """A display view for applicant data.
69    """
70
71    @property
72    def form_fields(self):
73        form_fields = grok.AutoFields(ICustomUGApplicant)
74        if self.context.is_nd:
75            for field in ND_OMIT_DISPLAY_FIELDS:
76                form_fields = form_fields.omit(field)
77        else:
78            form_fields = grok.AutoFields(ICustomUGApplicant)
79            for field in UG_OMIT_DISPLAY_FIELDS:
80                form_fields = form_fields.omit(field)
81        form_fields['notice'].custom_widget = BytesDisplayWidget
82        form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget
83        if not getattr(self.context, 'student_id'):
84            form_fields = form_fields.omit('student_id')
85        if not getattr(self.context, 'screening_score'):
86            form_fields = form_fields.omit('screening_score')
87        if not getattr(self.context, 'screening_venue'):
88            form_fields = form_fields.omit('screening_venue')
89        if not getattr(self.context, 'screening_date'):
90            form_fields = form_fields.omit('screening_date')
91        return form_fields
92
93class CustomPDFApplicationSlip(PDFApplicationSlip):
94
95    def _reduced_slip(self):
96        return getattr(self.context, 'result_uploaded', False)
97
98    @property
99    def form_fields(self):
100        form_fields = grok.AutoFields(ICustomUGApplicant)
101        if self.context.is_nd:
102            for field in ND_OMIT_PDF_FIELDS:
103                form_fields = form_fields.omit(field)
104        else:
105            form_fields = grok.AutoFields(ICustomUGApplicant)
106            for field in UG_OMIT_PDF_FIELDS:
107                form_fields = form_fields.omit(field)
108        if not getattr(self.context, 'student_id'):
109            form_fields = form_fields.omit('student_id')
110        if not getattr(self.context, 'screening_score'):
111            form_fields = form_fields.omit('screening_score')
112        if not getattr(self.context, 'screening_venue'):
113            form_fields = form_fields.omit('screening_venue')
114        if not getattr(self.context, 'screening_date'):
115            form_fields = form_fields.omit('screening_date')
116        return form_fields
117
118class CustomApplicantManageFormPage(ApplicantManageFormPage):
119    """A full edit view for applicant data.
120    """
121   
122    @property
123    def form_fields(self):
124        form_fields = grok.AutoFields(ICustomUGApplicant)
125        if self.context.is_nd:
126            for field in ND_OMIT_MANAGE_FIELDS:
127                form_fields = form_fields.omit(field)
128        else:
129            for field in UG_OMIT_MANAGE_FIELDS:
130                form_fields = form_fields.omit(field)
131        form_fields['student_id'].for_display = True
132        form_fields['applicant_id'].for_display = True
133        return form_fields
134
135class CustomApplicantEditFormPage(ApplicantEditFormPage):
136    """An applicant-centered edit view for applicant data.
137    """
138
139    @property
140    def form_fields(self):
141        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
142        if self.context.is_nd:
143            for field in ND_OMIT_EDIT_FIELDS:
144                form_fields = form_fields.omit(field)
145        elif self.target is not None and self.target.startswith('prejambites'):
146            for field in PREJAMBITES_OMIT_EDIT_FIELDS:
147                form_fields = form_fields.omit(field)
148        else:
149            for field in UG_OMIT_EDIT_FIELDS:
150                form_fields = form_fields.omit(field)
151        form_fields['applicant_id'].for_display = True
152        form_fields['reg_number'].for_display = True
153        return form_fields
Note: See TracBrowser for help on using the repository browser.