source: main/waeup.aaue/trunk/src/waeup/aaue/students/browser.py @ 8775

Last change on this file since 8775 was 8723, checked in by Henrik Bettermann, 13 years ago

Merged with r8720.

  • Property svn:keywords set to Id
File size: 8.8 KB
Line 
1## $Id: browser.py 8723 2012-06-14 08:08:27Z 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,
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 waeup.aaue.students.interfaces import (
37    ICustomStudentBase, ICustomStudent, ICustomStudentPersonal,
38    ICustomUGStudentClearance,ICustomPGStudentClearance,
39    ICustomStudentOnlinePayment,
40    )
41from waeup.kofa.students.workflow import ADMITTED
42from waeup.aaue.interfaces import MessageFactory as _
43
44#class RequestCallbackActionButton(RequestCallbackActionButton):
45#    """ Display the base package callback button in custom pages.
46#    """
47#    grok.context(ICustomStudentOnlinePayment)
48
49#class CustomOnlinePaymentCallbackPage(OnlinePaymentCallbackPage):
50#    """ Activate callback simulation view
51#    """
52#    grok.context(ICustomStudentOnlinePayment)
53
54class CustomOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb):
55    """A breadcrumb for payments.
56    """
57    grok.context(ICustomStudentOnlinePayment)
58
59class PaymentReceiptActionButton(PaymentReceiptActionButton):
60    grok.order(4)
61    grok.context(ICustomStudentOnlinePayment)
62
63class CustomStudentBaseManageFormPage(StudentBaseManageFormPage):
64    """ View to manage student base data
65    """
66    form_fields = grok.AutoFields(ICustomStudentBase).omit('student_id')
67
68class CustomStudentBaseEditFormPage(StudentBaseEditFormPage):
69    """ View to edit student base data
70    """
71    form_fields = grok.AutoFields(ICustomStudentBase).select(
72        'email', 'phone')
73
74
75class CustomStudentPersonalDisplayFormPage(StudentPersonalDisplayFormPage):
76    """ Page to display student personal data
77    """
78    grok.context(ICustomStudent)
79    form_fields = grok.AutoFields(ICustomStudentPersonal)
80    form_fields['perm_address'].custom_widget = BytesDisplayWidget
81
82
83class CustomStudentPersonalEditFormPage(StudentPersonalEditFormPage):
84    """ Page to edit personal data
85    """
86    form_fields = grok.AutoFields(ICustomStudentPersonal)
87
88
89class CustomStudentClearanceDisplayFormPage(StudentClearanceDisplayFormPage):
90    """ Page to display student clearance data
91    """
92    grok.context(ICustomStudent)
93
94    @property
95    def form_fields(self):
96        cm = getattr(self.context,'current_mode', None)
97        if cm is not None and cm.startswith('pg'):
98            form_fields = grok.AutoFields(
99                ICustomPGStudentClearance).omit('clearance_locked')
100        else:
101            form_fields = grok.AutoFields(
102                ICustomUGStudentClearance).omit('clearance_locked')
103        return form_fields
104
105class CustomExportPDFClearanceSlipPage(ExportPDFClearanceSlipPage):
106    """Deliver a PDF slip of the context.
107    """
108    grok.context(ICustomStudent)
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                ICustomPGStudentClearance).omit('clearance_locked')
116        else:
117            form_fields = grok.AutoFields(
118                ICustomUGStudentClearance).omit('clearance_locked')
119        return form_fields
120
121class CustomStudentClearanceManageFormPage(StudentClearanceManageFormPage):
122    """ Page to edit student clearance data
123    """
124    grok.context(ICustomStudent)
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'):
130            form_fields = grok.AutoFields(ICustomPGStudentClearance)
131        else:
132            form_fields = grok.AutoFields(ICustomUGStudentClearance)
133        return form_fields
134
135class CustomStudentClearanceEditFormPage(StudentClearanceEditFormPage):
136    """ View to edit student clearance data by student
137    """
138    grok.context(ICustomStudent)
139
140    @property
141    def form_fields(self):
142        cm = getattr(self.context,'current_mode', None)
143        if cm is not None and cm.startswith('pg'):
144            form_fields = grok.AutoFields(ICustomPGStudentClearance).omit('clearance_locked')
145        else:
146            form_fields = grok.AutoFields(ICustomUGStudentClearance).omit('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_certicicate.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 CustomOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
162    """ Page to view an online payment ticket
163    """
164    grok.context(ICustomStudentOnlinePayment)
165    form_fields = grok.AutoFields(ICustomStudentOnlinePayment)
166    form_fields[
167        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
168    form_fields[
169        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
170    #grok.template('payment_view')
171
172    #@property
173    #def transaction_code(self):
174    #    tcode = self.context.p_id
175    #    return tcode[len(tcode)-8:len(tcode)]
176
177class CustomOnlinePaymentAddFormPage(OnlinePaymentAddFormPage):
178    """ Page to add an online payment ticket
179    """
180    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
181        'p_category')
182
183class CustomOnlinePaymentFakeApprovePage(OnlinePaymentFakeApprovePage):
184    """ Disable payment approval view for students.
185
186    This view is used for browser tests only and
187    has to be neutralized here!
188    """
189
190    grok.name('fake_approve')
191    grok.require('waeup.managePortal')
192
193    def update(self):
194        return
195
196class CustomExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage):
197    """Deliver a PDF slip of the context.
198    """
199    grok.context(ICustomStudentOnlinePayment)
200    form_fields = grok.AutoFields(ICustomStudentOnlinePayment)
201    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
202    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
203
204#    @property
205#    def note(self):
206#        tcode = self.context.p_id
207#        tcode = tcode[len(tcode)-8:len(tcode)]
208#        amount = self.context.amount_auth
209#        note = translate(_(
210#            u"""<br /><br /><br />
211#The tranzaction code is <strong>${a}</strong>.""",
212#            mapping = {'a':tcode}))
213#        return note
214
215class StudentPassportActionButton(StudentPassportActionButton):
216
217    @property
218    def target_url(self):
219        slip = getUtility(IExtFileStore).getFileByContext(
220            self.context, 'application_slip')
221        if self.context.state != ADMITTED or slip is not None:
222            return ''
223        return self.view.url(self.view.context, self.target)
224
225class CustomStudentFilesUploadPage(StudentFilesUploadPage):
226    """ View to upload passport picture.
227
228    Students are not allowed to change the picture if they
229    passed the regular Kofa application.
230    """
231
232    def update(self):
233        slip = getUtility(IExtFileStore).getFileByContext(
234            self.context, 'application_slip')
235        if self.context.state != ADMITTED or slip is not None:
236            emit_lock_message(self)
237            return
238        super(StudentFilesUploadPage, self).update()
239        return
Note: See TracBrowser for help on using the repository browser.