source: main/kofacustom.edocons/trunk/src/kofacustom/edocons/applicants/browser.py @ 16638

Last change on this file since 16638 was 16618, checked in by Henrik Bettermann, 3 years ago

Start customization of application forms.

File size: 6.0 KB
Line 
1## $Id: browser.py 10765 2013-11-19 12:57:15Z 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.students.interfaces import IStudentsUtils
26from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage,
27    ApplicantManageFormPage, ApplicantEditFormPage,
28    ApplicantRegistrationPage,
29    OnlinePaymentDisplayFormPage,
30    OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage,
31    )
32from waeup.kofa.applicants.viewlets import (
33    PDFActionButton, PaymentReceiptActionButton)
34from waeup.kofa.applicants.pdf import PDFApplicationSlip
35from kofacustom.nigeria.applicants.browser import (
36    NigeriaApplicantDisplayFormPage,
37    NigeriaApplicantManageFormPage,
38    NigeriaApplicantEditFormPage,
39    NigeriaPDFApplicationSlip)
40from kofacustom.nigeria.applicants.interfaces import (
41    INigeriaPGApplicant, INigeriaUGApplicant,
42    INigeriaPGApplicantEdit, INigeriaUGApplicantEdit,
43    INigeriaApplicantOnlinePayment,
44    UG_OMIT_DISPLAY_FIELDS,
45    UG_OMIT_PDF_FIELDS,
46    UG_OMIT_MANAGE_FIELDS,
47    UG_OMIT_EDIT_FIELDS,
48    PG_OMIT_DISPLAY_FIELDS,
49    PG_OMIT_PDF_FIELDS,
50    PG_OMIT_MANAGE_FIELDS,
51    PG_OMIT_EDIT_FIELDS,
52    )
53from kofacustom.edocons.applicants.interfaces import (
54    ICustomPGApplicant, ICustomUGApplicant, ICustomApplicant,
55    ICustomPGApplicantEdit, ICustomUGApplicantEdit,
56    ICustomApplicantOnlinePayment,
57    )
58from kofacustom.nigeria.interfaces import MessageFactory as _
59
60class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
61    """A display view for applicant data.
62    """
63
64    @property
65    def form_fields(self):
66        if self.target is not None and self.target.startswith('pg'):
67            form_fields = grok.AutoFields(ICustomPGApplicant)
68            for field in PG_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['perm_address'].custom_widget = BytesDisplayWidget
75        form_fields['notice'].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') or self._not_paid():
81            form_fields = form_fields.omit('screening_venue')
82        if not getattr(self.context, 'screening_date') or self._not_paid():
83            form_fields = form_fields.omit('screening_date')
84        return form_fields
85
86class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
87
88    @property
89    def form_fields(self):
90        if self.target is not None and self.target.startswith('pg'):
91            form_fields = grok.AutoFields(ICustomPGApplicant)
92            for field in PG_OMIT_PDF_FIELDS:
93                form_fields = form_fields.omit(field)
94        else:
95            form_fields = grok.AutoFields(ICustomUGApplicant)
96            for field in UG_OMIT_PDF_FIELDS:
97                form_fields = form_fields.omit(field)
98        if not getattr(self.context, 'student_id'):
99            form_fields = form_fields.omit('student_id')
100        if not getattr(self.context, 'screening_score'):
101            form_fields = form_fields.omit('screening_score')
102        if not getattr(self.context, 'screening_venue'):
103            form_fields = form_fields.omit('screening_venue')
104        if not getattr(self.context, 'screening_date'):
105            form_fields = form_fields.omit('screening_date')
106        return form_fields
107
108class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
109    """A full edit view for applicant data.
110    """
111
112    @property
113    def form_fields(self):
114        if self.target is not None and self.target.startswith('pg'):
115            form_fields = grok.AutoFields(ICustomPGApplicant)
116            for field in PG_OMIT_MANAGE_FIELDS:
117                form_fields = form_fields.omit(field)
118        else:
119            form_fields = grok.AutoFields(ICustomUGApplicant)
120            for field in UG_OMIT_MANAGE_FIELDS:
121                form_fields = form_fields.omit(field)
122        form_fields['student_id'].for_display = True
123        form_fields['applicant_id'].for_display = True
124        return form_fields
125
126class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
127    """An applicant-centered edit view for applicant data.
128    """
129
130    @property
131    def form_fields(self):
132        if self.target is not None and self.target.startswith('pg'):
133            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
134            for field in PG_OMIT_EDIT_FIELDS:
135                form_fields = form_fields.omit(field)
136        else:
137            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
138            for field in UG_OMIT_EDIT_FIELDS:
139                form_fields = form_fields.omit(field)
140        form_fields['applicant_id'].for_display = True
141        form_fields['reg_number'].for_display = True
142        return form_fields
Note: See TracBrowser for help on using the repository browser.