[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 |
---|