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 | |
---|
26 | from zope.formlib.widgets import FileWidget |
---|
27 | from waeup.sirp.browser import ( |
---|
28 | WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage, |
---|
29 | WAeUPDisplayFormPage, NullValidator) |
---|
30 | from waeup.sirp.browser.pages import LoginPage |
---|
31 | from waeup.sirp.interfaces import IWAeUPObject |
---|
32 | from waeup.sirp.applicants import get_applicant_data, ResultEntry |
---|
33 | from waeup.sirp.applicants.interfaces import ( |
---|
34 | IApplicant, IApplicantPrincipal, IApplicantPDEEditData) |
---|
35 | from waeup.sirp.widgets.passportwidget import ( |
---|
36 | PassportWidget, PassportDisplayWidget |
---|
37 | ) |
---|
38 | #from zope.formlib.objectwidget import ObjectWidget |
---|
39 | from zope.formlib.sequencewidget import ListSequenceWidget, SequenceDisplayWidget |
---|
40 | from zope.formlib.widget import CustomWidgetFactory |
---|
41 | from waeup.sirp.widgets.objectwidget import ( |
---|
42 | WAeUPObjectWidget, WAeUPObjectDisplayWidget) |
---|
43 | from waeup.sirp.widgets.multilistwidget import ( |
---|
44 | MultiListWidget, MultiListDisplayWidget) |
---|
45 | from waeup.sirp.image.browser.widget import ( |
---|
46 | ThumbnailWidget, EncodingImageFileWidget, |
---|
47 | ) |
---|
48 | |
---|
49 | results_widget = CustomWidgetFactory( |
---|
50 | WAeUPObjectWidget, ResultEntry) |
---|
51 | |
---|
52 | results_display_widget = CustomWidgetFactory( |
---|
53 | WAeUPObjectDisplayWidget, ResultEntry) |
---|
54 | |
---|
55 | #list_results_widget = CustomWidgetFactory( |
---|
56 | # ListSequenceWidget, subwidget=results_widget) |
---|
57 | |
---|
58 | list_results_widget = CustomWidgetFactory( |
---|
59 | MultiListWidget, subwidget=results_widget) |
---|
60 | |
---|
61 | list_results_display_widget = CustomWidgetFactory( |
---|
62 | MultiListDisplayWidget, subwidget=results_display_widget) |
---|
63 | |
---|
64 | #class ApplicationsPage(WAeUPPage): |
---|
65 | # grok.context(IApplicantContainer) |
---|
66 | # grok.name('index') |
---|
67 | # title = 'Applications' |
---|
68 | # pnav = 1 |
---|
69 | # |
---|
70 | # def getApplications(self): |
---|
71 | # """Get a list of all stored applications. |
---|
72 | # """ |
---|
73 | # for key, val in self.context.items(): |
---|
74 | # url = self.url(val) |
---|
75 | # yield(dict(url=url, name=key)) |
---|
76 | |
---|
77 | #class AddApplicant(WAeUPAddFormPage): |
---|
78 | # grok.context(IApplicantContainer) |
---|
79 | # grok.name('add') |
---|
80 | # form_fields = grok.AutoFields(IApplicant) |
---|
81 | # form_fields['fst_sit_results'].custom_widget = list_results_widget |
---|
82 | # form_fields['passport'].custom_widget = EncodingImageFileWidget |
---|
83 | # label = 'Add Applicant' |
---|
84 | # title = 'Add Applicant' |
---|
85 | # pnav = 1 |
---|
86 | # |
---|
87 | # @grok.action('Add applicant') |
---|
88 | # def addApplicant(self, **data): |
---|
89 | # from waeup.sirp.jambtables.applicants import Applicant |
---|
90 | # applicant = Applicant() |
---|
91 | # self.applyData(applicant, **data) |
---|
92 | # # XXX: temporarily disabled. |
---|
93 | # #self.context[applicant.reg_no] = applicant |
---|
94 | # try: |
---|
95 | # self.context[applicant.access_code] = applicant |
---|
96 | # except KeyError: |
---|
97 | # self.flash('The given access code is already in use!') |
---|
98 | # return |
---|
99 | # self.redirect(self.url(self.context)) |
---|
100 | |
---|
101 | class DisplayApplicant(WAeUPDisplayFormPage): |
---|
102 | grok.context(IApplicant) |
---|
103 | grok.name('index') |
---|
104 | form_fields = grok.AutoFields(IApplicant) |
---|
105 | form_fields['fst_sit_results'].custom_widget = list_results_display_widget |
---|
106 | #form_fields['passport'].custom_widget = PassportDisplayWidget |
---|
107 | form_fields['passport'].custom_widget = ThumbnailWidget |
---|
108 | label = 'Applicant' |
---|
109 | title = 'Applicant' |
---|
110 | pnav = 1 |
---|
111 | |
---|
112 | class EditApplicant(WAeUPEditFormPage): |
---|
113 | grok.context(IApplicant) |
---|
114 | grok.name('edit') |
---|
115 | form_fields = grok.AutoFields(IApplicantPDEEditData) |
---|
116 | #form_fields['passport'].custom_widget = FileWidget |
---|
117 | #form_fields['passport'].custom_widget = PassportWidget |
---|
118 | form_fields['passport'].custom_widget = EncodingImageFileWidget |
---|
119 | grok.template('form_edit_pde') |
---|
120 | |
---|
121 | def update(self): |
---|
122 | super(EditApplicant, self).update() |
---|
123 | print self.request.form |
---|
124 | return |
---|
125 | |
---|
126 | @property |
---|
127 | def label(self): |
---|
128 | # XXX: Use current/upcoming session |
---|
129 | return 'Apply for Post UDE Screening Test (2009/2010)' |
---|
130 | title = 'Edit Application' |
---|
131 | pnav = 1 |
---|
132 | |
---|
133 | @grok.action('Save') |
---|
134 | def save(self, **data): |
---|
135 | self.applyData(self.context, **data) |
---|
136 | self.context._p_changed = True |
---|
137 | return |
---|
138 | |
---|
139 | @grok.action('Final Submit') |
---|
140 | def finalsubmit(self, **data): |
---|
141 | self.applyData(self.context, **data) |
---|
142 | self.context._p_changed = True |
---|
143 | # XXX: Lock the form for editing... |
---|
144 | return |
---|