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

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

Show correct datetime format on manage page.

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