1 | ## $Id: browser.py 9281 2012-10-03 07:08:02Z 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 | ## |
---|
18 | import grok |
---|
19 | from zope.i18n import translate |
---|
20 | from zope.schema.interfaces import ConstraintNotSatisfied |
---|
21 | from hurry.workflow.interfaces import IWorkflowInfo |
---|
22 | from waeup.kofa.interfaces import REQUESTED |
---|
23 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
24 | from waeup.kofa.browser.layout import KofaEditFormPage |
---|
25 | from waeup.kofa.browser.viewlets import ManageActionButton |
---|
26 | from waeup.kofa.browser.layout import action, jsaction |
---|
27 | from waeup.kofa.students.browser import ( |
---|
28 | StudentClearPage, StudentRejectClearancePage, |
---|
29 | StudyCourseDisplayFormPage, |
---|
30 | StudyLevelEditFormPage, |
---|
31 | msave, emit_lock_message) |
---|
32 | from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS |
---|
33 | from kofacustom.nigeria.students.browser import ( |
---|
34 | NigeriaOnlinePaymentDisplayFormPage, |
---|
35 | NigeriaStudentBaseManageFormPage, |
---|
36 | NigeriaOnlinePaymentAddFormPage, |
---|
37 | NigeriaExportPDFPaymentSlipPage, |
---|
38 | ) |
---|
39 | #from waeup.uniben.students.interfaces import ICustomStudent |
---|
40 | |
---|
41 | from waeup.uniben.students.interfaces import ( |
---|
42 | ICustomStudentOnlinePayment, ICustomStudentStudyCourse) |
---|
43 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
44 | |
---|
45 | class CustomStudentBaseManageFormPage(NigeriaStudentBaseManageFormPage): |
---|
46 | """ View to manage student base data |
---|
47 | """ |
---|
48 | #grok.context(ICustomStudent) |
---|
49 | |
---|
50 | def getTransitions(self): |
---|
51 | """Return a list of dicts of allowed transition ids and titles. |
---|
52 | |
---|
53 | Each list entry provides keys ``name`` and ``title`` for |
---|
54 | internal name and (human readable) title of a single |
---|
55 | transition. |
---|
56 | """ |
---|
57 | allowed_transitions = [t for t in self.wf_info.getManualTransitions() |
---|
58 | if not t[0].startswith('pay')] |
---|
59 | if self.context.is_postgrad and not self.context.is_special_postgrad: |
---|
60 | allowed_transitions = [t for t in allowed_transitions |
---|
61 | if not t[0] in FORBIDDEN_POSTGRAD_TRANS] |
---|
62 | return [dict(name='', title=_('No transition'))] +[ |
---|
63 | dict(name=x, title=y) for x, y in allowed_transitions] |
---|
64 | |
---|
65 | class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): |
---|
66 | """ Page to view an online payment ticket |
---|
67 | """ |
---|
68 | grok.context(ICustomStudentOnlinePayment) |
---|
69 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment) |
---|
70 | form_fields[ |
---|
71 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
72 | form_fields[ |
---|
73 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
74 | |
---|
75 | class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage): |
---|
76 | """ Page to add an online payment ticket |
---|
77 | """ |
---|
78 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( |
---|
79 | 'p_category') |
---|
80 | |
---|
81 | class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage): |
---|
82 | """Deliver a PDF slip of the context. |
---|
83 | """ |
---|
84 | grok.context(ICustomStudentOnlinePayment) |
---|
85 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment) |
---|
86 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
87 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
88 | |
---|
89 | |
---|
90 | ## In case we need to deactivate clearance |
---|
91 | #class CustomStudentClearPage(StudentClearPage): |
---|
92 | # """ Clear student by clearance officer |
---|
93 | # """ |
---|
94 | # def update(self): |
---|
95 | # self.flash('Clearance temporarily disabled!') |
---|
96 | # self.redirect(self.url(self.context,'view_clearance')) |
---|
97 | # return |
---|
98 | |
---|
99 | #class CustomStudentRejectClearancePage(StudentRejectClearancePage): |
---|
100 | # """ Reject clearance by clearance officers |
---|
101 | # """ |
---|
102 | |
---|
103 | # def update(self): |
---|
104 | # self.flash('Clearance temporarily disabled!') |
---|
105 | # self.redirect(self.url(self.context,'view_clearance')) |
---|
106 | # return |
---|
107 | |
---|
108 | class StudyCourseEditActionButton(ManageActionButton): |
---|
109 | grok.order(1) |
---|
110 | grok.context(ICustomStudentStudyCourse) |
---|
111 | grok.view(StudyCourseDisplayFormPage) |
---|
112 | grok.require('waeup.clearStudent') |
---|
113 | text = _('Edit level') |
---|
114 | target = 'edit_level' |
---|
115 | |
---|
116 | @property |
---|
117 | def target_url(self): |
---|
118 | if self.context.is_current and self.context.student.state == REQUESTED: |
---|
119 | return self.view.url(self.view.context, self.target) |
---|
120 | return False |
---|
121 | |
---|
122 | class StudyCourseCOEditFormPage(KofaEditFormPage): |
---|
123 | """ Page to edit the student study course data by clearance officers. |
---|
124 | |
---|
125 | This form page is available only in Uniben. |
---|
126 | """ |
---|
127 | grok.context(ICustomStudentStudyCourse) |
---|
128 | grok.name('edit_level') |
---|
129 | grok.require('waeup.clearStudent') |
---|
130 | label = _('Edit current level') |
---|
131 | pnav = 4 |
---|
132 | form_fields = grok.AutoFields( |
---|
133 | ICustomStudentStudyCourse).select('current_level') |
---|
134 | |
---|
135 | def update(self): |
---|
136 | if not (self.context.is_current and |
---|
137 | self.context.student.state == REQUESTED): |
---|
138 | emit_lock_message(self) |
---|
139 | return |
---|
140 | super(StudyCourseCOEditFormPage, self).update() |
---|
141 | return |
---|
142 | |
---|
143 | @action(_('Save'), style='primary') |
---|
144 | def save(self, **data): |
---|
145 | try: |
---|
146 | msave(self, **data) |
---|
147 | except ConstraintNotSatisfied: |
---|
148 | # The selected level might not exist in certificate |
---|
149 | self.flash(_('Current level not available for certificate.')) |
---|
150 | return |
---|
151 | #notify(grok.ObjectModifiedEvent(self.context.__parent__)) |
---|
152 | return |
---|
153 | |
---|
154 | class CustomStudyLevelEditFormPage(StudyLevelEditFormPage): |
---|
155 | """ Page to edit the student study level data by students. |
---|
156 | |
---|
157 | """ |
---|
158 | |
---|
159 | def _registerCourses(self, **data): |
---|
160 | """ This customized version does allow 'special postgraduate' |
---|
161 | students to register their courses. |
---|
162 | """ |
---|
163 | if self.context.student.is_postgrad and \ |
---|
164 | not self.context.student.is_special_postgrad: |
---|
165 | self.flash(_( |
---|
166 | "You are a postgraduate student, " |
---|
167 | "your course list can't bee registered.")) |
---|
168 | self.redirect(self.url(self.context)) |
---|
169 | return |
---|
170 | if self.total_credits > self.max_credits: |
---|
171 | self.flash(_('Maximum credits of ${a} exceeded.', |
---|
172 | mapping = {'a':self.max_credits})) |
---|
173 | return |
---|
174 | IWorkflowInfo(self.context.student).fireTransition( |
---|
175 | 'register_courses') |
---|
176 | self.flash(_('Course list has been registered.')) |
---|
177 | self.redirect(self.url(self.context)) |
---|
178 | return |
---|