[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 | |
---|
[5758] | 65 | #class ApplicationsPage(WAeUPPage): |
---|
| 66 | # grok.context(IApplicantContainer) |
---|
| 67 | # grok.name('index') |
---|
| 68 | # title = 'Applications' |
---|
| 69 | # pnav = 1 |
---|
| 70 | # |
---|
| 71 | # def getApplications(self): |
---|
| 72 | # """Get a list of all stored applications. |
---|
| 73 | # """ |
---|
| 74 | # for key, val in self.context.items(): |
---|
| 75 | # url = self.url(val) |
---|
| 76 | # yield(dict(url=url, name=key)) |
---|
[5273] | 77 | |
---|
[5758] | 78 | #class AddApplicant(WAeUPAddFormPage): |
---|
| 79 | # grok.context(IApplicantContainer) |
---|
| 80 | # grok.name('add') |
---|
| 81 | # form_fields = grok.AutoFields(IApplicant) |
---|
| 82 | # form_fields['fst_sit_results'].custom_widget = list_results_widget |
---|
| 83 | # form_fields['passport'].custom_widget = EncodingImageFileWidget |
---|
| 84 | # label = 'Add Applicant' |
---|
| 85 | # title = 'Add Applicant' |
---|
| 86 | # pnav = 1 |
---|
| 87 | # |
---|
| 88 | # @grok.action('Add applicant') |
---|
| 89 | # def addApplicant(self, **data): |
---|
| 90 | # from waeup.sirp.jambtables.applicants import Applicant |
---|
| 91 | # applicant = Applicant() |
---|
| 92 | # self.applyData(applicant, **data) |
---|
| 93 | # # XXX: temporarily disabled. |
---|
| 94 | # #self.context[applicant.reg_no] = applicant |
---|
| 95 | # try: |
---|
| 96 | # self.context[applicant.access_code] = applicant |
---|
| 97 | # except KeyError: |
---|
| 98 | # self.flash('The given access code is already in use!') |
---|
| 99 | # return |
---|
| 100 | # self.redirect(self.url(self.context)) |
---|
[5273] | 101 | |
---|
| 102 | class DisplayApplicant(WAeUPDisplayFormPage): |
---|
| 103 | grok.context(IApplicant) |
---|
| 104 | grok.name('index') |
---|
| 105 | form_fields = grok.AutoFields(IApplicant) |
---|
| 106 | form_fields['fst_sit_results'].custom_widget = list_results_display_widget |
---|
[5686] | 107 | #form_fields['passport'].custom_widget = PassportDisplayWidget |
---|
| 108 | form_fields['passport'].custom_widget = ThumbnailWidget |
---|
[5273] | 109 | label = 'Applicant' |
---|
| 110 | title = 'Applicant' |
---|
| 111 | pnav = 1 |
---|
| 112 | |
---|
| 113 | class EditApplicant(WAeUPEditFormPage): |
---|
| 114 | grok.context(IApplicant) |
---|
| 115 | grok.name('edit') |
---|
[5484] | 116 | form_fields = grok.AutoFields(IApplicantPDEEditData) |
---|
[5686] | 117 | #form_fields['passport'].custom_widget = FileWidget |
---|
| 118 | #form_fields['passport'].custom_widget = PassportWidget |
---|
| 119 | form_fields['passport'].custom_widget = EncodingImageFileWidget |
---|
[5488] | 120 | grok.template('form_edit_pde') |
---|
[5484] | 121 | |
---|
[5686] | 122 | def update(self): |
---|
| 123 | super(EditApplicant, self).update() |
---|
| 124 | print self.request.form |
---|
| 125 | return |
---|
| 126 | |
---|
[5484] | 127 | @property |
---|
| 128 | def label(self): |
---|
| 129 | # XXX: Use current/upcoming session |
---|
| 130 | return 'Apply for Post UDE Screening Test (2009/2010)' |
---|
[5273] | 131 | title = 'Edit Application' |
---|
| 132 | pnav = 1 |
---|
| 133 | |
---|
| 134 | @grok.action('Save') |
---|
| 135 | def save(self, **data): |
---|
| 136 | self.applyData(self.context, **data) |
---|
| 137 | self.context._p_changed = True |
---|
| 138 | return |
---|
| 139 | |
---|
[5484] | 140 | @grok.action('Final Submit') |
---|
| 141 | def finalsubmit(self, **data): |
---|
[5273] | 142 | self.applyData(self.context, **data) |
---|
[5484] | 143 | self.context._p_changed = True |
---|
| 144 | # XXX: Lock the form for editing... |
---|
[5273] | 145 | return |
---|
| 146 | |
---|
[5442] | 147 | class Login_PDE(LoginPage): |
---|
[5320] | 148 | grok.context(IWAeUPObject) |
---|
| 149 | grok.name('login_pde') |
---|
| 150 | |
---|
| 151 | title = 'PDE Login' |
---|
| 152 | pnav = 1 |
---|
| 153 | |
---|
[5453] | 154 | def update(self): |
---|
[5320] | 155 | """Validate credentials and redirect or show error. |
---|
| 156 | |
---|
[5453] | 157 | The real validation is done by an pluggable authentication |
---|
| 158 | utility (PAU). Here we only check, whether correct credentials |
---|
| 159 | were entered by looking up the principal status of the |
---|
| 160 | request: If the user authenticated successfully, we get an |
---|
| 161 | applicant principal. Otherwise we get the unauthenticated |
---|
| 162 | principal. |
---|
[5320] | 163 | """ |
---|
[5453] | 164 | formfields = ['form.ac_number', 'form.jamb_reg_no', |
---|
| 165 | 'form.ac_series', 'form.prefix',] |
---|
| 166 | |
---|
| 167 | self.reg_no = self.request.form.get('form.jamb_reg_no', '') |
---|
| 168 | self.ac_series = self.request.form.get('form.ac_series', '') |
---|
| 169 | self.ac_number = self.request.form.get('form.ac_number', '') |
---|
| 170 | |
---|
| 171 | for required_field in formfields: |
---|
| 172 | if required_field not in self.request.form.keys(): |
---|
[5320] | 173 | return |
---|
[5453] | 174 | self.reg_no = self.request.form['form.jamb_reg_no'] |
---|
| 175 | self.ac_series = self.request.form['form.ac_series'] |
---|
| 176 | self.ac_number = self.request.form['form.ac_number'] |
---|
| 177 | principal = self.request.principal |
---|
| 178 | if not IApplicantPrincipal.providedBy(principal): |
---|
| 179 | self.flash('You entered invalid credentials') |
---|
[5320] | 180 | return |
---|
[5453] | 181 | if hasattr(principal, 'reg_no'): |
---|
| 182 | if not principal.reg_no is None: |
---|
| 183 | |
---|
| 184 | site = grok.getSite() |
---|
| 185 | applications = site['applications'] |
---|
| 186 | application = applications[principal.reg_no] |
---|
| 187 | self.redirect(self.url(application, '@@edit')) |
---|
[5320] | 188 | return |
---|
| 189 | |
---|
| 190 | def getCurrentSession(self): |
---|
| 191 | """Get the current session. |
---|
| 192 | |
---|
| 193 | XXX: This should be computed or retrieved from elsewhere. |
---|
[5453] | 194 | |
---|
| 195 | `session` here means an academic session, not a browser |
---|
| 196 | session. |
---|
[5320] | 197 | """ |
---|
| 198 | return u'2010/2011' |
---|
| 199 | |
---|
| 200 | def getDeadline(self): |
---|
| 201 | """Get application submission deadline. |
---|
| 202 | |
---|
| 203 | XXX: This should be computed or retrieved from elsewhere. |
---|
| 204 | """ |
---|
| 205 | return u"""Application submission deadline is at Midnight on Friday, |
---|
| 206 | 01. October 2010. No application will be treated |
---|
| 207 | after the deadline.""" |
---|
| 208 | |
---|
| 209 | def getApplicantData(self, reg_no, ac): |
---|
| 210 | """Validate credentials and return applicant data. |
---|
| 211 | |
---|
| 212 | Returns tuple ``(<APPLICANT_ENTRY>, <ACCESSCODE>) on |
---|
| 213 | successful validation and ``None`` else. |
---|
| 214 | |
---|
| 215 | We expect a JAMB registration number and an access code in |
---|
| 216 | format ``PUDE-XXX-XXXXXXXXXX``. |
---|
[5325] | 217 | |
---|
| 218 | See |
---|
| 219 | :func:`waeup.sirp.jambtables.util.get_applicant_data` |
---|
| 220 | for details. |
---|
[5320] | 221 | """ |
---|
[5325] | 222 | return get_applicant_data(reg_no, ac) |
---|