source: main/waeup.uniben/trunk/src/waeup/uniben/students/browser.py @ 8247

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

Reorganize payment customizatiom. Tests will follow.

Let also applicants pay via eTranzact. Show transaction code on display view (slip view will follow).

  • Property svn:keywords set to Id
File size: 6.9 KB
Line 
1## $Id: browser.py 8247 2012-04-22 12:56:07Z 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 waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
22from waeup.kofa.interfaces import IExtFileStore
23from waeup.kofa.browser.layout import action
24from waeup.kofa.students.browser import (
25    StudentPersonalDisplayFormPage,
26    StudentClearanceManageFormPage, StudentClearanceEditFormPage,
27    StudentClearanceDisplayFormPage, OnlinePaymentCallbackPage,
28    ExportPDFClearanceSlipPage, StudentBaseManageFormPage,
29    StudentBaseEditFormPage, StudentPersonalEditFormPage,
30    OnlinePaymentDisplayFormPage, OnlinePaymentAddFormPage,
31    OnlinePaymentBreadcrumb)
32from waeup.kofa.students.viewlets import RequestCallbackActionButton
33from waeup.uniben.students.interfaces import (
34    ICustomStudentBase, ICustomStudent, ICustomStudentPersonal,
35    ICustomUGStudentClearance,ICustomPGStudentClearance,
36    ICustomStudentOnlinePayment,
37    )
38from waeup.uniben.interfaces import MessageFactory as _
39
40class CustomOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb):
41    """A breadcrumb for payments.
42    """
43    grok.context(ICustomStudentOnlinePayment)
44
45class RequestCallbackActionButton(RequestCallbackActionButton):
46    """ Do not display the base package callback button in custom pages.
47    """
48    @property
49    def target_url(self):
50        return ''
51
52class CustomOnlinePaymentCallbackPage(OnlinePaymentCallbackPage):
53    """ Neutralize callback simulation view
54    """
55    def update(self):
56        return
57
58class CustomStudentBaseManageFormPage(StudentBaseManageFormPage):
59    """ View to manage student base data
60    """
61    form_fields = grok.AutoFields(ICustomStudentBase).omit('student_id')
62
63class CustomStudentBaseEditFormPage(StudentBaseEditFormPage):
64    """ View to edit student base data
65    """
66    form_fields = grok.AutoFields(ICustomStudentBase).select(
67        'email', 'phone')
68
69
70class CustomStudentPersonalDisplayFormPage(StudentPersonalDisplayFormPage):
71    """ Page to display student personal data
72    """
73    grok.context(ICustomStudent)
74    form_fields = grok.AutoFields(ICustomStudentPersonal)
75    form_fields['perm_address'].custom_widget = BytesDisplayWidget
76
77
78class CustomStudentPersonalEditFormPage(StudentPersonalEditFormPage):
79    """ Page to edit personal data
80    """
81    form_fields = grok.AutoFields(ICustomStudentPersonal)
82
83
84class CustomStudentClearanceDisplayFormPage(StudentClearanceDisplayFormPage):
85    """ Page to display student clearance data
86    """
87    grok.context(ICustomStudent)
88
89    @property
90    def form_fields(self):
91        cm = getattr(self.context,'current_mode', None)
92        if cm is not None and cm.startswith('pg'):
93            form_fields = grok.AutoFields(
94                ICustomPGStudentClearance).omit('clearance_locked')
95        else:
96            form_fields = grok.AutoFields(
97                ICustomUGStudentClearance).omit('clearance_locked')
98        return form_fields
99
100class CustomExportPDFClearanceSlipPage(ExportPDFClearanceSlipPage):
101    """Deliver a PDF slip of the context.
102    """
103    grok.context(ICustomStudent)
104
105    @property
106    def form_fields(self):
107        cm = getattr(self.context,'current_mode', None)
108        if cm is not None and cm.startswith('pg'):
109            form_fields = grok.AutoFields(
110                ICustomPGStudentClearance).omit('clearance_locked')
111        else:
112            form_fields = grok.AutoFields(
113                ICustomUGStudentClearance).omit('clearance_locked')
114        return form_fields
115
116class CustomStudentClearanceManageFormPage(StudentClearanceManageFormPage):
117    """ Page to edit student clearance data
118    """
119    grok.context(ICustomStudent)
120
121    @property
122    def form_fields(self):
123        cm = getattr(self.context,'current_mode', None)
124        if cm is not None and cm.startswith('pg'):
125            form_fields = grok.AutoFields(ICustomPGStudentClearance)
126        else:
127            form_fields = grok.AutoFields(ICustomUGStudentClearance)
128        return form_fields
129
130class CustomStudentClearanceEditFormPage(StudentClearanceEditFormPage):
131    """ View to edit student clearance data by student
132    """
133    grok.context(ICustomStudent)
134
135    @property
136    def form_fields(self):
137        cm = getattr(self.context,'current_mode', None)
138        if cm is not None and cm.startswith('pg'):
139            form_fields = grok.AutoFields(ICustomPGStudentClearance).omit('clearance_locked')
140        else:
141            form_fields = grok.AutoFields(ICustomUGStudentClearance).omit('clearance_locked')
142        return form_fields
143
144    def dataNotComplete(self):
145        store = getUtility(IExtFileStore)
146        if not store.getFileByContext(self.context, attr=u'birth_certicicate.jpg'):
147            return _('No birth certificate uploaded.')
148        if not store.getFileByContext(self.context, attr=u'ref_let.jpg'):
149            return _('No referee letter uploaded.')
150        if not store.getFileByContext(self.context, attr=u'acc_let.jpg'):
151            return _('No acceptance letter uploaded.')
152        if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'):
153            return _('No first sitting result uploaded.')
154        return False
155
156class CustomOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
157    """ Page to view an online payment ticket
158    """
159    grok.context(ICustomStudentOnlinePayment)
160    form_fields = grok.AutoFields(ICustomStudentOnlinePayment)
161    form_fields[
162        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
163    form_fields[
164        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
165    grok.template('payment_view')
166
167    @property
168    def transaction_code(self):
169        tcode = self.context.p_id
170        return tcode[len(tcode)-8:len(tcode)]
171
172class CustomOnlinePaymentAddFormPage(OnlinePaymentAddFormPage):
173    """ Page to add an online payment ticket
174    """
175    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
176        'p_category')
177    factory = u'waeup.CustomStudentOnlinePayment'
178
179    def _fillCustomFields(self, payment, pay_details):
180        payment.surcharge_1 = pay_details['surcharge_1']
181        payment.surcharge_2 = pay_details['surcharge_2']
182        payment.surcharge_3 = pay_details['surcharge_3']
183        return payment
Note: See TracBrowser for help on using the repository browser.