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

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

Do not show email address on slips. Issoufou wrote:

On all pdf slips is to avoid garbing the email address by cafe and send funny mails to students to extort money.
Applicable to all Nigerian institutions.

  • Property svn:keywords set to Id
File size: 8.9 KB
Line 
1## $Id: browser.py 9376 2012-10-21 21:04:58Z 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.viewlets import (
38    PaymentReceiptActionButton, StudentPassportActionButton)
39from kofacustom.nigeria.students.interfaces import (
40    INigeriaStudentBase, INigeriaStudent, INigeriaStudentPersonal,
41    INigeriaUGStudentClearance,INigeriaPGStudentClearance,
42    INigeriaStudentOnlinePayment
43    )
44from waeup.kofa.students.workflow import ADMITTED
45from kofacustom.nigeria.interfaces import MessageFactory as _
46
47class NigeriaOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb):
48    """A breadcrumb for payments.
49    """
50    grok.context(INigeriaStudentOnlinePayment)
51
52class PaymentReceiptActionButton(PaymentReceiptActionButton):
53    grok.order(4)
54    grok.context(INigeriaStudentOnlinePayment)
55
56class NigeriaStudentBaseDisplayFormPage(StudentBaseDisplayFormPage):
57    """ Page to display student base data
58    """
59    form_fields = grok.AutoFields(INigeriaStudentBase).omit('password', 'suspended')
60
61class NigeriaStudentBaseManageFormPage(StudentBaseManageFormPage):
62    """ View to manage student base data
63    """
64    form_fields = grok.AutoFields(INigeriaStudentBase).omit(
65        'student_id', 'adm_code', 'suspended')
66
67class NigeriaStudentBaseEditFormPage(StudentBaseEditFormPage):
68    """ View to edit student base data
69    """
70    form_fields = grok.AutoFields(INigeriaStudentBase).select(
71        'email', 'phone')
72
73class NigeriaStudentPersonalDisplayFormPage(StudentPersonalDisplayFormPage):
74    """ Page to display student personal data
75    """
76    form_fields = grok.AutoFields(INigeriaStudentPersonal)
77    form_fields['perm_address'].custom_widget = BytesDisplayWidget
78    form_fields['next_kin_address'].custom_widget = BytesDisplayWidget
79
80class NigeriaStudentPersonalEditFormPage(StudentPersonalEditFormPage):
81    """ Page to edit personal data
82    """
83    form_fields = grok.AutoFields(INigeriaStudentPersonal)
84
85class NigeriaStudentPersonalManageFormPage(StudentPersonalManageFormPage):
86    """ Page to edit personal data
87    """
88    form_fields = grok.AutoFields(INigeriaStudentPersonal)
89
90class NigeriaStudentClearanceDisplayFormPage(StudentClearanceDisplayFormPage):
91    """ Page to display student clearance data
92    """
93
94    @property
95    def form_fields(self):
96        if self.context.is_postgrad:
97            form_fields = grok.AutoFields(
98                INigeriaPGStudentClearance).omit('clearance_locked')
99        else:
100            form_fields = grok.AutoFields(
101                INigeriaUGStudentClearance).omit('clearance_locked')
102        return form_fields
103
104class NigeriaExportPDFClearanceSlipPage(ExportPDFClearanceSlipPage):
105    """Deliver a PDF slip of the context.
106    """
107    omit_fields = ('password', 'suspended', 'phone', 'adm_code', 'sex', 'email')
108
109    @property
110    def form_fields(self):
111        if self.context.is_postgrad:
112            form_fields = grok.AutoFields(
113                INigeriaPGStudentClearance).omit('clearance_locked')
114        else:
115            form_fields = grok.AutoFields(
116                INigeriaUGStudentClearance).omit('clearance_locked')
117        return form_fields
118
119class NigeriaStudentClearanceManageFormPage(StudentClearanceManageFormPage):
120    """ Page to edit student clearance data
121    """
122
123    @property
124    def form_fields(self):
125        if self.context.is_postgrad:
126            form_fields = grok.AutoFields(
127                INigeriaPGStudentClearance).omit('clr_code')
128        else:
129            form_fields = grok.AutoFields(
130                INigeriaUGStudentClearance).omit('clr_code')
131        return form_fields
132
133class NigeriaStudentClearanceEditFormPage(StudentClearanceEditFormPage):
134    """ View to edit student clearance data by student
135    """
136
137    @property
138    def form_fields(self):
139        if self.context.is_postgrad:
140            form_fields = grok.AutoFields(INigeriaPGStudentClearance).omit(
141            'clearance_locked', 'nysc_location', 'clr_code')
142        else:
143            form_fields = grok.AutoFields(INigeriaUGStudentClearance).omit(
144            'clearance_locked', 'clr_code')
145        return form_fields
146
147    def dataNotComplete(self):
148        store = getUtility(IExtFileStore)
149        if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'):
150            return _('No birth certificate uploaded.')
151        if not store.getFileByContext(self.context, attr=u'ref_let.jpg'):
152            return _('No referee letter uploaded.')
153        if not store.getFileByContext(self.context, attr=u'acc_let.jpg'):
154            return _('No acceptance letter uploaded.')
155        if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'):
156            return _('No first sitting result uploaded.')
157        return False
158
159class NigeriaExportPDFCourseRegistrationSlipPage(ExportPDFCourseRegistrationSlipPage):
160    """Deliver a PDF slip of the context.
161    """
162    omit_fields = ('password', 'suspended', 'phone', 'adm_code', 'sex', 'email')
163
164class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
165    """ Page to view an online payment ticket
166    """
167    grok.context(INigeriaStudentOnlinePayment)
168    form_fields = grok.AutoFields(INigeriaStudentOnlinePayment)
169    form_fields[
170        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
171    form_fields[
172        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
173
174class NigeriaOnlinePaymentAddFormPage(OnlinePaymentAddFormPage):
175    """ Page to add an online payment ticket
176    """
177    form_fields = grok.AutoFields(INigeriaStudentOnlinePayment).select(
178        'p_category')
179
180class NigeriaOnlinePaymentFakeApprovePage(OnlinePaymentFakeApprovePage):
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
192class NigeriaExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage):
193    """Deliver a PDF slip of the context.
194    """
195    grok.context(INigeriaStudentOnlinePayment)
196    form_fields = grok.AutoFields(INigeriaStudentOnlinePayment)
197    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
198    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
199    omit_fields = ('password', 'suspended', 'phone', 'adm_code', 'sex', 'email')
200
201class NigeriaExportPDFBedTicketSlipPage(ExportPDFBedTicketSlipPage):
202    """Deliver a PDF slip of the context.
203    """
204    omit_fields = ('password', 'suspended', 'phone', 'adm_code', 'sex', 'email')
205
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
216class NigeriaStudentFilesUploadPage(StudentFilesUploadPage):
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.