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

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

Add nysc_location. We need this field only for imported data from SRP. This field shouldn't be filled by students in Kofa.

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