[5273] | 1 | ## |
---|
| 2 | ## browser.py |
---|
| 3 | ## Login : <uli@pu.smp.net> |
---|
| 4 | ## Started on Sun Jun 27 11:03:10 2010 Uli Fouquet |
---|
| 5 | ## $Id$ |
---|
| 6 | ## |
---|
| 7 | ## Copyright (C) 2010 Uli Fouquet |
---|
| 8 | ## This program is free software; you can redistribute it and/or modify |
---|
| 9 | ## it under the terms of the GNU General Public License as published by |
---|
| 10 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 11 | ## (at your option) any later version. |
---|
| 12 | ## |
---|
| 13 | ## This program is distributed in the hope that it will be useful, |
---|
| 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | ## GNU General Public License for more details. |
---|
| 17 | ## |
---|
| 18 | ## You should have received a copy of the GNU General Public License |
---|
| 19 | ## along with this program; if not, write to the Free Software |
---|
| 20 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 21 | ## |
---|
| 22 | """UI components for JAMB tables. |
---|
| 23 | """ |
---|
| 24 | import grok |
---|
| 25 | |
---|
[5686] | 26 | from zope.formlib.widgets import FileWidget |
---|
[5273] | 27 | from waeup.sirp.browser import ( |
---|
| 28 | WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage, |
---|
| 29 | WAeUPDisplayFormPage, NullValidator) |
---|
[5442] | 30 | from waeup.sirp.browser.pages import LoginPage |
---|
[5320] | 31 | from waeup.sirp.interfaces import IWAeUPObject |
---|
[5690] | 32 | from waeup.sirp.applicants.jambtables.util import get_applicant_data |
---|
[5758] | 33 | from waeup.sirp.applicants.interfaces import ( |
---|
| 34 | IApplicant, IApplicantPrincipal, IApplicantPDEEditData) |
---|
[5686] | 35 | from waeup.sirp.widgets.passportwidget import ( |
---|
| 36 | PassportWidget, PassportDisplayWidget |
---|
| 37 | ) |
---|
[5273] | 38 | #from zope.formlib.objectwidget import ObjectWidget |
---|
| 39 | from zope.formlib.sequencewidget import ListSequenceWidget, SequenceDisplayWidget |
---|
| 40 | from zope.formlib.widget import CustomWidgetFactory |
---|
[5758] | 41 | from waeup.sirp.applicants import ResultEntry |
---|
[5303] | 42 | from waeup.sirp.widgets.objectwidget import ( |
---|
[5301] | 43 | WAeUPObjectWidget, WAeUPObjectDisplayWidget) |
---|
[5303] | 44 | from waeup.sirp.widgets.multilistwidget import ( |
---|
[5273] | 45 | MultiListWidget, MultiListDisplayWidget) |
---|
[5686] | 46 | from waeup.sirp.image.browser.widget import ( |
---|
| 47 | ThumbnailWidget, EncodingImageFileWidget, |
---|
| 48 | ) |
---|
[5320] | 49 | |
---|
[5273] | 50 | results_widget = CustomWidgetFactory( |
---|
[5301] | 51 | WAeUPObjectWidget, ResultEntry) |
---|
[5273] | 52 | |
---|
| 53 | results_display_widget = CustomWidgetFactory( |
---|
[5301] | 54 | WAeUPObjectDisplayWidget, ResultEntry) |
---|
[5273] | 55 | |
---|
| 56 | #list_results_widget = CustomWidgetFactory( |
---|
| 57 | # ListSequenceWidget, subwidget=results_widget) |
---|
| 58 | |
---|
| 59 | list_results_widget = CustomWidgetFactory( |
---|
| 60 | MultiListWidget, subwidget=results_widget) |
---|
| 61 | |
---|
| 62 | list_results_display_widget = CustomWidgetFactory( |
---|
| 63 | MultiListDisplayWidget, subwidget=results_display_widget) |
---|
| 64 | |
---|
[5442] | 65 | class Login_PDE(LoginPage): |
---|
[5320] | 66 | grok.context(IWAeUPObject) |
---|
| 67 | grok.name('login_pde') |
---|
| 68 | |
---|
| 69 | title = 'PDE Login' |
---|
| 70 | pnav = 1 |
---|
| 71 | |
---|
[5453] | 72 | def update(self): |
---|
[5320] | 73 | """Validate credentials and redirect or show error. |
---|
| 74 | |
---|
[5453] | 75 | The real validation is done by an pluggable authentication |
---|
| 76 | utility (PAU). Here we only check, whether correct credentials |
---|
| 77 | were entered by looking up the principal status of the |
---|
| 78 | request: If the user authenticated successfully, we get an |
---|
| 79 | applicant principal. Otherwise we get the unauthenticated |
---|
| 80 | principal. |
---|
[5320] | 81 | """ |
---|
[5453] | 82 | formfields = ['form.ac_number', 'form.jamb_reg_no', |
---|
| 83 | 'form.ac_series', 'form.prefix',] |
---|
| 84 | |
---|
| 85 | self.reg_no = self.request.form.get('form.jamb_reg_no', '') |
---|
| 86 | self.ac_series = self.request.form.get('form.ac_series', '') |
---|
| 87 | self.ac_number = self.request.form.get('form.ac_number', '') |
---|
| 88 | |
---|
| 89 | for required_field in formfields: |
---|
| 90 | if required_field not in self.request.form.keys(): |
---|
[5320] | 91 | return |
---|
[5453] | 92 | self.reg_no = self.request.form['form.jamb_reg_no'] |
---|
| 93 | self.ac_series = self.request.form['form.ac_series'] |
---|
| 94 | self.ac_number = self.request.form['form.ac_number'] |
---|
| 95 | principal = self.request.principal |
---|
| 96 | if not IApplicantPrincipal.providedBy(principal): |
---|
| 97 | self.flash('You entered invalid credentials') |
---|
[5320] | 98 | return |
---|
[5453] | 99 | if hasattr(principal, 'reg_no'): |
---|
| 100 | if not principal.reg_no is None: |
---|
| 101 | |
---|
| 102 | site = grok.getSite() |
---|
| 103 | applications = site['applications'] |
---|
| 104 | application = applications[principal.reg_no] |
---|
| 105 | self.redirect(self.url(application, '@@edit')) |
---|
[5320] | 106 | return |
---|
| 107 | |
---|
| 108 | def getCurrentSession(self): |
---|
| 109 | """Get the current session. |
---|
| 110 | |
---|
| 111 | XXX: This should be computed or retrieved from elsewhere. |
---|
[5453] | 112 | |
---|
| 113 | `session` here means an academic session, not a browser |
---|
| 114 | session. |
---|
[5320] | 115 | """ |
---|
| 116 | return u'2010/2011' |
---|
| 117 | |
---|
| 118 | def getDeadline(self): |
---|
| 119 | """Get application submission deadline. |
---|
| 120 | |
---|
| 121 | XXX: This should be computed or retrieved from elsewhere. |
---|
| 122 | """ |
---|
| 123 | return u"""Application submission deadline is at Midnight on Friday, |
---|
| 124 | 01. October 2010. No application will be treated |
---|
| 125 | after the deadline.""" |
---|
| 126 | |
---|
| 127 | def getApplicantData(self, reg_no, ac): |
---|
| 128 | """Validate credentials and return applicant data. |
---|
| 129 | |
---|
| 130 | Returns tuple ``(<APPLICANT_ENTRY>, <ACCESSCODE>) on |
---|
| 131 | successful validation and ``None`` else. |
---|
| 132 | |
---|
| 133 | We expect a JAMB registration number and an access code in |
---|
| 134 | format ``PUDE-XXX-XXXXXXXXXX``. |
---|
[5325] | 135 | |
---|
| 136 | See |
---|
| 137 | :func:`waeup.sirp.jambtables.util.get_applicant_data` |
---|
| 138 | for details. |
---|
[5320] | 139 | """ |
---|
[5325] | 140 | return get_applicant_data(reg_no, ac) |
---|