[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 | |
---|
[5822] | 26 | from zope.component import getUtility, getAllUtilitiesRegisteredFor |
---|
[5686] | 27 | from zope.formlib.widgets import FileWidget |
---|
[5273] | 28 | from waeup.sirp.browser import ( |
---|
| 29 | WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage, |
---|
| 30 | WAeUPDisplayFormPage, NullValidator) |
---|
[5442] | 31 | from waeup.sirp.browser.pages import LoginPage |
---|
[5320] | 32 | from waeup.sirp.interfaces import IWAeUPObject |
---|
[5822] | 33 | from waeup.sirp.browser.viewlets import AddActionButton |
---|
[5806] | 34 | from waeup.sirp.applicants import get_applicant_data, ResultEntry |
---|
[5758] | 35 | from waeup.sirp.applicants.interfaces import ( |
---|
[5822] | 36 | IApplicant, IApplicantPrincipal, IApplicantPDEEditData, |
---|
| 37 | IApplicantsRoot, IApplicantsContainer, IApplicantContainerProvider, |
---|
| 38 | ) |
---|
[5686] | 39 | from waeup.sirp.widgets.passportwidget import ( |
---|
| 40 | PassportWidget, PassportDisplayWidget |
---|
| 41 | ) |
---|
[5273] | 42 | #from zope.formlib.objectwidget import ObjectWidget |
---|
| 43 | from zope.formlib.sequencewidget import ListSequenceWidget, SequenceDisplayWidget |
---|
| 44 | from zope.formlib.widget import CustomWidgetFactory |
---|
[5303] | 45 | from waeup.sirp.widgets.objectwidget import ( |
---|
[5301] | 46 | WAeUPObjectWidget, WAeUPObjectDisplayWidget) |
---|
[5303] | 47 | from waeup.sirp.widgets.multilistwidget import ( |
---|
[5273] | 48 | MultiListWidget, MultiListDisplayWidget) |
---|
[5686] | 49 | from waeup.sirp.image.browser.widget import ( |
---|
| 50 | ThumbnailWidget, EncodingImageFileWidget, |
---|
| 51 | ) |
---|
[5320] | 52 | |
---|
[5273] | 53 | results_widget = CustomWidgetFactory( |
---|
[5301] | 54 | WAeUPObjectWidget, ResultEntry) |
---|
[5273] | 55 | |
---|
| 56 | results_display_widget = CustomWidgetFactory( |
---|
[5301] | 57 | WAeUPObjectDisplayWidget, ResultEntry) |
---|
[5273] | 58 | |
---|
| 59 | #list_results_widget = CustomWidgetFactory( |
---|
| 60 | # ListSequenceWidget, subwidget=results_widget) |
---|
| 61 | |
---|
| 62 | list_results_widget = CustomWidgetFactory( |
---|
| 63 | MultiListWidget, subwidget=results_widget) |
---|
| 64 | |
---|
| 65 | list_results_display_widget = CustomWidgetFactory( |
---|
| 66 | MultiListDisplayWidget, subwidget=results_display_widget) |
---|
| 67 | |
---|
[5822] | 68 | class ApplicationsPage(WAeUPPage): |
---|
| 69 | grok.context(IApplicantsRoot) |
---|
| 70 | grok.name('index') |
---|
| 71 | title = 'Applicants' |
---|
| 72 | pnav = 1 |
---|
| 73 | |
---|
| 74 | def getApplications(self): |
---|
| 75 | """Get a list of all stored applicant containers. |
---|
| 76 | """ |
---|
| 77 | for key, val in self.context.items(): |
---|
| 78 | url = self.url(val) |
---|
| 79 | yield(dict(url=url, name=key)) |
---|
[5273] | 80 | |
---|
[5822] | 81 | class AddApplicantsContainerActionButton(AddActionButton): |
---|
| 82 | grok.context(IApplicantsRoot) |
---|
| 83 | grok.view(ApplicationsPage) |
---|
| 84 | text = 'Add applicants container' |
---|
| 85 | |
---|
| 86 | class AddApplicantsContainer(WAeUPPage): |
---|
| 87 | grok.context(IApplicantsRoot) |
---|
| 88 | grok.name('add') |
---|
| 89 | grok.template('addcontainer') |
---|
| 90 | title = 'Add applicants container' |
---|
| 91 | pnav = 1 |
---|
| 92 | |
---|
| 93 | def update(self, providername=None, name=None, ADD=None, CANCEL=None): |
---|
| 94 | if CANCEL is not None: |
---|
| 95 | self.redirect(self.url(self.context)) |
---|
| 96 | return |
---|
| 97 | if ADD is None: |
---|
| 98 | return |
---|
| 99 | if not name: |
---|
| 100 | self.flash('Error: you must give a name') |
---|
| 101 | return |
---|
| 102 | if name in self.context.keys(): |
---|
| 103 | self.flash('A container of the given name already exists') |
---|
| 104 | return |
---|
| 105 | # Add new applicants container... |
---|
| 106 | provider = getUtility(IApplicantContainerProvider, |
---|
| 107 | name=providername) |
---|
| 108 | container = provider.factory() |
---|
| 109 | self.context[name] = container |
---|
| 110 | self.flash('Added "%s".' % name) |
---|
| 111 | self.redirect(self.url(self.context)) |
---|
| 112 | return |
---|
| 113 | |
---|
| 114 | def getContainerProviders(self): |
---|
| 115 | |
---|
| 116 | providers = getAllUtilitiesRegisteredFor(IApplicantContainerProvider) |
---|
| 117 | result = [ |
---|
| 118 | {'name': getattr(x, 'grokcore.component.directive.name'), |
---|
| 119 | 'provider': x} |
---|
| 120 | for x in providers |
---|
| 121 | ] |
---|
| 122 | return result |
---|
| 123 | |
---|
[5758] | 124 | #class AddApplicant(WAeUPAddFormPage): |
---|
| 125 | # grok.context(IApplicantContainer) |
---|
| 126 | # grok.name('add') |
---|
| 127 | # form_fields = grok.AutoFields(IApplicant) |
---|
| 128 | # form_fields['fst_sit_results'].custom_widget = list_results_widget |
---|
| 129 | # form_fields['passport'].custom_widget = EncodingImageFileWidget |
---|
| 130 | # label = 'Add Applicant' |
---|
| 131 | # title = 'Add Applicant' |
---|
| 132 | # pnav = 1 |
---|
| 133 | # |
---|
| 134 | # @grok.action('Add applicant') |
---|
| 135 | # def addApplicant(self, **data): |
---|
| 136 | # from waeup.sirp.jambtables.applicants import Applicant |
---|
| 137 | # applicant = Applicant() |
---|
| 138 | # self.applyData(applicant, **data) |
---|
| 139 | # # XXX: temporarily disabled. |
---|
| 140 | # #self.context[applicant.reg_no] = applicant |
---|
| 141 | # try: |
---|
| 142 | # self.context[applicant.access_code] = applicant |
---|
| 143 | # except KeyError: |
---|
| 144 | # self.flash('The given access code is already in use!') |
---|
| 145 | # return |
---|
| 146 | # self.redirect(self.url(self.context)) |
---|
[5273] | 147 | |
---|
| 148 | class DisplayApplicant(WAeUPDisplayFormPage): |
---|
| 149 | grok.context(IApplicant) |
---|
| 150 | grok.name('index') |
---|
| 151 | form_fields = grok.AutoFields(IApplicant) |
---|
| 152 | form_fields['fst_sit_results'].custom_widget = list_results_display_widget |
---|
[5686] | 153 | #form_fields['passport'].custom_widget = PassportDisplayWidget |
---|
| 154 | form_fields['passport'].custom_widget = ThumbnailWidget |
---|
[5273] | 155 | label = 'Applicant' |
---|
| 156 | title = 'Applicant' |
---|
| 157 | pnav = 1 |
---|
| 158 | |
---|
| 159 | class EditApplicant(WAeUPEditFormPage): |
---|
| 160 | grok.context(IApplicant) |
---|
| 161 | grok.name('edit') |
---|
[5484] | 162 | form_fields = grok.AutoFields(IApplicantPDEEditData) |
---|
[5686] | 163 | #form_fields['passport'].custom_widget = FileWidget |
---|
| 164 | #form_fields['passport'].custom_widget = PassportWidget |
---|
| 165 | form_fields['passport'].custom_widget = EncodingImageFileWidget |
---|
[5488] | 166 | grok.template('form_edit_pde') |
---|
[5484] | 167 | |
---|
[5686] | 168 | def update(self): |
---|
| 169 | super(EditApplicant, self).update() |
---|
| 170 | print self.request.form |
---|
| 171 | return |
---|
| 172 | |
---|
[5484] | 173 | @property |
---|
| 174 | def label(self): |
---|
| 175 | # XXX: Use current/upcoming session |
---|
| 176 | return 'Apply for Post UDE Screening Test (2009/2010)' |
---|
[5273] | 177 | title = 'Edit Application' |
---|
| 178 | pnav = 1 |
---|
| 179 | |
---|
| 180 | @grok.action('Save') |
---|
| 181 | def save(self, **data): |
---|
| 182 | self.applyData(self.context, **data) |
---|
| 183 | self.context._p_changed = True |
---|
| 184 | return |
---|
| 185 | |
---|
[5484] | 186 | @grok.action('Final Submit') |
---|
| 187 | def finalsubmit(self, **data): |
---|
[5273] | 188 | self.applyData(self.context, **data) |
---|
[5484] | 189 | self.context._p_changed = True |
---|
| 190 | # XXX: Lock the form for editing... |
---|
[5273] | 191 | return |
---|