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

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

Also next_kin_address is a text field with newlines.

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