[10765] | 1 | ## $Id: browser.py 15131 2018-09-07 09:01:25Z 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 |
---|
[15123] | 21 | from time import time |
---|
[15087] | 22 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
[15123] | 23 | from zope.component import getUtility, createObject |
---|
| 24 | from hurry.workflow.interfaces import IWorkflowState |
---|
[10765] | 25 | from waeup.kofa.applicants.browser import ( |
---|
[15123] | 26 | ApplicantRegistrationPage, ApplicantsContainerPage, |
---|
| 27 | ExportPDFPageApplicationSlip) |
---|
| 28 | from waeup.kofa.browser.layout import action, UtilityView |
---|
[10765] | 29 | from kofacustom.nigeria.applicants.browser import ( |
---|
| 30 | NigeriaApplicantDisplayFormPage, |
---|
[15087] | 31 | NigeriaPDFApplicationSlip, |
---|
| 32 | NigeriaApplicantManageFormPage, |
---|
| 33 | NigeriaApplicantEditFormPage) |
---|
| 34 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
| 35 | UG_OMIT_DISPLAY_FIELDS, |
---|
| 36 | UG_OMIT_PDF_FIELDS, |
---|
| 37 | UG_OMIT_MANAGE_FIELDS, |
---|
| 38 | UG_OMIT_EDIT_FIELDS, |
---|
| 39 | PG_OMIT_DISPLAY_FIELDS, |
---|
| 40 | PG_OMIT_PDF_FIELDS, |
---|
| 41 | PG_OMIT_MANAGE_FIELDS, |
---|
| 42 | PG_OMIT_EDIT_FIELDS, |
---|
| 43 | ) |
---|
[15131] | 44 | from waeup.kofa.applicants.workflow import ( |
---|
| 45 | ADMITTED, PAID, STARTED, NOT_ADMITTED, CREATED) |
---|
[15087] | 46 | from kofacustom.edopoly.applicants.interfaces import ( |
---|
| 47 | ICustomUGApplicantEdit, ICustomUGApplicant, |
---|
[15123] | 48 | ICustomPGApplicantEdit, ICustomPGApplicant, |
---|
| 49 | ICustomApplicant,) |
---|
[10765] | 50 | |
---|
[15000] | 51 | from kofacustom.edopoly.interfaces import MessageFactory as _ |
---|
[10765] | 52 | |
---|
[15087] | 53 | # Fields to be omitted in all display forms. course_admitted is |
---|
| 54 | # rendered separately. |
---|
| 55 | |
---|
| 56 | OMIT_DISPLAY_FIELDS = ('locked', 'course_admitted', |
---|
| 57 | 'result_uploaded', 'suspended', 'special_application', |
---|
| 58 | 'bank_account_number', |
---|
| 59 | 'bank_account_name', |
---|
| 60 | 'bank_name') |
---|
| 61 | |
---|
| 62 | # UG students are all undergraduate students. |
---|
| 63 | UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + ( |
---|
| 64 | 'jamb_subjects_list', 'programme_type') |
---|
| 65 | UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',) |
---|
| 66 | UG_OMIT_MANAGE_FIELDS = ( |
---|
| 67 | 'special_application', |
---|
| 68 | 'jamb_subjects_list', |
---|
| 69 | 'programme_type') |
---|
| 70 | UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + OMIT_DISPLAY_FIELDS + ( |
---|
| 71 | 'student_id', |
---|
| 72 | 'notice', |
---|
| 73 | 'screening_score', |
---|
| 74 | 'screening_venue', |
---|
| 75 | 'screening_date', |
---|
| 76 | # 'jamb_age', |
---|
| 77 | # 'jamb_subjects', |
---|
| 78 | # 'jamb_score', |
---|
| 79 | # 'jamb_reg_number', |
---|
| 80 | 'aggregate') |
---|
| 81 | |
---|
| 82 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
| 83 | """A display view for applicant data. |
---|
| 84 | """ |
---|
[15123] | 85 | grok.template('applicantdisplaypage') |
---|
[15087] | 86 | |
---|
| 87 | @property |
---|
| 88 | def form_fields(self): |
---|
| 89 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
| 90 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
[15123] | 91 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
| 92 | form_fields = form_fields.omit(field) |
---|
[15087] | 93 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
| 94 | form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget |
---|
| 95 | if not getattr(self.context, 'student_id'): |
---|
| 96 | form_fields = form_fields.omit('student_id') |
---|
| 97 | if not getattr(self.context, 'screening_score'): |
---|
| 98 | form_fields = form_fields.omit('screening_score') |
---|
| 99 | if not getattr(self.context, 'screening_venue'): |
---|
| 100 | form_fields = form_fields.omit('screening_venue') |
---|
| 101 | if not getattr(self.context, 'screening_date'): |
---|
| 102 | form_fields = form_fields.omit('screening_date') |
---|
[15123] | 103 | if not self.context.admchecking_fee_paid(): |
---|
| 104 | form_fields = form_fields.omit( |
---|
| 105 | 'screening_score', 'aggregate', 'student_id') |
---|
[15087] | 106 | return form_fields |
---|
| 107 | |
---|
[15123] | 108 | @property |
---|
| 109 | def admission_checking_info(self): |
---|
[15131] | 110 | if self.context.state in (ADMITTED, NOT_ADMITTED, CREATED) and \ |
---|
[15123] | 111 | not self.context.admchecking_fee_paid(): |
---|
| 112 | return _('You must pay the admission checking fee ' |
---|
[15124] | 113 | 'to view your screening results and your course admitted.') |
---|
[15123] | 114 | |
---|
| 115 | @property |
---|
| 116 | def display_actions(self): |
---|
| 117 | state = IWorkflowState(self.context).getState() |
---|
| 118 | actions = [] |
---|
[15131] | 119 | if state in (ADMITTED, NOT_ADMITTED, CREATED) \ |
---|
| 120 | and not self.context.admchecking_fee_paid(): |
---|
[15123] | 121 | actions = [_('Add admission checking payment ticket')] |
---|
| 122 | return actions |
---|
| 123 | |
---|
| 124 | def getCourseAdmitted(self): |
---|
| 125 | """Return link, title and code in html format to the certificate |
---|
| 126 | admitted. |
---|
| 127 | """ |
---|
| 128 | if self.admission_checking_info: |
---|
[15124] | 129 | return '<span class="hint">%s</span>' % self.admission_checking_info |
---|
[15123] | 130 | return super(CustomApplicantDisplayFormPage, self).getCourseAdmitted() |
---|
| 131 | |
---|
| 132 | @action(_('Add admission checking payment ticket'), style='primary') |
---|
| 133 | def addPaymentTicket(self, **data): |
---|
| 134 | self.redirect(self.url(self.context, '@@addacp')) |
---|
| 135 | return |
---|
| 136 | |
---|
| 137 | class AdmissionCheckingFeePaymentAddPage(UtilityView, grok.View): |
---|
| 138 | """ Page to add an admission checking online payment ticket. |
---|
| 139 | """ |
---|
| 140 | grok.context(ICustomApplicant) |
---|
| 141 | grok.name('addacp') |
---|
| 142 | grok.require('waeup.payApplicant') |
---|
| 143 | factory = u'waeup.ApplicantOnlinePayment' |
---|
| 144 | |
---|
| 145 | def _setPaymentDetails(self, payment): |
---|
| 146 | container = self.context.__parent__ |
---|
| 147 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
| 148 | session = str(container.year) |
---|
| 149 | try: |
---|
| 150 | session_config = grok.getSite()['configuration'][session] |
---|
| 151 | except KeyError: |
---|
| 152 | return _(u'Session configuration object is not available.'), None |
---|
| 153 | payment.p_id = "p%s" % timestamp |
---|
| 154 | payment.p_item = container.title |
---|
| 155 | payment.p_session = container.year |
---|
| 156 | payment.amount_auth = 0.0 |
---|
| 157 | payment.p_category = 'admission_checking' |
---|
| 158 | payment.amount_auth = session_config.admchecking_fee |
---|
| 159 | if payment.amount_auth in (0.0, None): |
---|
| 160 | return _('Amount could not be determined.'), None |
---|
| 161 | return |
---|
| 162 | |
---|
| 163 | def update(self): |
---|
| 164 | if self.context.admchecking_fee_paid(): |
---|
| 165 | self.flash( |
---|
| 166 | _('Admission checking payment has already been made.'), |
---|
| 167 | type='warning') |
---|
| 168 | self.redirect(self.url(self.context)) |
---|
| 169 | return |
---|
| 170 | payment = createObject(self.factory) |
---|
| 171 | failure = self._setPaymentDetails(payment) |
---|
| 172 | if failure is not None: |
---|
| 173 | self.flash(failure[0], type='danger') |
---|
| 174 | self.redirect(self.url(self.context)) |
---|
| 175 | return |
---|
| 176 | self.context[payment.p_id] = payment |
---|
| 177 | self.flash(_('Payment ticket created.')) |
---|
| 178 | self.redirect(self.url(payment)) |
---|
| 179 | return |
---|
| 180 | |
---|
| 181 | def render(self): |
---|
| 182 | return |
---|
| 183 | |
---|
| 184 | class CustomExportPDFPageApplicationSlip(ExportPDFPageApplicationSlip): |
---|
| 185 | """Deliver a PDF slip of the context. |
---|
| 186 | """ |
---|
| 187 | |
---|
| 188 | def update(self): |
---|
| 189 | super(CustomExportPDFPageApplicationSlip, self).update() |
---|
[15131] | 190 | if self.context.state in (ADMITTED, NOT_ADMITTED, CREATED) and \ |
---|
[15123] | 191 | not self.context.admchecking_fee_paid(): |
---|
| 192 | self.flash( |
---|
| 193 | _('Please pay admission checking fee before trying to download ' |
---|
| 194 | 'the application slip.'), type='warning') |
---|
| 195 | return self.redirect(self.url(self.context)) |
---|
| 196 | return |
---|
| 197 | |
---|
[15087] | 198 | class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): |
---|
| 199 | |
---|
| 200 | @property |
---|
| 201 | def form_fields(self): |
---|
| 202 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
| 203 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 204 | for field in UG_OMIT_PDF_FIELDS: |
---|
| 205 | form_fields = form_fields.omit(field) |
---|
| 206 | if not getattr(self.context, 'student_id'): |
---|
| 207 | form_fields = form_fields.omit('student_id') |
---|
| 208 | if not getattr(self.context, 'screening_score'): |
---|
| 209 | form_fields = form_fields.omit('screening_score') |
---|
| 210 | if not getattr(self.context, 'screening_venue'): |
---|
| 211 | form_fields = form_fields.omit('screening_venue') |
---|
| 212 | if not getattr(self.context, 'screening_date'): |
---|
| 213 | form_fields = form_fields.omit('screening_date') |
---|
| 214 | return form_fields |
---|
| 215 | |
---|
| 216 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
| 217 | """A full edit view for applicant data. |
---|
| 218 | """ |
---|
| 219 | |
---|
| 220 | @property |
---|
| 221 | def form_fields(self): |
---|
| 222 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
| 223 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
| 224 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
| 225 | form_fields = form_fields.omit(field) |
---|
| 226 | form_fields['student_id'].for_display = True |
---|
| 227 | form_fields['applicant_id'].for_display = True |
---|
| 228 | return form_fields |
---|
| 229 | |
---|
| 230 | class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): |
---|
| 231 | """An applicant-centered edit view for applicant data. |
---|
| 232 | """ |
---|
| 233 | |
---|
| 234 | @property |
---|
| 235 | def form_fields(self): |
---|
| 236 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
| 237 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
| 238 | for field in UG_OMIT_EDIT_FIELDS: |
---|
| 239 | form_fields = form_fields.omit(field) |
---|
| 240 | form_fields['applicant_id'].for_display = True |
---|
| 241 | form_fields['reg_number'].for_display = True |
---|
| 242 | return form_fields |
---|