source: main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students/browser.py @ 9704

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

Adjust browser module to changes in base package.

  • Property svn:keywords set to Id
File size: 9.1 KB
Line 
1## $Id: browser.py 9704 2012-11-21 15:36:28Z henrik $
2##
3## Copyright (C) 2012 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##
18import grok
19from zope.formlib.textwidgets import BytesDisplayWidget
20from zope.component import getUtility
21from zope.i18n import translate
22from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
23from waeup.kofa.interfaces import IExtFileStore
24from waeup.kofa.browser.layout import action
25from waeup.kofa.students.browser import (
26    StudentPersonalDisplayFormPage, StudentPersonalManageFormPage,
27    StudentClearanceManageFormPage, StudentClearanceEditFormPage,
28    StudentClearanceDisplayFormPage, OnlinePaymentFakeApprovePage,
29    ExportPDFClearanceSlipPage, StudentBaseManageFormPage,
30    StudentBaseDisplayFormPage,
31    StudentBaseEditFormPage, StudentPersonalEditFormPage,
32    OnlinePaymentDisplayFormPage, OnlinePaymentAddFormPage,
33    OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage,
34    ExportPDFCourseRegistrationSlipPage,
35    ExportPDFBedTicketSlipPage,
36    StudentFilesUploadPage, emit_lock_message)
37from waeup.kofa.students.viewlets import (
38    PaymentReceiptActionButton, StudentPassportActionButton)
39from kofacustom.nigeria.students.interfaces import (
40    INigeriaStudentBase, INigeriaStudent, INigeriaStudentPersonal,
41    INigeriaStudentPersonalEdit,
42    INigeriaUGStudentClearance,INigeriaPGStudentClearance,
43    INigeriaStudentOnlinePayment
44    )
45from waeup.kofa.students.workflow import ADMITTED
46from kofacustom.nigeria.interfaces import MessageFactory as _
47
48class NigeriaOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb):
49    """A breadcrumb for payments.
50    """
51    grok.context(INigeriaStudentOnlinePayment)
52
53class PaymentReceiptActionButton(PaymentReceiptActionButton):
54    grok.order(4)
55    grok.context(INigeriaStudentOnlinePayment)
56
57class NigeriaStudentBaseDisplayFormPage(StudentBaseDisplayFormPage):
58    """ Page to display student base data
59    """
60    form_fields = grok.AutoFields(INigeriaStudentBase).omit(
61        'password', 'suspended', 'suspended_comment')
62
63class NigeriaStudentBaseManageFormPage(StudentBaseManageFormPage):
64    """ View to manage student base data
65    """
66    form_fields = grok.AutoFields(INigeriaStudentBase).omit(
67        'student_id', 'adm_code', 'suspended')
68
69class NigeriaStudentBaseEditFormPage(StudentBaseEditFormPage):
70    """ View to edit student base data
71    """
72    form_fields = grok.AutoFields(INigeriaStudentBase).select(
73        'email', 'phone')
74
75class NigeriaStudentPersonalDisplayFormPage(StudentPersonalDisplayFormPage):
76    """ Page to display student personal data
77    """
78    form_fields = grok.AutoFields(INigeriaStudentPersonal)
79    form_fields['perm_address'].custom_widget = BytesDisplayWidget
80    form_fields['next_kin_address'].custom_widget = BytesDisplayWidget
81    form_fields[
82        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
83
84class NigeriaStudentPersonalEditFormPage(StudentPersonalEditFormPage):
85    """ Page to edit personal data
86    """
87    form_fields = grok.AutoFields(INigeriaStudentPersonalEdit).omit('personal_updated')
88
89class NigeriaStudentPersonalManageFormPage(StudentPersonalManageFormPage):
90    """ Page to edit personal data
91    """
92    form_fields = grok.AutoFields(INigeriaStudentPersonal)
93    form_fields['personal_updated'].for_display = True
94    form_fields[
95        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
96
97class NigeriaStudentClearanceDisplayFormPage(StudentClearanceDisplayFormPage):
98    """ Page to display student clearance data
99    """
100
101    @property
102    def form_fields(self):
103        if self.context.is_postgrad:
104            form_fields = grok.AutoFields(
105                INigeriaPGStudentClearance).omit('clearance_locked')
106        else:
107            form_fields = grok.AutoFields(
108                INigeriaUGStudentClearance).omit('clearance_locked')
109        if not getattr(self.context, 'officer_comment'):
110            form_fields = form_fields.omit('officer_comment')
111        else:
112            form_fields['officer_comment'].custom_widget = BytesDisplayWidget
113        return form_fields
114
115class NigeriaExportPDFClearanceSlipPage(ExportPDFClearanceSlipPage):
116    """Deliver a PDF slip of the context.
117    """
118    omit_fields = ('password', 'suspended', 'suspended_comment',
119        'phone', 'adm_code', 'email')
120
121    @property
122    def form_fields(self):
123        if self.context.is_postgrad:
124            form_fields = grok.AutoFields(
125                INigeriaPGStudentClearance).omit('clearance_locked')
126        else:
127            form_fields = grok.AutoFields(
128                INigeriaUGStudentClearance).omit('clearance_locked')
129        if not getattr(self.context, 'officer_comment'):
130            form_fields = form_fields.omit('officer_comment')
131        return form_fields
132
133class NigeriaStudentClearanceManageFormPage(StudentClearanceManageFormPage):
134    """ Page to edit student clearance data
135    """
136
137    @property
138    def form_fields(self):
139        if self.context.is_postgrad:
140            form_fields = grok.AutoFields(
141                INigeriaPGStudentClearance).omit('clr_code')
142        else:
143            form_fields = grok.AutoFields(
144                INigeriaUGStudentClearance).omit('clr_code')
145        return form_fields
146
147class NigeriaStudentClearanceEditFormPage(StudentClearanceEditFormPage):
148    """ View to edit student clearance data by student
149    """
150
151    @property
152    def form_fields(self):
153        if self.context.is_postgrad:
154            form_fields = grok.AutoFields(INigeriaPGStudentClearance).omit(
155            'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment')
156        else:
157            form_fields = grok.AutoFields(INigeriaUGStudentClearance).omit(
158            'clearance_locked', 'clr_code', 'officer_comment')
159        return form_fields
160
161class NigeriaExportPDFCourseRegistrationSlipPage(ExportPDFCourseRegistrationSlipPage):
162    """Deliver a PDF slip of the context.
163    """
164    omit_fields = ('password', 'suspended', 'suspended_comment',
165        'phone', 'adm_code', 'sex', 'email')
166
167class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
168    """ Page to view an online payment ticket
169    """
170    grok.context(INigeriaStudentOnlinePayment)
171    form_fields = grok.AutoFields(INigeriaStudentOnlinePayment)
172    form_fields[
173        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
174    form_fields[
175        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
176
177class NigeriaOnlinePaymentAddFormPage(OnlinePaymentAddFormPage):
178    """ Page to add an online payment ticket
179    """
180    form_fields = grok.AutoFields(INigeriaStudentOnlinePayment).select(
181        'p_category')
182
183class NigeriaOnlinePaymentFakeApprovePage(OnlinePaymentFakeApprovePage):
184    """ Disable payment approval view for students.
185
186    This view is used for browser tests only and
187    has to be neutralized here!
188    """
189    grok.name('fake_approve')
190    grok.require('waeup.managePortal')
191
192    def update(self):
193        return
194
195class NigeriaExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage):
196    """Deliver a PDF slip of the context.
197    """
198    grok.context(INigeriaStudentOnlinePayment)
199    form_fields = grok.AutoFields(INigeriaStudentOnlinePayment)
200    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
201    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
202    omit_fields = ('password', 'suspended', 'suspended_comment', 'phone',
203        'adm_code', 'sex', 'email')
204
205class NigeriaExportPDFBedTicketSlipPage(ExportPDFBedTicketSlipPage):
206    """Deliver a PDF slip of the context.
207    """
208    omit_fields = ('password', 'suspended', 'suspended_comment',
209        'phone', 'adm_code', 'email')
210
211class StudentPassportActionButton(StudentPassportActionButton):
212
213    @property
214    def target_url(self):
215        slip = getUtility(IExtFileStore).getFileByContext(
216            self.context, 'application_slip')
217        if self.context.state != ADMITTED or slip is not None:
218            return ''
219        return self.view.url(self.view.context, self.target)
220
221class NigeriaStudentFilesUploadPage(StudentFilesUploadPage):
222    """ View to upload passport picture.
223
224    Students are not allowed to change the picture if they
225    passed the regular Kofa application.
226    """
227
228    def update(self):
229        slip = getUtility(IExtFileStore).getFileByContext(
230            self.context, 'application_slip')
231        if self.context.state != ADMITTED or slip is not None:
232            emit_lock_message(self)
233            return
234        super(StudentFilesUploadPage, self).update()
235        return
Note: See TracBrowser for help on using the repository browser.