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

Last change on this file since 13058 was 13058, checked in by Henrik Bettermann, 10 years ago

Rename views according to changes in base package.

  • Property svn:keywords set to Id
File size: 9.8 KB
Line 
1## $Id: browser.py 13058 2015-06-16 11:57:31Z 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, OnlinePaymentFakeApproveView,
29    ExportPDFClearanceSlip, StudentBaseManageFormPage,
30    StudentBaseDisplayFormPage,
31    StudentBaseEditFormPage, StudentPersonalEditFormPage,
32    OnlinePaymentDisplayFormPage, OnlinePaymentAddFormPage,
33    OnlinePaymentBreadcrumb, ExportPDFPaymentSlip,
34    ExportPDFCourseRegistrationSlip,
35    ExportPDFBedTicketSlip,
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 NigeriaExportPDFClearanceSlip(ExportPDFClearanceSlip):
117    """Deliver a PDF slip of the context.
118    """
119    omit_fields = ('password', 'suspended', 'suspended_comment',
120        'phone', 'adm_code', 'email', 'date_of_birth', 'current_level')
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            'physical_clearance_date')
158        else:
159            form_fields = grok.AutoFields(INigeriaUGStudentClearance).omit(
160            'clearance_locked', 'clr_code', 'officer_comment',
161            'physical_clearance_date')
162        return form_fields
163
164class NigeriaExportPDFCourseRegistrationSlip(ExportPDFCourseRegistrationSlip):
165    """Deliver a PDF slip of the context.
166    """
167    omit_fields = ('password', 'suspended', 'suspended_comment',
168        'phone', 'adm_code', 'sex', 'email', 'date_of_birth', 'current_level')
169
170class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
171    """ Page to view an online payment ticket
172    """
173    grok.context(INigeriaStudentOnlinePayment)
174    form_fields = grok.AutoFields(INigeriaStudentOnlinePayment).omit(
175        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
176    form_fields[
177        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
178    form_fields[
179        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
180
181class NigeriaOnlinePaymentAddFormPage(OnlinePaymentAddFormPage):
182    """ Page to add an online payment ticket
183    """
184    form_fields = grok.AutoFields(INigeriaStudentOnlinePayment).select(
185        'p_category')
186
187class NigeriaOnlinePaymentFakeApproveView(OnlinePaymentFakeApproveView):
188    """ Disable payment approval view for students.
189
190    This view is used for browser tests only and
191    has to be neutralized here!
192    """
193    grok.name('fake_approve')
194    grok.require('waeup.managePortal')
195
196    def update(self):
197        return
198
199class NigeriaExportPDFPaymentSlip(ExportPDFPaymentSlip):
200    """Deliver a PDF slip of the context.
201    """
202    grok.context(INigeriaStudentOnlinePayment)
203    form_fields = grok.AutoFields(INigeriaStudentOnlinePayment).omit(
204        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
205    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
206    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
207    omit_fields = ('password', 'suspended', 'suspended_comment', 'phone',
208        'adm_code', 'sex', 'email', 'date_of_birth', 'current_level')
209
210class NigeriaExportPDFBedTicketSlip(ExportPDFBedTicketSlip):
211    """Deliver a PDF slip of the context.
212    """
213    omit_fields = ('password', 'suspended', 'suspended_comment',
214        'phone', 'adm_code', 'email', 'date_of_birth', 'current_level')
215
216class StudentPassportActionButton(StudentPassportActionButton):
217
218    @property
219    def target_url(self):
220        # Passport pictures must not be editable if application slip
221        # exists.
222        slip = getUtility(IExtFileStore).getFileByContext(
223            self.context, 'application_slip')
224        PWCHANGE_STATES = getUtility(IStudentsUtils).PWCHANGE_STATES
225        if self.context.state not in PWCHANGE_STATES or slip is not None:
226            return ''
227        return self.view.url(self.view.context, self.target)
228
229class NigeriaStudentFilesUploadPage(StudentFilesUploadPage):
230    """ View to upload passport picture.
231
232    Students are not allowed to change the picture if they
233    passed the regular Kofa application.
234    """
235
236    def update(self):
237        # Passport pictures must not be editable if application slip
238        # exists.
239        slip = getUtility(IExtFileStore).getFileByContext(
240            self.context, 'application_slip')
241        PWCHANGE_STATES = getUtility(IStudentsUtils).PWCHANGE_STATES
242        if self.context.state not in PWCHANGE_STATES or slip is not None:
243            emit_lock_message(self)
244            return
245        super(StudentFilesUploadPage, self).update()
246        return
Note: See TracBrowser for help on using the repository browser.