source: main/kofacustom.nigeria/branches/0.1/src/kofacustom/nigeria/students/browser.py @ 17364

Last change on this file since 17364 was 10707, checked in by Henrik Bettermann, 11 years ago

See r10706.

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