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

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

Rename field.

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