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

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

Disable hostel selection.

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