source: main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants/browser.py @ 15830

Last change on this file since 15830 was 15809, checked in by Henrik Bettermann, 5 years ago

Add application category, hide application fee and show sponsor field.

  • Property svn:keywords set to Id
File size: 6.2 KB
Line 
1## $Id: browser.py 15809 2019-11-15 07:28:55Z 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.formlib.textwidgets import BytesDisplayWidget
22from waeup.kofa.applicants.browser import (
23    ApplicantRegistrationPage, ApplicantsContainerPage)
24from waeup.kofa.applicants.interfaces import (
25    ISpecialApplicant, IApplicantsContainer)
26from kofacustom.nigeria.applicants.browser import (
27    NigeriaApplicantDisplayFormPage,
28    NigeriaApplicantManageFormPage,
29    NigeriaApplicantEditFormPage,
30    NigeriaPDFApplicationSlip)
31from waeup.kofa.widgets.datewidget import (
32    FriendlyDateDisplayWidget,
33    FriendlyDatetimeDisplayWidget)
34from kofacustom.nigeria.applicants.interfaces import (
35    UG_OMIT_DISPLAY_FIELDS,
36    UG_OMIT_PDF_FIELDS,
37    UG_OMIT_MANAGE_FIELDS,
38    UG_OMIT_EDIT_FIELDS,
39    PG_OMIT_DISPLAY_FIELDS,
40    PG_OMIT_PDF_FIELDS,
41    PG_OMIT_MANAGE_FIELDS,
42    PG_OMIT_EDIT_FIELDS,
43    )
44from kofacustom.iuokada.applicants.interfaces import (
45    ICustomPGApplicant, ICustomUGApplicant,
46    ICustomPGApplicantEdit, ICustomUGApplicantEdit,
47    ICustomApplicantOnlinePayment
48    )
49from kofacustom.iuokada.interfaces import MessageFactory as _
50
51class CustomApplicantsContainerPage(ApplicantsContainerPage):
52    """The standard view for regular applicant containers.
53    """
54
55    @property
56    def form_fields(self):
57        form_fields = grok.AutoFields(IApplicantsContainer).omit(
58            'title', 'description')
59        form_fields[
60            'startdate'].custom_widget = FriendlyDatetimeDisplayWidget('le')
61        form_fields[
62            'enddate'].custom_widget = FriendlyDatetimeDisplayWidget('le')
63        if self.request.principal.id == 'zope.anybody':
64            form_fields = form_fields.omit(
65                'code', 'prefix', 'year', 'mode', 'hidden',
66                'strict_deadline', 'application_category',
67                'application_slip_notice', 'application_fee', 'with_picture')
68        return form_fields
69
70class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
71    """A display view for applicant data.
72    """
73
74    @property
75    def form_fields(self):
76        if self.target is not None and self.target.startswith('pg'):
77            form_fields = grok.AutoFields(ICustomPGApplicant)
78            for field in PG_OMIT_DISPLAY_FIELDS:
79                form_fields = form_fields.omit(field)
80        else:
81            form_fields = grok.AutoFields(ICustomUGApplicant)
82            for field in UG_OMIT_DISPLAY_FIELDS:
83                form_fields = form_fields.omit(field)
84        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
85        form_fields['notice'].custom_widget = BytesDisplayWidget
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') or self._not_paid():
91            form_fields = form_fields.omit('screening_venue')
92        if not getattr(self.context, 'screening_date') or self._not_paid():
93            form_fields = form_fields.omit('screening_date')
94        return form_fields
95
96class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
97    """A full edit view for applicant data.
98    """
99
100    @property
101    def form_fields(self):
102        if self.target is not None and self.target.startswith('pg'):
103            form_fields = grok.AutoFields(ICustomPGApplicant)
104            for field in PG_OMIT_MANAGE_FIELDS:
105                form_fields = form_fields.omit(field)
106        else:
107            form_fields = grok.AutoFields(ICustomUGApplicant)
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(NigeriaApplicantEditFormPage):
115    """An applicant-centered edit view for applicant data.
116    """
117
118    @property
119    def form_fields(self):
120        if self.target is not None and self.target.startswith('pg'):
121            form_fields = grok.AutoFields(ICustomPGApplicantEdit)
122            for field in PG_OMIT_EDIT_FIELDS:
123                form_fields = form_fields.omit(field)
124        else:
125            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
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
131
132class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
133
134    @property
135    def form_fields(self):
136        if self.target is not None and self.target.startswith('pg'):
137            form_fields = grok.AutoFields(ICustomPGApplicant)
138            for field in PG_OMIT_PDF_FIELDS:
139                form_fields = form_fields.omit(field)
140        else:
141            form_fields = grok.AutoFields(ICustomUGApplicant)
142            for field in UG_OMIT_PDF_FIELDS:
143                form_fields = form_fields.omit(field)
144        if not getattr(self.context, 'student_id'):
145            form_fields = form_fields.omit('student_id')
146        if not getattr(self.context, 'screening_score'):
147            form_fields = form_fields.omit('screening_score')
148        if not getattr(self.context, 'screening_venue'):
149            form_fields = form_fields.omit('screening_venue')
150        if not getattr(self.context, 'screening_date'):
151            form_fields = form_fields.omit('screening_date')
152        return form_fields
153
Note: See TracBrowser for help on using the repository browser.