1 | ## $Id: browser.py 8254 2012-04-22 20:19:11Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2011 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 | ## |
---|
18 | """UI components for basic applicants and related components. |
---|
19 | """ |
---|
20 | import grok |
---|
21 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
22 | from waeup.kofa.applicants.interfaces import ( |
---|
23 | IApplicantRegisterUpdate, IApplicant, IApplicantEdit) |
---|
24 | from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage, |
---|
25 | OnlinePaymentCallbackPage, ExportPDFPage, |
---|
26 | ApplicantManageFormPage, ApplicantEditFormPage, |
---|
27 | ApplicantRegistrationPage, ApplicantAddFormPage, |
---|
28 | OnlinePaymentDisplayFormPage, AcceptanceFeePaymentAddPage, |
---|
29 | OnlinePaymentBreadcrumb) |
---|
30 | from waeup.kofa.applicants.viewlets import RequestCallbackActionButton |
---|
31 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
32 | from waeup.uniben.applicants.interfaces import ( |
---|
33 | IPGApplicant, IUGApplicant, IPGApplicantEdit, IUGApplicantEdit, |
---|
34 | ICustomApplicantOnlinePayment) |
---|
35 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
36 | |
---|
37 | #class RequestCallbackActionButton(RequestCallbackActionButton): |
---|
38 | # """ Do not display the base package callback button in custom pages. |
---|
39 | # """ |
---|
40 | # @property |
---|
41 | # def target_url(self): |
---|
42 | # return '' |
---|
43 | |
---|
44 | #class CustomOnlinePaymentCallbackPage(OnlinePaymentCallbackPage): |
---|
45 | # """ Neutralize callback simulation view |
---|
46 | # """ |
---|
47 | # def update(self): |
---|
48 | # return |
---|
49 | |
---|
50 | class CustomOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb): |
---|
51 | """A breadcrumb for payments. |
---|
52 | """ |
---|
53 | grok.context(ICustomApplicantOnlinePayment) |
---|
54 | |
---|
55 | class CustomPDFApplicationSlip(PDFApplicationSlip): |
---|
56 | |
---|
57 | @property |
---|
58 | def form_fields(self): |
---|
59 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
60 | if target is not None and target.startswith('pg'): |
---|
61 | form_fields = grok.AutoFields(IPGApplicant).omit( |
---|
62 | 'locked', 'course_admitted') |
---|
63 | else: |
---|
64 | form_fields = grok.AutoFields(IUGApplicant).omit( |
---|
65 | 'locked', 'course_admitted') |
---|
66 | return form_fields |
---|
67 | |
---|
68 | class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage): |
---|
69 | """A display view for applicant data. |
---|
70 | """ |
---|
71 | |
---|
72 | @property |
---|
73 | def form_fields(self): |
---|
74 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
75 | if target is not None and target.startswith('pg'): |
---|
76 | form_fields = grok.AutoFields(IPGApplicant).omit( |
---|
77 | 'locked', 'course_admitted', 'password') |
---|
78 | else: |
---|
79 | form_fields = grok.AutoFields(IUGApplicant).omit( |
---|
80 | 'locked', 'course_admitted', 'password') |
---|
81 | return form_fields |
---|
82 | |
---|
83 | class CustomApplicantManageFormPage(ApplicantManageFormPage): |
---|
84 | """A full edit view for applicant data. |
---|
85 | """ |
---|
86 | |
---|
87 | @property |
---|
88 | def form_fields(self): |
---|
89 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
90 | if target is not None and target.startswith('pg'): |
---|
91 | form_fields = grok.AutoFields(IPGApplicant) |
---|
92 | else: |
---|
93 | form_fields = grok.AutoFields(IUGApplicant) |
---|
94 | form_fields['student_id'].for_display = True |
---|
95 | form_fields['applicant_id'].for_display = True |
---|
96 | return form_fields |
---|
97 | |
---|
98 | class CustomApplicantEditFormPage(ApplicantEditFormPage): |
---|
99 | """An applicant-centered edit view for applicant data. |
---|
100 | """ |
---|
101 | |
---|
102 | @property |
---|
103 | def form_fields(self): |
---|
104 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
105 | if target is not None and target.startswith('pg'): |
---|
106 | form_fields = grok.AutoFields(IPGApplicantEdit).omit( |
---|
107 | 'locked', 'course_admitted', 'student_id', |
---|
108 | 'screening_score', 'screening_venue' |
---|
109 | ) |
---|
110 | else: |
---|
111 | form_fields = grok.AutoFields(IUGApplicantEdit).omit( |
---|
112 | 'locked', 'course_admitted', 'student_id', |
---|
113 | 'screening_score' |
---|
114 | ) |
---|
115 | form_fields['applicant_id'].for_display = True |
---|
116 | form_fields['reg_number'].for_display = True |
---|
117 | return form_fields |
---|
118 | |
---|
119 | class CustomOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage): |
---|
120 | """ Page to view an online payment ticket |
---|
121 | """ |
---|
122 | grok.context(ICustomApplicantOnlinePayment) |
---|
123 | form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit( |
---|
124 | 'surcharge_1', 'surcharge_2', 'surcharge_3', 'ac') |
---|
125 | form_fields[ |
---|
126 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
127 | form_fields[ |
---|
128 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
129 | grok.template('payment_view') |
---|
130 | |
---|
131 | @property |
---|
132 | def transaction_code(self): |
---|
133 | tcode = self.context.p_id |
---|
134 | return tcode[len(tcode)-8:len(tcode)] |
---|
135 | |
---|
136 | class CustomAcceptanceFeePaymentAddPage(AcceptanceFeePaymentAddPage): |
---|
137 | """ Page to add an online payment ticket |
---|
138 | """ |
---|
139 | factory = u'waeup.CustomApplicantOnlinePayment' |
---|
140 | |
---|
141 | def _fillCustomFields(self, payment, session_config): |
---|
142 | payment.surcharge_1 = session_config.surcharge_1 |
---|
143 | payment.surcharge_2 = session_config.surcharge_2 |
---|
144 | payment.surcharge_3 = session_config.surcharge_3 |
---|
145 | return payment |
---|