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

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

Fix exporter test.

Show personal_updated on NigeriaStudentPersonalDisplayFormPage? like in base package.

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