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

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

Omit suspended and adm_code attributes.

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