[7505] | 1 | ## $Id: browser.py 8140 2012-04-13 06:52:37Z 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.formlib.textwidgets import BytesDisplayWidget |
---|
[8137] | 20 | from zope.component import getUtility |
---|
[7822] | 21 | from waeup.kofa.widgets.datewidget import ( |
---|
[7525] | 22 | FriendlyDateWidget, FriendlyDateDisplayWidget |
---|
| 23 | ) |
---|
[8137] | 24 | from waeup.kofa.interfaces import IExtFileStore |
---|
[7822] | 25 | from waeup.kofa.students.browser import ( |
---|
[8129] | 26 | StudentPersonalDisplayFormPage, |
---|
[7525] | 27 | StudentClearanceManageFormPage, StudentClearanceEditFormPage, |
---|
[7998] | 28 | StudentClearanceDisplayFormPage, OnlinePaymentCallbackPage, |
---|
[8076] | 29 | ExportPDFClearanceSlipPage, StudentBaseManageFormPage, |
---|
[8140] | 30 | StudentBaseEditFormPage, StudentPersonalEditFormPage) |
---|
[7879] | 31 | from waeup.kofa.students.viewlets import RequestCallbackActionButton |
---|
[8020] | 32 | from waeup.uniben.students.interfaces import ( |
---|
[8076] | 33 | IStudentBase, IStudent, IStudentPersonal, |
---|
[7995] | 34 | IUGStudentClearance,IPGStudentClearance, |
---|
[7879] | 35 | ) |
---|
[8020] | 36 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
[8076] | 37 | from waeup.uniben.widgets.phonewidget import PhoneWidget |
---|
[7505] | 38 | |
---|
[7998] | 39 | class RequestCallbackActionButton(RequestCallbackActionButton): |
---|
| 40 | """ Do not display the base package callback button in custom pages. |
---|
| 41 | """ |
---|
| 42 | @property |
---|
| 43 | def target_url(self): |
---|
| 44 | return '' |
---|
| 45 | |
---|
| 46 | class OnlinePaymentCallbackPage(OnlinePaymentCallbackPage): |
---|
| 47 | """ Neutralize callback simulation view |
---|
| 48 | """ |
---|
| 49 | def update(self): |
---|
| 50 | return |
---|
| 51 | |
---|
[8076] | 52 | class StudentBaseManageFormPage(StudentBaseManageFormPage): |
---|
| 53 | """ View to manage student base data |
---|
| 54 | """ |
---|
| 55 | form_fields = grok.AutoFields(IStudentBase).omit('student_id') |
---|
| 56 | form_fields['phone'].custom_widget = PhoneWidget |
---|
| 57 | |
---|
| 58 | class StudentBaseEditFormPage(StudentBaseEditFormPage): |
---|
| 59 | """ View to edit student base data |
---|
| 60 | """ |
---|
| 61 | form_fields = grok.AutoFields(IStudentBase).select( |
---|
| 62 | 'email', 'phone') |
---|
| 63 | form_fields['phone'].custom_widget = PhoneWidget |
---|
| 64 | |
---|
| 65 | |
---|
[7505] | 66 | class StudentPersonalDisplayFormPage(StudentPersonalDisplayFormPage): |
---|
| 67 | """ Page to display student personal data |
---|
| 68 | """ |
---|
| 69 | grok.context(IStudent) |
---|
| 70 | form_fields = grok.AutoFields(IStudentPersonal) |
---|
| 71 | form_fields['perm_address'].custom_widget = BytesDisplayWidget |
---|
| 72 | |
---|
| 73 | |
---|
[8140] | 74 | class StudentPersonalEditFormPage(StudentPersonalEditFormPage): |
---|
| 75 | """ Page to edit personal data |
---|
| 76 | """ |
---|
| 77 | form_fields = grok.AutoFields(IStudentPersonal) |
---|
| 78 | |
---|
| 79 | |
---|
[7525] | 80 | class StudentClearanceDisplayFormPage(StudentClearanceDisplayFormPage): |
---|
| 81 | """ Page to display student clearance data |
---|
| 82 | """ |
---|
| 83 | grok.context(IStudent) |
---|
| 84 | |
---|
[7995] | 85 | @property |
---|
| 86 | def form_fields(self): |
---|
| 87 | cm = getattr(self.context,'current_mode', None) |
---|
| 88 | if cm is not None and cm.startswith('pg'): |
---|
| 89 | form_fields = grok.AutoFields(IPGStudentClearance).omit('clearance_locked') |
---|
[8108] | 90 | form_fields['emp_start'].custom_widget = FriendlyDateDisplayWidget('le') |
---|
| 91 | form_fields['emp_end'].custom_widget = FriendlyDateDisplayWidget('le') |
---|
| 92 | form_fields['emp2_start'].custom_widget = FriendlyDateDisplayWidget('le') |
---|
| 93 | form_fields['emp2_end'].custom_widget = FriendlyDateDisplayWidget('le') |
---|
[7995] | 94 | else: |
---|
| 95 | form_fields = grok.AutoFields(IUGStudentClearance).omit('clearance_locked') |
---|
| 96 | form_fields['date_of_birth'].custom_widget = FriendlyDateDisplayWidget('le') |
---|
[8108] | 97 | form_fields['fst_sit_date'].custom_widget = FriendlyDateDisplayWidget('le') |
---|
| 98 | form_fields['scd_sit_date'].custom_widget = FriendlyDateDisplayWidget('le') |
---|
| 99 | form_fields['scd_sit_date'].custom_widget = FriendlyDateDisplayWidget('le') |
---|
| 100 | form_fields['alr_date'].custom_widget = FriendlyDateDisplayWidget('le') |
---|
[7995] | 101 | return form_fields |
---|
| 102 | |
---|
| 103 | class ExportPDFClearanceSlipPage(ExportPDFClearanceSlipPage): |
---|
| 104 | """Deliver a PDF slip of the context. |
---|
| 105 | """ |
---|
| 106 | grok.context(IStudent) |
---|
| 107 | |
---|
| 108 | @property |
---|
| 109 | def form_fields(self): |
---|
| 110 | cm = getattr(self.context,'current_mode', None) |
---|
| 111 | if cm is not None and cm.startswith('pg'): |
---|
| 112 | form_fields = grok.AutoFields(IPGStudentClearance).omit('clearance_locked') |
---|
[8108] | 113 | form_fields['emp_start'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 114 | form_fields['emp_end'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 115 | form_fields['emp2_start'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 116 | form_fields['emp2_end'].custom_widget = FriendlyDateWidget('le-year') |
---|
[7995] | 117 | else: |
---|
| 118 | form_fields = grok.AutoFields(IUGStudentClearance).omit('clearance_locked') |
---|
| 119 | form_fields['date_of_birth'].custom_widget = FriendlyDateDisplayWidget('le') |
---|
[8108] | 120 | form_fields['fst_sit_date'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 121 | form_fields['scd_sit_date'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 122 | form_fields['scd_sit_date'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 123 | form_fields['alr_date'].custom_widget = FriendlyDateWidget('le-year') |
---|
[7995] | 124 | return form_fields |
---|
| 125 | |
---|
[7525] | 126 | class StudentClearanceManageFormPage(StudentClearanceManageFormPage): |
---|
| 127 | """ Page to edit student clearance data |
---|
| 128 | """ |
---|
| 129 | grok.context(IStudent) |
---|
| 130 | |
---|
[7995] | 131 | @property |
---|
| 132 | def form_fields(self): |
---|
| 133 | cm = getattr(self.context,'current_mode', None) |
---|
| 134 | if cm is not None and cm.startswith('pg'): |
---|
| 135 | form_fields = grok.AutoFields(IPGStudentClearance) |
---|
[8108] | 136 | form_fields['emp_start'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 137 | form_fields['emp_end'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 138 | form_fields['emp2_start'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 139 | form_fields['emp2_end'].custom_widget = FriendlyDateWidget('le-year') |
---|
[7995] | 140 | else: |
---|
| 141 | form_fields = grok.AutoFields(IUGStudentClearance) |
---|
| 142 | form_fields['date_of_birth'].custom_widget = FriendlyDateWidget('le-year') |
---|
[8108] | 143 | form_fields['fst_sit_date'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 144 | form_fields['scd_sit_date'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 145 | form_fields['scd_sit_date'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 146 | form_fields['alr_date'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 147 | |
---|
| 148 | |
---|
[7995] | 149 | return form_fields |
---|
| 150 | |
---|
[7525] | 151 | class StudentClearanceEditFormPage(StudentClearanceEditFormPage): |
---|
| 152 | """ View to edit student clearance data by student |
---|
| 153 | """ |
---|
| 154 | grok.context(IStudent) |
---|
| 155 | |
---|
[7995] | 156 | @property |
---|
| 157 | def form_fields(self): |
---|
| 158 | cm = getattr(self.context,'current_mode', None) |
---|
| 159 | if cm is not None and cm.startswith('pg'): |
---|
| 160 | form_fields = grok.AutoFields(IPGStudentClearance).omit('clearance_locked') |
---|
[8108] | 161 | form_fields['emp_start'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 162 | form_fields['emp_end'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 163 | form_fields['emp2_start'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 164 | form_fields['emp2_end'].custom_widget = FriendlyDateWidget('le-year') |
---|
[7995] | 165 | else: |
---|
| 166 | form_fields = grok.AutoFields(IUGStudentClearance).omit('clearance_locked') |
---|
| 167 | form_fields['date_of_birth'].custom_widget = FriendlyDateWidget('le-year') |
---|
[8108] | 168 | form_fields['fst_sit_date'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 169 | form_fields['scd_sit_date'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 170 | form_fields['scd_sit_date'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 171 | form_fields['alr_date'].custom_widget = FriendlyDateWidget('le-year') |
---|
[7995] | 172 | return form_fields |
---|
| 173 | |
---|
[8137] | 174 | def dataNotComplete(self): |
---|
| 175 | store = getUtility(IExtFileStore) |
---|
| 176 | if not store.getFileByContext(self.context, attr=u'birth_certicicate.jpg'): |
---|
| 177 | return _('No birth certificate uploaded.') |
---|
| 178 | if not store.getFileByContext(self.context, attr=u'ref_let.jpg'): |
---|
| 179 | return _('No referee letter uploaded.') |
---|
| 180 | if not store.getFileByContext(self.context, attr=u'acc_let.jpg'): |
---|
| 181 | return _('No acceptance letter uploaded.') |
---|
| 182 | if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'): |
---|
| 183 | return _('No first sitting result uploaded.') |
---|
| 184 | return False |
---|
| 185 | |
---|