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

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

Use is_postgrad property.

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