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

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

Catch traceback. Tests are missing!

  • Property svn:keywords set to Id
File size: 5.3 KB
Line 
1## $Id: browser.py 9481 2012-10-31 08:11: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,
26    ApplicantManageFormPage, ApplicantEditFormPage)
27from waeup.kofa.applicants.viewlets import (
28    PaymentReceiptActionButton, PDFActionButton)
29from waeup.kofa.applicants.pdf import PDFApplicationSlip
30from kofacustom.nigeria.applicants.interfaces import (
31    UG_OMIT_DISPLAY_FIELDS,
32    UG_OMIT_PDF_FIELDS,
33    UG_OMIT_MANAGE_FIELDS,
34    UG_OMIT_EDIT_FIELDS
35    )
36from waeup.fceokene.applicants.interfaces import (
37    ICustomUGApplicant, ICustomUGApplicantEdit,
38    BEC_OMIT_DISPLAY_FIELDS,
39    BEC_OMIT_PDF_FIELDS,
40    BEC_OMIT_MANAGE_FIELDS,
41    BEC_OMIT_EDIT_FIELDS
42    )
43
44class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage):
45    """A display view for applicant data.
46    """
47
48    @property
49    def form_fields(self):
50        target = getattr(self.context.__parent__, 'prefix', None)
51        form_fields = grok.AutoFields(ICustomUGApplicant)
52        if target is not None and target.startswith('bec'):
53            for field in BEC_OMIT_DISPLAY_FIELDS:
54                form_fields = form_fields.omit(field)
55        else:
56            form_fields = grok.AutoFields(ICustomUGApplicant)
57            for field in UG_OMIT_DISPLAY_FIELDS:
58                form_fields = form_fields.omit(field)
59        form_fields['notice'].custom_widget = BytesDisplayWidget
60        if not getattr(self.context, 'student_id'):
61            form_fields = form_fields.omit('student_id')
62        if not getattr(self.context, 'screening_score'):
63            form_fields = form_fields.omit('screening_score')
64        if not getattr(self.context, 'screening_venue'):
65            form_fields = form_fields.omit('screening_venue')
66        if not getattr(self.context, 'screening_date'):
67            form_fields = form_fields.omit('screening_date')
68        return form_fields
69
70class CustomPDFApplicationSlip(PDFApplicationSlip):
71
72    def _reduced_slip(self):
73        return getattr(self.context, 'result_uploaded', False)
74
75    @property
76    def form_fields(self):
77        target = getattr(self.context.__parent__, 'prefix', None)
78        form_fields = grok.AutoFields(ICustomUGApplicant)
79        if target is not None and target.startswith('bec'):
80            for field in BEC_OMIT_PDF_FIELDS:
81                form_fields = form_fields.omit(field)
82        else:
83            form_fields = grok.AutoFields(ICustomUGApplicant)
84            for field in UG_OMIT_PDF_FIELDS:
85                form_fields = form_fields.omit(field)
86        if not getattr(self.context, 'student_id'):
87            form_fields = form_fields.omit('student_id')
88        if not getattr(self.context, 'screening_score'):
89            form_fields = form_fields.omit('screening_score')
90        if not getattr(self.context, 'screening_venue'):
91            form_fields = form_fields.omit('screening_venue')
92        if not getattr(self.context, 'screening_date'):
93            form_fields = form_fields.omit('screening_date')
94        return form_fields
95
96class CustomApplicantManageFormPage(ApplicantManageFormPage):
97    """A full edit view for applicant data.
98    """
99   
100    @property
101    def form_fields(self):
102        target = getattr(self.context.__parent__, 'prefix', None)
103        form_fields = grok.AutoFields(ICustomUGApplicant)
104        if target is not None and target.startswith('bec'):
105            for field in BEC_OMIT_MANAGE_FIELDS:
106                form_fields = form_fields.omit(field)
107        else:
108            for field in UG_OMIT_MANAGE_FIELDS:
109                form_fields = form_fields.omit(field)
110        form_fields['student_id'].for_display = True
111        form_fields['applicant_id'].for_display = True
112        return form_fields
113
114class CustomApplicantEditFormPage(ApplicantEditFormPage):
115    """An applicant-centered 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(ICustomUGApplicantEdit)
122        if target is not None and target.startswith('bec'):
123            for field in BEC_OMIT_EDIT_FIELDS:
124                form_fields = form_fields.omit(field)
125        else:
126            for field in UG_OMIT_EDIT_FIELDS:
127                form_fields = form_fields.omit(field)
128        form_fields['applicant_id'].for_display = True
129        form_fields['reg_number'].for_display = True
130        return form_fields
Note: See TracBrowser for help on using the repository browser.