[8012] | 1 | ## $Id: browser.py 11786 2014-08-30 05:42:26Z 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 | """ |
---|
[10287] | 20 | import grok |
---|
[11784] | 21 | from time import time |
---|
[11782] | 22 | from zope.component import getUtility, createObject |
---|
[11736] | 23 | from zope.security import checkPermission |
---|
[11784] | 24 | from hurry.workflow.interfaces import IWorkflowState |
---|
| 25 | from waeup.kofa.browser.layout import action, UtilityView |
---|
[11728] | 26 | from waeup.kofa.interfaces import IExtFileStore |
---|
[10587] | 27 | from waeup.kofa.applicants.browser import ( |
---|
[11728] | 28 | ApplicantRegistrationPage, ApplicantsContainerPage, |
---|
[11782] | 29 | ApplicationFeePaymentAddPage, |
---|
[11784] | 30 | OnlinePaymentApprovePage, |
---|
| 31 | ExportPDFPageApplicationSlip) |
---|
[11782] | 32 | from waeup.kofa.applicants.interfaces import ( |
---|
| 33 | ISpecialApplicant, IApplicantsUtils) |
---|
[10378] | 34 | from kofacustom.nigeria.applicants.browser import ( |
---|
| 35 | NigeriaApplicantDisplayFormPage, |
---|
[11736] | 36 | NigeriaApplicantManageFormPage, |
---|
[10378] | 37 | NigeriaPDFApplicationSlip) |
---|
[11782] | 38 | from waeup.uniben.applicants.interfaces import ( |
---|
| 39 | ICustomApplicant) |
---|
[11784] | 40 | from waeup.kofa.applicants.workflow import ADMITTED, PAID |
---|
[8012] | 41 | |
---|
[10378] | 42 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
| 43 | |
---|
[10338] | 44 | PASTQ_ALL = ['ADT','EPCS','ESM','HEK','VTE'] |
---|
[8012] | 45 | |
---|
[10338] | 46 | PASTQ_AL = ['ENL','FAA','FOL','HIS','LAL', |
---|
| 47 | 'PHL','THR','BUL','JIL','LAW','PPL','PUL'] + PASTQ_ALL |
---|
| 48 | |
---|
| 49 | PASTQ_BS = ['ANT','ANY','CHH','COH','HAE','MED','MEH','PHS','SUR', |
---|
| 50 | 'PCG','PCH','PCO', 'PCT','PHA','PHM','PMB','ANA','MBC', |
---|
| 51 | 'MLS','NSC','PSY','DPV','ODR','OSP','PER', 'RES','AEB', |
---|
| 52 | 'BCH','BOT','CED','EVL','MCB','OPT','PBB','SLT','ZOO', |
---|
| 53 | 'AEE','ANS', 'CRS','FIS','FOW','SOS'] + PASTQ_ALL |
---|
| 54 | |
---|
| 55 | PASTQ_EPS = ['CHE','CVE','DMIC','EEE','MCH','PEE','PRE','CHM', |
---|
| 56 | 'CSC','GLY','MTH','PHY'] + PASTQ_ALL |
---|
| 57 | |
---|
| 58 | PASTQ_MSS = ['ACC','BNK','BUS','ECO','GEO','POL','SAA','SWK'] + PASTQ_ALL |
---|
| 59 | |
---|
[10587] | 60 | class CustomApplicantsContainerPage(ApplicantsContainerPage): |
---|
| 61 | """The standard view for regular applicant containers. |
---|
| 62 | """ |
---|
| 63 | |
---|
| 64 | @property |
---|
| 65 | def form_fields(self): |
---|
| 66 | form_fields = super(CustomApplicantsContainerPage, self).form_fields |
---|
[10589] | 67 | usertype = getattr(self.request.principal, 'user_type', None) |
---|
| 68 | if self.request.principal.id == 'zope.anybody' or \ |
---|
| 69 | usertype in ('applicant', 'student'): |
---|
[10587] | 70 | return form_fields.omit('application_fee') |
---|
| 71 | return form_fields |
---|
| 72 | |
---|
[8630] | 73 | class CustomApplicantRegistrationPage(ApplicantRegistrationPage): |
---|
| 74 | """Captcha'd registration page for applicants. |
---|
| 75 | """ |
---|
| 76 | |
---|
[10337] | 77 | def _redirect(self, email, password, applicant_id): |
---|
| 78 | # Forward email and credentials to landing page. |
---|
| 79 | self.redirect(self.url(self.context, 'registration_complete', |
---|
| 80 | data = dict(email=email, password=password, |
---|
| 81 | applicant_id=applicant_id))) |
---|
| 82 | return |
---|
[10287] | 83 | |
---|
[10375] | 84 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
| 85 | """A display view for applicant data. |
---|
[10287] | 86 | """ |
---|
[10375] | 87 | grok.template('applicantdisplaypage') |
---|
[10338] | 88 | |
---|
[10622] | 89 | def _show_pastq_putme(self): |
---|
[10338] | 90 | return self.target.startswith('putme') \ |
---|
[10375] | 91 | and self.context.state in ('paid', 'submitted') \ |
---|
[10338] | 92 | and getattr(self.context, 'course1') is not None |
---|
| 93 | |
---|
| 94 | @property |
---|
| 95 | def show_pastq_al(self): |
---|
[10622] | 96 | return self._show_pastq_putme() \ |
---|
[10338] | 97 | and self.context.course1.__parent__.__parent__.code in PASTQ_AL |
---|
| 98 | |
---|
| 99 | @property |
---|
| 100 | def show_pastq_bs(self): |
---|
[10622] | 101 | return self._show_pastq_putme() \ |
---|
[10338] | 102 | and self.context.course1.__parent__.__parent__.code in PASTQ_BS |
---|
| 103 | |
---|
| 104 | @property |
---|
| 105 | def show_pastq_eps(self): |
---|
[10622] | 106 | return self._show_pastq_putme() \ |
---|
[10338] | 107 | and self.context.course1.__parent__.__parent__.code in PASTQ_EPS |
---|
| 108 | |
---|
| 109 | @property |
---|
| 110 | def show_pastq_mss(self): |
---|
[10622] | 111 | return self._show_pastq_putme() \ |
---|
[10338] | 112 | and self.context.course1.__parent__.__parent__.code in PASTQ_MSS |
---|
| 113 | |
---|
[10622] | 114 | @property |
---|
| 115 | def show_pastq_pude(self): |
---|
| 116 | return self.target.startswith('pude') \ |
---|
| 117 | and self.context.state in ('paid', 'submitted') |
---|
| 118 | |
---|
[11784] | 119 | # Customizations for admission checking payments |
---|
| 120 | |
---|
[11782] | 121 | @property |
---|
| 122 | def form_fields(self): |
---|
[11784] | 123 | form_fields = super(CustomApplicantDisplayFormPage, self).form_fields |
---|
| 124 | if not self.context.admchecking_fee_paid(): |
---|
| 125 | form_fields = form_fields.omit( |
---|
| 126 | 'screening_score', 'aggregate', 'student_id') |
---|
[11782] | 127 | return form_fields |
---|
| 128 | |
---|
[11784] | 129 | @property |
---|
| 130 | def display_actions(self): |
---|
| 131 | state = IWorkflowState(self.context).getState() |
---|
| 132 | actions = [] |
---|
| 133 | if state == ADMITTED and not self.context.admchecking_fee_paid(): |
---|
| 134 | actions = [_('Add admission checking payment ticket')] |
---|
| 135 | return actions |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | def getCourseAdmitted(self): |
---|
| 139 | """Return link, title and code in html format to the certificate |
---|
| 140 | admitted. |
---|
| 141 | """ |
---|
| 142 | course_admitted = self.context.course_admitted |
---|
| 143 | if getattr(course_admitted, '__parent__',None) and \ |
---|
| 144 | self.context.admchecking_fee_paid(): |
---|
| 145 | url = self.url(course_admitted) |
---|
| 146 | title = course_admitted.title |
---|
| 147 | code = course_admitted.code |
---|
| 148 | return '<a href="%s">%s - %s</a>' %(url,code,title) |
---|
| 149 | return '' |
---|
| 150 | |
---|
[11786] | 151 | @property |
---|
| 152 | def admission_checking_info(self): |
---|
| 153 | if self.context.state == ADMITTED and \ |
---|
| 154 | not self.context.admchecking_fee_paid(): |
---|
| 155 | return _('You must pay the admission checking fee ' |
---|
| 156 | 'to view your screening results and course admitted.') |
---|
| 157 | return |
---|
| 158 | |
---|
[11784] | 159 | @action(_('Add admission checking payment ticket'), style='primary') |
---|
| 160 | def addPaymentTicket(self, **data): |
---|
| 161 | self.redirect(self.url(self.context, '@@addacp')) |
---|
| 162 | return |
---|
| 163 | |
---|
[10378] | 164 | class CustomNigeriaPDFApplicationSlip(NigeriaPDFApplicationSlip): |
---|
[10338] | 165 | |
---|
[10378] | 166 | @property |
---|
| 167 | def note(self): |
---|
| 168 | if self.target is not None and not self.target.startswith('pg') \ |
---|
| 169 | and not self._reduced_slip(): |
---|
| 170 | return _(u'<br /><br /><br />' |
---|
[11771] | 171 | 'Comfirm your screening venue 72 hours to the screening. ' |
---|
[11770] | 172 | '<br /><br />' |
---|
| 173 | 'No bags, phones and calculators are allowed in the ' |
---|
| 174 | 'screening venues.') |
---|
[10378] | 175 | return |
---|
| 176 | |
---|
[11728] | 177 | class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage): |
---|
| 178 | """ Page to add an online payment ticket |
---|
| 179 | """ |
---|
[10378] | 180 | |
---|
[11728] | 181 | @property |
---|
| 182 | def custom_requirements(self): |
---|
| 183 | store = getUtility(IExtFileStore) |
---|
| 184 | if not store.getFileByContext(self.context, attr=u'passport.jpg'): |
---|
[11782] | 185 | return _('Upload your 1"x1" Red background passport photo before making payment.') |
---|
[11728] | 186 | return '' |
---|
| 187 | |
---|
[11784] | 188 | class AdmissionCheckingFeePaymentAddPage(UtilityView, grok.View): |
---|
| 189 | """ Page to add an admission checking online payment ticket. |
---|
| 190 | """ |
---|
| 191 | grok.context(ICustomApplicant) |
---|
| 192 | grok.name('addacp') |
---|
| 193 | grok.require('waeup.payApplicant') |
---|
| 194 | factory = u'waeup.ApplicantOnlinePayment' |
---|
| 195 | |
---|
| 196 | def _setPaymentDetails(self, payment): |
---|
| 197 | container = self.context.__parent__ |
---|
| 198 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
| 199 | session = str(container.year) |
---|
| 200 | try: |
---|
| 201 | session_config = grok.getSite()['configuration'][session] |
---|
| 202 | except KeyError: |
---|
| 203 | return _(u'Session configuration object is not available.'), None |
---|
| 204 | payment.p_id = "p%s" % timestamp |
---|
| 205 | payment.p_item = container.title |
---|
| 206 | payment.p_session = container.year |
---|
| 207 | payment.amount_auth = 0.0 |
---|
| 208 | payment.p_category = 'admission_checking' |
---|
| 209 | payment.amount_auth = session_config.admchecking_fee |
---|
| 210 | if payment.amount_auth in (0.0, None): |
---|
| 211 | return _('Amount could not be determined.'), None |
---|
| 212 | return |
---|
| 213 | |
---|
[11782] | 214 | def update(self): |
---|
[11784] | 215 | if self.context.admchecking_fee_paid(): |
---|
| 216 | self.flash( |
---|
| 217 | _('Admission checking payment has already been made.'), |
---|
| 218 | type='warning') |
---|
| 219 | self.redirect(self.url(self.context)) |
---|
| 220 | return |
---|
[11782] | 221 | payment = createObject(self.factory) |
---|
[11784] | 222 | failure = self._setPaymentDetails(payment) |
---|
[11782] | 223 | if failure is not None: |
---|
| 224 | self.flash(failure[0], type='danger') |
---|
| 225 | self.redirect(self.url(self.context)) |
---|
| 226 | return |
---|
| 227 | self.context[payment.p_id] = payment |
---|
| 228 | self.flash(_('Payment ticket created.')) |
---|
| 229 | self.redirect(self.url(payment)) |
---|
| 230 | return |
---|
[11736] | 231 | |
---|
[11784] | 232 | def render(self): |
---|
| 233 | return |
---|
[11736] | 234 | |
---|
[11784] | 235 | |
---|
[11782] | 236 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
| 237 | |
---|
[11736] | 238 | @property |
---|
| 239 | def custom_upload_requirements(self): |
---|
| 240 | if not checkPermission('waeup.uploadPassportPictures', self.context): |
---|
| 241 | return _('You are not entitled to upload passport pictures.') |
---|
[11782] | 242 | |
---|
| 243 | class CustomOnlinePaymentApprovePage(OnlinePaymentApprovePage): |
---|
| 244 | """ Approval view |
---|
| 245 | """ |
---|
| 246 | |
---|
[11784] | 247 | |
---|
[11782] | 248 | def update(self): |
---|
[11784] | 249 | if self.context.p_category == 'admission_checking': |
---|
| 250 | if self.context.p_state == 'paid': |
---|
| 251 | flashtype = 'warning' |
---|
| 252 | msg = _('This ticket has already been paid.') |
---|
| 253 | log = None |
---|
| 254 | else: |
---|
| 255 | self.context.approve() |
---|
| 256 | log = 'payment approved: %s' % self.context.p_id |
---|
| 257 | msg = _('Payment approved') |
---|
| 258 | flashtype = 'success' |
---|
| 259 | else: |
---|
| 260 | flashtype, msg, log = self.context.approveApplicantPayment() |
---|
[11782] | 261 | if log is not None: |
---|
| 262 | applicant = self.context.__parent__ |
---|
| 263 | # Add log message to applicants.log |
---|
| 264 | applicant.writeLogMessage(self, log) |
---|
| 265 | # Add log message to payments.log |
---|
| 266 | self.context.logger.info( |
---|
| 267 | '%s,%s,%s,%s,%s,,,,,,' % ( |
---|
| 268 | applicant.applicant_id, |
---|
| 269 | self.context.p_id, self.context.p_category, |
---|
| 270 | self.context.amount_auth, self.context.r_code)) |
---|
| 271 | self.flash(msg, type=flashtype) |
---|
| 272 | return |
---|
[11784] | 273 | |
---|
| 274 | class CustomExportPDFPageApplicationSlip(ExportPDFPageApplicationSlip): |
---|
| 275 | """Deliver a PDF slip of the context. |
---|
| 276 | """ |
---|
| 277 | |
---|
| 278 | |
---|
| 279 | def update(self): |
---|
| 280 | super(CustomExportPDFPageApplicationSlip, self).update() |
---|
| 281 | if self.context.state == ADMITTED and \ |
---|
| 282 | not self.context.admchecking_fee_paid(): |
---|
| 283 | self.flash( |
---|
| 284 | _('Please pay admission checking fee before trying to download ' |
---|
| 285 | 'the application slip.'), type='warning') |
---|
| 286 | return self.redirect(self.url(self.context)) |
---|
| 287 | return |
---|