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

Last change on this file since 10279 was 10134, checked in by Henrik Bettermann, 12 years ago

Customize ApplicantsContainerPage? to omit application_fee.

  • Property svn:keywords set to Id
File size: 5.3 KB
RevLine 
[10132]1## $Id: browser.py 10134 2013-05-02 11:34:38Z 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,
[10134]26    ApplicantManageFormPage, ApplicantEditFormPage,
27    ApplicantsContainerPage)
[10132]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
[10134]45class CustomApplicantsContainerPage(ApplicantsContainerPage):
46    """The standard view for regular applicant containers.
47    """
48
49    @property
50    def form_fields(self):
51        form_fields = super(CustomApplicantsContainerPage, self).form_fields
52        if self.request.principal.id == 'zope.anybody':
53            return form_fields.omit('application_fee')
54        return form_fields
55
[10132]56class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage):
57    """A display view for applicant data.
58    """
59
60    @property
61    def form_fields(self):
62        form_fields = grok.AutoFields(ICustomUGApplicant)
63        if self.context.is_nd:
64            for field in ND_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        if not getattr(self.context, 'student_id'):
72            form_fields = form_fields.omit('student_id')
73        if not getattr(self.context, 'screening_score'):
74            form_fields = form_fields.omit('screening_score')
75        if not getattr(self.context, 'screening_venue'):
76            form_fields = form_fields.omit('screening_venue')
77        if not getattr(self.context, 'screening_date'):
78            form_fields = form_fields.omit('screening_date')
79        return form_fields
80
81class CustomPDFApplicationSlip(PDFApplicationSlip):
82
83    def _reduced_slip(self):
84        return getattr(self.context, 'result_uploaded', False)
85
86    @property
87    def form_fields(self):
88        form_fields = grok.AutoFields(ICustomUGApplicant)
89        if self.context.is_nd:
90            for field in ND_OMIT_PDF_FIELDS:
91                form_fields = form_fields.omit(field)
92        else:
93            form_fields = grok.AutoFields(ICustomUGApplicant)
94            for field in UG_OMIT_PDF_FIELDS:
95                form_fields = form_fields.omit(field)
96        if not getattr(self.context, 'student_id'):
97            form_fields = form_fields.omit('student_id')
98        if not getattr(self.context, 'screening_score'):
99            form_fields = form_fields.omit('screening_score')
100        if not getattr(self.context, 'screening_venue'):
101            form_fields = form_fields.omit('screening_venue')
102        if not getattr(self.context, 'screening_date'):
103            form_fields = form_fields.omit('screening_date')
104        return form_fields
105
106class CustomApplicantManageFormPage(ApplicantManageFormPage):
107    """A full edit view for applicant data.
108    """
109   
110    @property
111    def form_fields(self):
112        form_fields = grok.AutoFields(ICustomUGApplicant)
113        if self.context.is_nd:
114            for field in ND_OMIT_MANAGE_FIELDS:
115                form_fields = form_fields.omit(field)
116        else:
117            for field in UG_OMIT_MANAGE_FIELDS:
118                form_fields = form_fields.omit(field)
119        form_fields['student_id'].for_display = True
120        form_fields['applicant_id'].for_display = True
121        return form_fields
122
123class CustomApplicantEditFormPage(ApplicantEditFormPage):
124    """An applicant-centered edit view for applicant data.
125    """
126
127    @property
128    def form_fields(self):
129        form_fields = grok.AutoFields(ICustomUGApplicantEdit)
130        if self.context.is_nd:
131            for field in ND_OMIT_EDIT_FIELDS:
132                form_fields = form_fields.omit(field)
133        else:
134            for field in UG_OMIT_EDIT_FIELDS:
135                form_fields = form_fields.omit(field)
136        form_fields['applicant_id'].for_display = True
137        form_fields['reg_number'].for_display = True
138        return form_fields
Note: See TracBrowser for help on using the repository browser.