source: main/kofacustom.wdu/trunk/src/kofacustom/wdu/applicants/browser.py @ 12885

Last change on this file since 12885 was 12885, checked in by Henrik Bettermann, 9 years ago

Initialize customization of forms.

  • Property svn:keywords set to Id
File size: 6.8 KB
Line 
1## $Id: browser.py 12885 2015-04-26 08:59:40Z 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 kofacustom.nigeria.applicants.browser import (
27    NigeriaApplicantDisplayFormPage,
28    NigeriaApplicantManageFormPage,
29    NigeriaApplicantEditFormPage,
30    NigeriaPDFApplicationSlip)
31
32from kofacustom.nigeria.applicants.interfaces import (
33    UG_OMIT_DISPLAY_FIELDS,
34    UG_OMIT_PDF_FIELDS,
35    UG_OMIT_MANAGE_FIELDS,
36    UG_OMIT_EDIT_FIELDS,
37    PUTME_OMIT_DISPLAY_FIELDS,
38    PUTME_OMIT_PDF_FIELDS,
39    PUTME_OMIT_MANAGE_FIELDS,
40    PUTME_OMIT_EDIT_FIELDS,
41    PUTME_OMIT_RESULT_SLIP_FIELDS,
42    PUDE_OMIT_DISPLAY_FIELDS,
43    PUDE_OMIT_PDF_FIELDS,
44    PUDE_OMIT_MANAGE_FIELDS,
45    PUDE_OMIT_EDIT_FIELDS,
46    PUDE_OMIT_RESULT_SLIP_FIELDS,
47    )
48
49from kofacustom.wdu.applicants.interfaces import (
50    ICustomUGApplicant,
51    ICustomUGApplicantEdit,
52    ICustomPUTMEApplicantEdit,
53    )
54
55from kofacustom.wdu.interfaces import MessageFactory as _
56
57
58class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage):
59    """A display view for applicant data.
60    """
61
62    @property
63    def form_fields(self):
64        if self.target is not None and self.target.startswith('putme'):
65            form_fields = grok.AutoFields(ICustomUGApplicant)
66            for field in PUTME_OMIT_DISPLAY_FIELDS:
67                form_fields = form_fields.omit(field)
68        elif self.target is not None and self.target.startswith('pude'):
69            form_fields = grok.AutoFields(ICustomUGApplicant)
70            for field in PUDE_OMIT_DISPLAY_FIELDS:
71                form_fields = form_fields.omit(field)
72        else:
73            form_fields = grok.AutoFields(ICustomUGApplicant)
74            for field in UG_OMIT_DISPLAY_FIELDS:
75                form_fields = form_fields.omit(field)
76        #form_fields['perm_address'].custom_widget = BytesDisplayWidget
77        form_fields['notice'].custom_widget = BytesDisplayWidget
78        if not getattr(self.context, 'student_id'):
79            form_fields = form_fields.omit('student_id')
80        if not getattr(self.context, 'screening_score'):
81            form_fields = form_fields.omit('screening_score')
82        if not getattr(self.context, 'screening_venue') or self._not_paid():
83            form_fields = form_fields.omit('screening_venue')
84        if not getattr(self.context, 'screening_date') or self._not_paid():
85            form_fields = form_fields.omit('screening_date')
86        return form_fields
87
88class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip):
89
90    @property
91    def form_fields(self):
92        if self.target is not None and self.target.startswith('putme'):
93            form_fields = grok.AutoFields(ICustomUGApplicant)
94            if self._reduced_slip():
95                for field in PUTME_OMIT_RESULT_SLIP_FIELDS:
96                    form_fields = form_fields.omit(field)
97            else:
98                for field in PUTME_OMIT_PDF_FIELDS:
99                    form_fields = form_fields.omit(field)
100        elif self.target is not None and self.target.startswith('pude'):
101            form_fields = grok.AutoFields(ICustomUGApplicant)
102            if self._reduced_slip():
103                for field in PUDE_OMIT_RESULT_SLIP_FIELDS:
104                    form_fields = form_fields.omit(field)
105            else:
106                for field in PUDE_OMIT_PDF_FIELDS:
107                    form_fields = form_fields.omit(field)
108        else:
109            form_fields = grok.AutoFields(ICustomUGApplicant)
110            for field in UG_OMIT_PDF_FIELDS:
111                form_fields = form_fields.omit(field)
112        if not getattr(self.context, 'student_id'):
113            form_fields = form_fields.omit('student_id')
114        if not getattr(self.context, 'screening_score'):
115            form_fields = form_fields.omit('screening_score')
116        if not getattr(self.context, 'screening_venue'):
117            form_fields = form_fields.omit('screening_venue')
118        if not getattr(self.context, 'screening_date'):
119            form_fields = form_fields.omit('screening_date')
120        return form_fields
121
122class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage):
123    """A full edit view for applicant data.
124    """
125
126    @property
127    def form_fields(self):
128        if self.target is not None and self.target.startswith('putme'):
129            form_fields = grok.AutoFields(ICustomUGApplicant)
130            for field in PUTME_OMIT_MANAGE_FIELDS:
131                form_fields = form_fields.omit(field)
132        elif self.target is not None and self.target.startswith('pude'):
133            form_fields = grok.AutoFields(ICustomUGApplicant)
134            for field in PUDE_OMIT_MANAGE_FIELDS:
135                form_fields = form_fields.omit(field)
136        else:
137            form_fields = grok.AutoFields(ICustomUGApplicant)
138            for field in UG_OMIT_MANAGE_FIELDS:
139                form_fields = form_fields.omit(field)
140        form_fields['student_id'].for_display = True
141        form_fields['applicant_id'].for_display = True
142        return form_fields
143
144class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage):
145    """An applicant-centered edit view for applicant data.
146    """
147
148    @property
149    def form_fields(self):
150        if self.target is not None and self.target.startswith('putme'):
151            form_fields = grok.AutoFields(ICustomPUTMEApplicantEdit)
152            for field in PUTME_OMIT_EDIT_FIELDS:
153                form_fields = form_fields.omit(field)
154        elif self.target is not None and self.target.startswith('pude'):
155            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
156            for field in PUDE_OMIT_EDIT_FIELDS:
157                form_fields = form_fields.omit(field)
158        else:
159            form_fields = grok.AutoFields(ICustomUGApplicantEdit)
160            for field in UG_OMIT_EDIT_FIELDS:
161                form_fields = form_fields.omit(field)
162        form_fields['applicant_id'].for_display = True
163        form_fields['reg_number'].for_display = True
164        return form_fields
Note: See TracBrowser for help on using the repository browser.