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

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