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

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

All 'pre' applicants must not edit name fields.

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