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

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

Show officers's comment in the same way as shown in the base package.

  • Property svn:keywords set to Id
File size: 8.6 KB
Line 
1## $Id: browser.py 9535 2012-11-05 12:13:10Z 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        if not getattr(self.context, 'officer_comment'):
103            form_fields = form_fields.omit('officer_comment')
104        else:
105            form_fields['officer_comment'].custom_widget = BytesDisplayWidget
106        return form_fields
107
108class NigeriaExportPDFClearanceSlipPage(ExportPDFClearanceSlipPage):
109    """Deliver a PDF slip of the context.
110    """
111    omit_fields = ('password', 'suspended', 'phone', 'adm_code', 'email')
112
113    @property
114    def form_fields(self):
115        if self.context.is_postgrad:
116            form_fields = grok.AutoFields(
117                INigeriaPGStudentClearance).omit('clearance_locked')
118        else:
119            form_fields = grok.AutoFields(
120                INigeriaUGStudentClearance).omit('clearance_locked')
121        if not getattr(self.context, 'officer_comment'):
122            form_fields = form_fields.omit('officer_comment')
123        return form_fields
124
125class NigeriaStudentClearanceManageFormPage(StudentClearanceManageFormPage):
126    """ Page to edit student clearance data
127    """
128
129    @property
130    def form_fields(self):
131        if self.context.is_postgrad:
132            form_fields = grok.AutoFields(
133                INigeriaPGStudentClearance).omit('clr_code')
134        else:
135            form_fields = grok.AutoFields(
136                INigeriaUGStudentClearance).omit('clr_code')
137        return form_fields
138
139class NigeriaStudentClearanceEditFormPage(StudentClearanceEditFormPage):
140    """ View to edit student clearance data by student
141    """
142
143    @property
144    def form_fields(self):
145        if self.context.is_postgrad:
146            form_fields = grok.AutoFields(INigeriaPGStudentClearance).omit(
147            'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment')
148        else:
149            form_fields = grok.AutoFields(INigeriaUGStudentClearance).omit(
150            'clearance_locked', 'clr_code', 'officer_comment')
151        return form_fields
152
153class NigeriaExportPDFCourseRegistrationSlipPage(ExportPDFCourseRegistrationSlipPage):
154    """Deliver a PDF slip of the context.
155    """
156    omit_fields = ('password', 'suspended', 'phone', 'adm_code', 'sex', 'email')
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    grok.name('fake_approve')
181    grok.require('waeup.managePortal')
182
183    def update(self):
184        return
185
186class NigeriaExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage):
187    """Deliver a PDF slip of the context.
188    """
189    grok.context(INigeriaStudentOnlinePayment)
190    form_fields = grok.AutoFields(INigeriaStudentOnlinePayment)
191    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
192    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
193    omit_fields = ('password', 'suspended', 'phone', 'adm_code', 'sex', 'email')
194
195class NigeriaExportPDFBedTicketSlipPage(ExportPDFBedTicketSlipPage):
196    """Deliver a PDF slip of the context.
197    """
198    omit_fields = ('password', 'suspended', 'phone', 'adm_code', 'email')
199
200class StudentPassportActionButton(StudentPassportActionButton):
201
202    @property
203    def target_url(self):
204        slip = getUtility(IExtFileStore).getFileByContext(
205            self.context, 'application_slip')
206        if self.context.state != ADMITTED or slip is not None:
207            return ''
208        return self.view.url(self.view.context, self.target)
209
210class NigeriaStudentFilesUploadPage(StudentFilesUploadPage):
211    """ View to upload passport picture.
212
213    Students are not allowed to change the picture if they
214    passed the regular Kofa application.
215    """
216
217    def update(self):
218        slip = getUtility(IExtFileStore).getFileByContext(
219            self.context, 'application_slip')
220        if self.context.state != ADMITTED or slip is not None:
221            emit_lock_message(self)
222            return
223        super(StudentFilesUploadPage, self).update()
224        return
Note: See TracBrowser for help on using the repository browser.