[5273] | 1 | ## |
---|
| 2 | ## browser.py |
---|
| 3 | ## Login : <uli@pu.smp.net> |
---|
[6153] | 4 | ## Started on Sun Jun 27 11:03:10 2010 Uli Fouquet & Henrik Bettermann |
---|
[5273] | 5 | ## $Id: browser.py 7184 2011-11-24 09:20:13Z henrik $ |
---|
[6078] | 6 | ## |
---|
[6063] | 7 | ## Copyright (C) 2010 Uli Fouquet & Henrik Bettermann |
---|
[5273] | 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. |
---|
[6078] | 12 | ## |
---|
[5273] | 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. |
---|
[6078] | 17 | ## |
---|
[5273] | 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 | ## |
---|
[5824] | 22 | """UI components for basic applicants and related components. |
---|
[5273] | 23 | """ |
---|
[7063] | 24 | import os |
---|
[6082] | 25 | import sys |
---|
[5273] | 26 | import grok |
---|
| 27 | |
---|
[6816] | 28 | from datetime import datetime, date |
---|
| 29 | from zope.authentication.interfaces import ILogout, IAuthentication |
---|
| 30 | from zope.component import getUtility |
---|
[6081] | 31 | from zope.formlib.widget import CustomWidgetFactory |
---|
[6358] | 32 | from zope.formlib.form import setUpEditWidgets |
---|
[5937] | 33 | from zope.securitypolicy.interfaces import IPrincipalRoleManager |
---|
[6153] | 34 | from zope.traversing.browser import absoluteURL |
---|
[6081] | 35 | |
---|
[6303] | 36 | from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState |
---|
[6357] | 37 | from reportlab.pdfgen import canvas |
---|
[6364] | 38 | from reportlab.lib.units import cm |
---|
[6390] | 39 | from reportlab.lib.pagesizes import A4 |
---|
[6364] | 40 | from reportlab.lib.styles import getSampleStyleSheet |
---|
| 41 | from reportlab.platypus import (Frame, Paragraph, Image, |
---|
| 42 | Table, Spacer) |
---|
| 43 | from reportlab.platypus.tables import TableStyle |
---|
[6357] | 44 | |
---|
[6469] | 45 | from waeup.sirp.accesscodes import invalidate_accesscode, get_access_code |
---|
| 46 | from waeup.sirp.accesscodes.workflow import USED |
---|
[5273] | 47 | from waeup.sirp.browser import ( |
---|
[6321] | 48 | WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage, WAeUPDisplayFormPage) |
---|
[6081] | 49 | from waeup.sirp.browser.breadcrumbs import Breadcrumb |
---|
[6103] | 50 | from waeup.sirp.browser.layout import NullValidator |
---|
[6321] | 51 | from waeup.sirp.browser.pages import add_local_role, del_local_roles |
---|
[6013] | 52 | from waeup.sirp.browser.resources import datepicker, tabs, datatable |
---|
[6153] | 53 | from waeup.sirp.browser.viewlets import ( |
---|
| 54 | ManageActionButton, PrimaryNavTab, LeftSidebarLink |
---|
| 55 | ) |
---|
[7063] | 56 | from waeup.sirp.interfaces import ( |
---|
| 57 | IWAeUPObject, ILocalRolesAssignable, IExtFileStore, IFileStoreNameChooser) |
---|
[6321] | 58 | from waeup.sirp.permissions import get_users_with_local_roles |
---|
[7094] | 59 | from waeup.sirp.browser import DEFAULT_PASSPORT_IMAGE_PATH |
---|
[6254] | 60 | from waeup.sirp.university.interfaces import ICertificate |
---|
[7081] | 61 | from waeup.sirp.utils.helpers import string_from_bytes, file_size |
---|
[6054] | 62 | from waeup.sirp.widgets.datewidget import ( |
---|
| 63 | FriendlyDateWidget, FriendlyDateDisplayWidget) |
---|
[6084] | 64 | from waeup.sirp.widgets.restwidget import ReSTDisplayWidget |
---|
[5303] | 65 | from waeup.sirp.widgets.objectwidget import ( |
---|
[5301] | 66 | WAeUPObjectWidget, WAeUPObjectDisplayWidget) |
---|
[6153] | 67 | from waeup.sirp.applicants import ResultEntry, Applicant, get_applicant_data |
---|
[6081] | 68 | from waeup.sirp.applicants.interfaces import ( |
---|
[6321] | 69 | IApplicant, IApplicantPrincipal,IApplicantEdit, IApplicantsRoot, |
---|
[7063] | 70 | IApplicantsContainer, IApplicantsContainerAdd, application_types_vocab, |
---|
[7094] | 71 | MAX_UPLOAD_SIZE, |
---|
[5686] | 72 | ) |
---|
[6353] | 73 | from waeup.sirp.applicants.workflow import INITIALIZED, STARTED |
---|
[5320] | 74 | |
---|
[5273] | 75 | results_widget = CustomWidgetFactory( |
---|
[5301] | 76 | WAeUPObjectWidget, ResultEntry) |
---|
[5273] | 77 | |
---|
| 78 | results_display_widget = CustomWidgetFactory( |
---|
[5301] | 79 | WAeUPObjectDisplayWidget, ResultEntry) |
---|
[5273] | 80 | |
---|
[6067] | 81 | class ApplicantsRootPage(WAeUPPage): |
---|
[5822] | 82 | grok.context(IApplicantsRoot) |
---|
| 83 | grok.name('index') |
---|
[6153] | 84 | grok.require('waeup.Public') |
---|
[5822] | 85 | title = 'Applicants' |
---|
[6069] | 86 | label = 'Application Section' |
---|
[5843] | 87 | pnav = 3 |
---|
[6012] | 88 | |
---|
| 89 | def update(self): |
---|
[6067] | 90 | super(ApplicantsRootPage, self).update() |
---|
[6012] | 91 | datatable.need() |
---|
| 92 | return |
---|
| 93 | |
---|
[5828] | 94 | class ManageApplicantsRootActionButton(ManageActionButton): |
---|
| 95 | grok.context(IApplicantsRoot) |
---|
[6067] | 96 | grok.view(ApplicantsRootPage) |
---|
[7136] | 97 | grok.require('waeup.manageApplication') |
---|
[6069] | 98 | text = 'Manage application section' |
---|
[5828] | 99 | |
---|
[6069] | 100 | class ApplicantsRootManageFormPage(WAeUPEditFormPage): |
---|
[5828] | 101 | grok.context(IApplicantsRoot) |
---|
| 102 | grok.name('manage') |
---|
[6107] | 103 | grok.template('applicantsrootmanagepage') |
---|
[6069] | 104 | title = 'Applicants' |
---|
| 105 | label = 'Manage application section' |
---|
[5843] | 106 | pnav = 3 |
---|
[7136] | 107 | grok.require('waeup.manageApplication') |
---|
[6069] | 108 | taboneactions = ['Add applicants container', 'Remove selected','Cancel'] |
---|
[6184] | 109 | tabtwoactions1 = ['Remove selected local roles'] |
---|
| 110 | tabtwoactions2 = ['Add local role'] |
---|
[6069] | 111 | subunits = 'Applicants Containers' |
---|
[6078] | 112 | |
---|
[6069] | 113 | def update(self): |
---|
| 114 | tabs.need() |
---|
[6108] | 115 | datatable.need() |
---|
[6069] | 116 | return super(ApplicantsRootManageFormPage, self).update() |
---|
[5828] | 117 | |
---|
[6184] | 118 | def getLocalRoles(self): |
---|
| 119 | roles = ILocalRolesAssignable(self.context) |
---|
| 120 | return roles() |
---|
| 121 | |
---|
| 122 | def getUsers(self): |
---|
| 123 | """Get a list of all users. |
---|
| 124 | """ |
---|
| 125 | for key, val in grok.getSite()['users'].items(): |
---|
| 126 | url = self.url(val) |
---|
| 127 | yield(dict(url=url, name=key, val=val)) |
---|
| 128 | |
---|
| 129 | def getUsersWithLocalRoles(self): |
---|
| 130 | return get_users_with_local_roles(self.context) |
---|
| 131 | |
---|
[6069] | 132 | # ToDo: Show warning message before deletion |
---|
| 133 | @grok.action('Remove selected') |
---|
| 134 | def delApplicantsContainers(self, **data): |
---|
| 135 | form = self.request.form |
---|
| 136 | child_id = form['val_id'] |
---|
| 137 | if not isinstance(child_id, list): |
---|
| 138 | child_id = [child_id] |
---|
| 139 | deleted = [] |
---|
| 140 | for id in child_id: |
---|
| 141 | try: |
---|
| 142 | del self.context[id] |
---|
| 143 | deleted.append(id) |
---|
| 144 | except: |
---|
| 145 | self.flash('Could not delete %s: %s: %s' % ( |
---|
| 146 | id, sys.exc_info()[0], sys.exc_info()[1])) |
---|
| 147 | if len(deleted): |
---|
| 148 | self.flash('Successfully removed: %s' % ', '.join(deleted)) |
---|
[6078] | 149 | self.redirect(self.url(self.context, '@@manage')+'#tab-1') |
---|
| 150 | return |
---|
[5828] | 151 | |
---|
[6069] | 152 | @grok.action('Add applicants container', validator=NullValidator) |
---|
| 153 | def addApplicantsContainer(self, **data): |
---|
| 154 | self.redirect(self.url(self.context, '@@add')) |
---|
[6078] | 155 | return |
---|
| 156 | |
---|
[6069] | 157 | @grok.action('Cancel', validator=NullValidator) |
---|
| 158 | def cancel(self, **data): |
---|
| 159 | self.redirect(self.url(self.context)) |
---|
[6078] | 160 | return |
---|
| 161 | |
---|
[6184] | 162 | @grok.action('Add local role', validator=NullValidator) |
---|
| 163 | def addLocalRole(self, **data): |
---|
| 164 | return add_local_role(self,2, **data) |
---|
| 165 | |
---|
| 166 | @grok.action('Remove selected local roles') |
---|
| 167 | def delLocalRoles(self, **data): |
---|
| 168 | return del_local_roles(self,2,**data) |
---|
| 169 | |
---|
[6069] | 170 | class ApplicantsContainerAddFormPage(WAeUPAddFormPage): |
---|
[5822] | 171 | grok.context(IApplicantsRoot) |
---|
[7136] | 172 | grok.require('waeup.manageApplication') |
---|
[5822] | 173 | grok.name('add') |
---|
[6107] | 174 | grok.template('applicantscontaineraddpage') |
---|
[6069] | 175 | title = 'Applicants' |
---|
| 176 | label = 'Add applicants container' |
---|
[5843] | 177 | pnav = 3 |
---|
[6078] | 178 | |
---|
[6103] | 179 | form_fields = grok.AutoFields( |
---|
| 180 | IApplicantsContainerAdd).omit('code').omit('title') |
---|
[6083] | 181 | form_fields['startdate'].custom_widget = FriendlyDateWidget('le') |
---|
| 182 | form_fields['enddate'].custom_widget = FriendlyDateWidget('le') |
---|
[6078] | 183 | |
---|
[6083] | 184 | def update(self): |
---|
| 185 | datepicker.need() # Enable jQuery datepicker in date fields. |
---|
| 186 | return super(ApplicantsContainerAddFormPage, self).update() |
---|
| 187 | |
---|
[6069] | 188 | @grok.action('Add applicants container') |
---|
| 189 | def addApplicantsContainer(self, **data): |
---|
[6103] | 190 | year = data['year'] |
---|
| 191 | code = u'%s%s' % (data['prefix'], year) |
---|
| 192 | prefix = application_types_vocab.getTerm(data['prefix']) |
---|
| 193 | title = u'%s %s/%s' % (prefix.title, year, year + 1) |
---|
[6087] | 194 | if code in self.context.keys(): |
---|
[6105] | 195 | self.flash( |
---|
| 196 | 'An applicants container for the same application ' |
---|
| 197 | 'type and entrance year exists already in the database.') |
---|
[5822] | 198 | return |
---|
| 199 | # Add new applicants container... |
---|
[6083] | 200 | provider = data['provider'][1] |
---|
[5822] | 201 | container = provider.factory() |
---|
[6069] | 202 | self.applyData(container, **data) |
---|
[6087] | 203 | container.code = code |
---|
| 204 | container.title = title |
---|
| 205 | self.context[code] = container |
---|
[6105] | 206 | self.flash('Added: "%s".' % code) |
---|
[6069] | 207 | self.redirect(self.url(self.context, u'@@manage')+'#tab-1') |
---|
[5822] | 208 | return |
---|
[6078] | 209 | |
---|
[6103] | 210 | @grok.action('Cancel', validator=NullValidator) |
---|
[6069] | 211 | def cancel(self, **data): |
---|
[6103] | 212 | self.redirect(self.url(self.context, '@@manage') + '#tab-1') |
---|
[6078] | 213 | |
---|
[5845] | 214 | class ApplicantsRootBreadcrumb(Breadcrumb): |
---|
| 215 | """A breadcrumb for applicantsroot. |
---|
| 216 | """ |
---|
| 217 | grok.context(IApplicantsRoot) |
---|
[6654] | 218 | title = u'Applicants' |
---|
[6078] | 219 | |
---|
[5845] | 220 | class ApplicantsContainerBreadcrumb(Breadcrumb): |
---|
| 221 | """A breadcrumb for applicantscontainers. |
---|
| 222 | """ |
---|
| 223 | grok.context(IApplicantsContainer) |
---|
[6319] | 224 | |
---|
[6153] | 225 | class ApplicantBreadcrumb(Breadcrumb): |
---|
| 226 | """A breadcrumb for applicants. |
---|
| 227 | """ |
---|
| 228 | grok.context(IApplicant) |
---|
[6319] | 229 | |
---|
[6153] | 230 | @property |
---|
| 231 | def title(self): |
---|
| 232 | """Get a title for a context. |
---|
| 233 | """ |
---|
| 234 | return self.context.access_code |
---|
[5828] | 235 | |
---|
[7184] | 236 | class ApplicantsAuthTab(PrimaryNavTab): |
---|
[6153] | 237 | """Applicants tab in primary navigation. |
---|
[5828] | 238 | """ |
---|
| 239 | grok.context(IWAeUPObject) |
---|
| 240 | grok.order(3) |
---|
[7184] | 241 | grok.require('waeup.viewApplication') |
---|
[5828] | 242 | grok.template('primarynavtab') |
---|
[5843] | 243 | pnav = 3 |
---|
[5828] | 244 | tab_title = u'Applicants' |
---|
| 245 | |
---|
| 246 | @property |
---|
| 247 | def link_target(self): |
---|
| 248 | return self.view.application_url('applicants') |
---|
| 249 | |
---|
[7184] | 250 | class ApplicantsAnonTab(ApplicantsAuthTab): |
---|
| 251 | """Applicants tab in primary navigation. |
---|
| 252 | |
---|
| 253 | Display tab only for anonymous. Authenticated users can call the |
---|
| 254 | form from the user navigation bar. |
---|
| 255 | """ |
---|
| 256 | grok.require('waeup.Anonymous') |
---|
| 257 | tab_title = u'Application' |
---|
| 258 | |
---|
| 259 | # Also zope.manager has role Anonymous. |
---|
| 260 | # To avoid displaying this tab, uncomment the following. |
---|
| 261 | #def tab_title(self): |
---|
| 262 | # userid = self.request.principal.id |
---|
| 263 | # if userid != 'zope.anybody': |
---|
| 264 | # tt = u'' |
---|
| 265 | # else: |
---|
| 266 | # tt = u'Application' |
---|
| 267 | # return tt |
---|
| 268 | |
---|
[6029] | 269 | class ApplicantsContainerPage(WAeUPDisplayFormPage): |
---|
[5830] | 270 | """The standard view for regular applicant containers. |
---|
| 271 | """ |
---|
| 272 | grok.context(IApplicantsContainer) |
---|
| 273 | grok.name('index') |
---|
[6153] | 274 | grok.require('waeup.Public') |
---|
[6029] | 275 | grok.template('applicantscontainerpage') |
---|
[5850] | 276 | pnav = 3 |
---|
[6053] | 277 | |
---|
[6105] | 278 | form_fields = grok.AutoFields(IApplicantsContainer).omit('title') |
---|
[6054] | 279 | form_fields['startdate'].custom_widget = FriendlyDateDisplayWidget('le') |
---|
| 280 | form_fields['enddate'].custom_widget = FriendlyDateDisplayWidget('le') |
---|
[6084] | 281 | form_fields['description'].custom_widget = ReSTDisplayWidget |
---|
[6053] | 282 | |
---|
[5837] | 283 | @property |
---|
| 284 | def title(self): |
---|
[6087] | 285 | return "Applicants Container: %s" % self.context.title |
---|
[5837] | 286 | |
---|
| 287 | @property |
---|
| 288 | def label(self): |
---|
[6087] | 289 | return self.context.title |
---|
[5830] | 290 | |
---|
[6107] | 291 | class ApplicantsContainerManageActionButton(ManageActionButton): |
---|
[6336] | 292 | grok.order(1) |
---|
[5832] | 293 | grok.context(IApplicantsContainer) |
---|
| 294 | grok.view(ApplicantsContainerPage) |
---|
[7136] | 295 | grok.require('waeup.manageApplication') |
---|
[6070] | 296 | text = 'Manage applicants container' |
---|
[5832] | 297 | |
---|
[6336] | 298 | class LoginApplicantActionButton(ManageActionButton): |
---|
| 299 | grok.order(2) |
---|
| 300 | grok.context(IApplicantsContainer) |
---|
| 301 | grok.view(ApplicantsContainerPage) |
---|
| 302 | grok.require('waeup.Anonymous') |
---|
| 303 | icon = 'login.png' |
---|
| 304 | text = 'Login for applicants' |
---|
| 305 | target = 'login' |
---|
[5832] | 306 | |
---|
[6107] | 307 | class ApplicantsContainerManageFormPage(WAeUPEditFormPage): |
---|
[5837] | 308 | grok.context(IApplicantsContainer) |
---|
[5850] | 309 | grok.name('manage') |
---|
[6107] | 310 | grok.template('applicantscontainermanagepage') |
---|
[6105] | 311 | form_fields = grok.AutoFields(IApplicantsContainer).omit('title') |
---|
| 312 | taboneactions = ['Save','Cancel'] |
---|
| 313 | tabtwoactions = ['Add applicant', 'Remove selected','Cancel'] |
---|
[6184] | 314 | tabthreeactions1 = ['Remove selected local roles'] |
---|
| 315 | tabthreeactions2 = ['Add local role'] |
---|
[5844] | 316 | # Use friendlier date widget... |
---|
[6054] | 317 | form_fields['startdate'].custom_widget = FriendlyDateWidget('le') |
---|
| 318 | form_fields['enddate'].custom_widget = FriendlyDateWidget('le') |
---|
[7136] | 319 | grok.require('waeup.manageApplication') |
---|
[5850] | 320 | |
---|
| 321 | @property |
---|
| 322 | def title(self): |
---|
[6087] | 323 | return "Applicants Container: %s" % self.context.title |
---|
[6078] | 324 | |
---|
[5850] | 325 | @property |
---|
| 326 | def label(self): |
---|
[6087] | 327 | return 'Manage applicants container' |
---|
[5850] | 328 | |
---|
[5845] | 329 | pnav = 3 |
---|
[5837] | 330 | |
---|
| 331 | def update(self): |
---|
[5850] | 332 | datepicker.need() # Enable jQuery datepicker in date fields. |
---|
[5982] | 333 | tabs.need() |
---|
[6015] | 334 | datatable.need() # Enable jQurey datatables for contents listing |
---|
[6107] | 335 | return super(ApplicantsContainerManageFormPage, self).update() |
---|
[5837] | 336 | |
---|
[6184] | 337 | def getLocalRoles(self): |
---|
| 338 | roles = ILocalRolesAssignable(self.context) |
---|
| 339 | return roles() |
---|
| 340 | |
---|
| 341 | def getUsers(self): |
---|
| 342 | """Get a list of all users. |
---|
| 343 | """ |
---|
| 344 | for key, val in grok.getSite()['users'].items(): |
---|
| 345 | url = self.url(val) |
---|
| 346 | yield(dict(url=url, name=key, val=val)) |
---|
| 347 | |
---|
| 348 | def getUsersWithLocalRoles(self): |
---|
| 349 | return get_users_with_local_roles(self.context) |
---|
| 350 | |
---|
[5850] | 351 | @grok.action('Save') |
---|
[5837] | 352 | def apply(self, **data): |
---|
| 353 | self.applyData(self.context, **data) |
---|
| 354 | self.flash('Data saved.') |
---|
| 355 | return |
---|
[6078] | 356 | |
---|
[6105] | 357 | # ToDo: Show warning message before deletion |
---|
| 358 | @grok.action('Remove selected') |
---|
| 359 | def delApplicant(self, **data): |
---|
[6189] | 360 | form = self.request.form |
---|
| 361 | if form.has_key('val_id'): |
---|
| 362 | child_id = form['val_id'] |
---|
| 363 | else: |
---|
| 364 | self.flash('No applicant selected!') |
---|
| 365 | self.redirect(self.url(self.context, '@@manage')+'#tab-2') |
---|
| 366 | return |
---|
| 367 | if not isinstance(child_id, list): |
---|
| 368 | child_id = [child_id] |
---|
| 369 | deleted = [] |
---|
| 370 | for id in child_id: |
---|
| 371 | try: |
---|
| 372 | del self.context[id] |
---|
| 373 | deleted.append(id) |
---|
| 374 | except: |
---|
| 375 | self.flash('Could not delete %s: %s: %s' % ( |
---|
| 376 | id, sys.exc_info()[0], sys.exc_info()[1])) |
---|
| 377 | if len(deleted): |
---|
| 378 | self.flash('Successfully removed: %s' % ', '.join(deleted)) |
---|
| 379 | self.redirect(self.url(self.context, u'@@manage')+'#tab-2') |
---|
| 380 | return |
---|
[6105] | 381 | |
---|
| 382 | @grok.action('Add applicant', validator=NullValidator) |
---|
| 383 | def addApplicant(self, **data): |
---|
[6327] | 384 | self.redirect(self.url(self.context, 'addapplicant')) |
---|
| 385 | return |
---|
[6105] | 386 | |
---|
| 387 | @grok.action('Cancel', validator=NullValidator) |
---|
[5837] | 388 | def cancel(self, **data): |
---|
| 389 | self.redirect(self.url(self.context)) |
---|
| 390 | return |
---|
[5886] | 391 | |
---|
[6184] | 392 | @grok.action('Add local role', validator=NullValidator) |
---|
| 393 | def addLocalRole(self, **data): |
---|
| 394 | return add_local_role(self,3, **data) |
---|
[6105] | 395 | |
---|
[6184] | 396 | @grok.action('Remove selected local roles') |
---|
| 397 | def delLocalRoles(self, **data): |
---|
| 398 | return del_local_roles(self,3,**data) |
---|
| 399 | |
---|
[5886] | 400 | class LoginApplicant(WAeUPPage): |
---|
| 401 | grok.context(IApplicantsContainer) |
---|
| 402 | grok.name('login') |
---|
[6153] | 403 | grok.require('waeup.Public') |
---|
[5886] | 404 | |
---|
[6110] | 405 | @property |
---|
| 406 | def title(self): |
---|
| 407 | return u"Applicant Login: %s" % self.context.title |
---|
[6078] | 408 | |
---|
[5886] | 409 | @property |
---|
| 410 | def label(self): |
---|
[6724] | 411 | return u"Login for '%s' applicants only" % self.context.title |
---|
[5886] | 412 | |
---|
| 413 | pnav = 3 |
---|
[6319] | 414 | |
---|
[6110] | 415 | @property |
---|
| 416 | def ac_prefix(self): |
---|
| 417 | return self.context.ac_prefix |
---|
[6078] | 418 | |
---|
[5896] | 419 | def update(self, SUBMIT=None): |
---|
| 420 | self.ac_series = self.request.form.get('form.ac_series', None) |
---|
| 421 | self.ac_number = self.request.form.get('form.ac_number', None) |
---|
[5886] | 422 | if SUBMIT is None: |
---|
| 423 | return |
---|
[5894] | 424 | if self.request.principal.id == 'zope.anybody': |
---|
[6105] | 425 | self.flash('Entered credentials are invalid.') |
---|
[5886] | 426 | return |
---|
[5894] | 427 | if not IApplicantPrincipal.providedBy(self.request.principal): |
---|
| 428 | # Don't care if user is already authenticated as non-applicant |
---|
| 429 | return |
---|
[6377] | 430 | |
---|
| 431 | # From here we handle an applicant (not an officer browsing) |
---|
[5905] | 432 | pin = self.request.principal.access_code |
---|
[6375] | 433 | |
---|
[6816] | 434 | # If application has not yet started, |
---|
| 435 | # logout without marking AC as used |
---|
| 436 | if self.context.startdate > date.today(): |
---|
| 437 | self.flash('Application has not yet started.') |
---|
| 438 | auth = getUtility(IAuthentication) |
---|
| 439 | ILogout(auth).logout(self.request) |
---|
| 440 | self.redirect(self.url(self.context, 'login')) |
---|
| 441 | return |
---|
| 442 | |
---|
| 443 | # If application has ended and applicant record doesn't exist, |
---|
| 444 | # logout without marking AC as used |
---|
[7063] | 445 | if not pin in self.context.keys() and ( |
---|
| 446 | self.context.enddate < date.today()): |
---|
[6816] | 447 | self.flash('Application has ended.') |
---|
| 448 | auth = getUtility(IAuthentication) |
---|
| 449 | ILogout(auth).logout(self.request) |
---|
| 450 | self.redirect(self.url(self.context, 'login')) |
---|
| 451 | return |
---|
| 452 | |
---|
| 453 | # Mark AC as used (this also fires a pin related transition) |
---|
[7063] | 454 | if get_access_code(pin).state != USED: |
---|
[6471] | 455 | comment = u"AC invalidated" |
---|
[6469] | 456 | # Here we know that the ac is in state initialized so we do not |
---|
| 457 | # expect an exception |
---|
[6471] | 458 | invalidate_accesscode(pin,comment) |
---|
[6375] | 459 | |
---|
[6377] | 460 | if not pin in self.context.keys(): |
---|
| 461 | # Create applicant record |
---|
| 462 | applicant = Applicant() |
---|
| 463 | applicant.access_code = pin |
---|
| 464 | self.context[pin] = applicant |
---|
[6359] | 465 | |
---|
[6377] | 466 | role_manager = IPrincipalRoleManager(self.context[pin]) |
---|
[6394] | 467 | role_manager.assignRoleToPrincipal( |
---|
| 468 | 'waeup.local.ApplicationOwner', self.request.principal.id) |
---|
[6359] | 469 | |
---|
[7166] | 470 | # Assign current principal the global Applicant role |
---|
[6397] | 471 | role_manager = IPrincipalRoleManager(grok.getSite()) |
---|
[6394] | 472 | role_manager.assignRoleToPrincipal( |
---|
[7166] | 473 | 'waeup.Applicant', self.request.principal.id) |
---|
[6377] | 474 | |
---|
| 475 | # Mark application as started |
---|
| 476 | if IWorkflowState(self.context[pin]).getState() is INITIALIZED: |
---|
| 477 | IWorkflowInfo(self.context[pin]).fireTransition('start') |
---|
| 478 | |
---|
[5937] | 479 | self.redirect(self.url(self.context[pin], 'edit')) |
---|
[5886] | 480 | return |
---|
[6319] | 481 | |
---|
[6327] | 482 | class ApplicantAddFormPage(WAeUPAddFormPage): |
---|
[6622] | 483 | """Add-form to add an applicant. |
---|
[6327] | 484 | """ |
---|
| 485 | grok.context(IApplicantsContainer) |
---|
[7136] | 486 | grok.require('waeup.manageApplication') |
---|
[6327] | 487 | grok.name('addapplicant') |
---|
| 488 | grok.template('applicantaddpage') |
---|
| 489 | title = 'Applicants' |
---|
| 490 | label = 'Add applicant' |
---|
| 491 | pnav = 3 |
---|
| 492 | |
---|
| 493 | @property |
---|
| 494 | def title(self): |
---|
| 495 | return "Applicants Container: %s" % self.context.title |
---|
| 496 | |
---|
| 497 | @property |
---|
| 498 | def ac_prefix(self): |
---|
| 499 | return self.context.ac_prefix |
---|
| 500 | |
---|
| 501 | @grok.action('Create application record') |
---|
| 502 | def addApplicant(self, **data): |
---|
| 503 | ac_series = self.request.form.get('form.ac_series', None) |
---|
| 504 | ac_number = self.request.form.get('form.ac_number', None) |
---|
| 505 | pin = '%s-%s-%s' % (self.ac_prefix,ac_series,ac_number) |
---|
[6459] | 506 | if not invalidate_accesscode(pin, comment=u"Invalidated by system"): |
---|
[6383] | 507 | self.flash('%s is not a valid access code.' % pin) |
---|
| 508 | self.redirect(self.url(self.context, '@@manage')+'#tab-2') |
---|
| 509 | return |
---|
| 510 | else: |
---|
[6327] | 511 | # Create applicant record |
---|
| 512 | applicant = Applicant() |
---|
| 513 | applicant.access_code = pin |
---|
| 514 | self.context[pin] = applicant |
---|
| 515 | self.redirect(self.url(self.context[pin], 'edit')) |
---|
| 516 | return |
---|
| 517 | |
---|
[6396] | 518 | class AccessCodeViewLink(LeftSidebarLink): |
---|
[6153] | 519 | grok.order(1) |
---|
| 520 | grok.require('waeup.Public') |
---|
[6396] | 521 | icon = 'actionicon_view.png' |
---|
| 522 | title = 'View Record' |
---|
| 523 | target = '/@@index' |
---|
[5886] | 524 | |
---|
[6396] | 525 | @property |
---|
| 526 | def url(self): |
---|
[6153] | 527 | if not IApplicantPrincipal.providedBy(self.request.principal): |
---|
| 528 | return '' |
---|
| 529 | access_code = getattr(self.request.principal,'access_code',None) |
---|
| 530 | if access_code: |
---|
| 531 | applicant_object = get_applicant_data(access_code) |
---|
[6396] | 532 | return absoluteURL(applicant_object, self.request) + self.target |
---|
[7063] | 533 | return '' |
---|
[6153] | 534 | |
---|
[6396] | 535 | class AccessCodeEditLink(AccessCodeViewLink): |
---|
| 536 | grok.order(2) |
---|
| 537 | grok.require('waeup.Public') |
---|
| 538 | icon = 'actionicon_modify.png' |
---|
| 539 | title = 'Edit Record' |
---|
| 540 | target = '/@@edit' |
---|
| 541 | |
---|
| 542 | @property |
---|
| 543 | def url(self): |
---|
| 544 | if not IApplicantPrincipal.providedBy(self.request.principal): |
---|
| 545 | return '' |
---|
| 546 | access_code = getattr(self.request.principal,'access_code',None) |
---|
| 547 | if access_code: |
---|
| 548 | applicant_object = get_applicant_data(access_code) |
---|
| 549 | if applicant_object.locked: |
---|
| 550 | return '' |
---|
| 551 | return absoluteURL(applicant_object, self.request) + self.target |
---|
[7063] | 552 | return '' |
---|
[6396] | 553 | |
---|
| 554 | class AccessCodeSlipLink(AccessCodeViewLink): |
---|
| 555 | grok.order(3) |
---|
| 556 | grok.require('waeup.Public') |
---|
| 557 | icon = 'actionicon_pdf.png' |
---|
| 558 | title = 'Download Slip' |
---|
| 559 | target = '/application_slip.pdf' |
---|
| 560 | |
---|
[5273] | 561 | class DisplayApplicant(WAeUPDisplayFormPage): |
---|
| 562 | grok.context(IApplicant) |
---|
| 563 | grok.name('index') |
---|
[7113] | 564 | grok.require('waeup.viewApplication') |
---|
[6320] | 565 | form_fields = grok.AutoFields(IApplicant).omit( |
---|
| 566 | 'locked').omit('course_admitted') |
---|
[6054] | 567 | form_fields['date_of_birth'].custom_widget = FriendlyDateDisplayWidget('le') |
---|
[5273] | 568 | label = 'Applicant' |
---|
[6254] | 569 | grok.template('form_display') |
---|
[5843] | 570 | pnav = 3 |
---|
[5273] | 571 | |
---|
[7063] | 572 | def update(self): |
---|
| 573 | self.passport_url = self.url(self.context, 'passport.jpg') |
---|
| 574 | return |
---|
| 575 | |
---|
[6196] | 576 | @property |
---|
| 577 | def title(self): |
---|
[6465] | 578 | if self.request.principal.title == 'Applicant': |
---|
| 579 | return u'Your Application Record' |
---|
[6196] | 580 | return '%s' % self.context.access_code |
---|
| 581 | |
---|
| 582 | @property |
---|
| 583 | def label(self): |
---|
| 584 | container_title = self.context.__parent__.title |
---|
| 585 | return '%s Application Record' % container_title |
---|
| 586 | |
---|
[6254] | 587 | def getCourseAdmitted(self): |
---|
[6355] | 588 | """Return link, title and code in html format to the certificate |
---|
| 589 | admitted. |
---|
[6351] | 590 | """ |
---|
[6254] | 591 | course_admitted = self.context.course_admitted |
---|
| 592 | if ICertificate.providedBy(course_admitted): |
---|
| 593 | url = self.url(course_admitted) |
---|
| 594 | title = course_admitted.title |
---|
| 595 | code = course_admitted.code |
---|
[6366] | 596 | return '<a href="%s">%s - %s</a>' %(url,code,title) |
---|
[6457] | 597 | return '' |
---|
[6254] | 598 | |
---|
[6358] | 599 | class PDFActionButton(ManageActionButton): |
---|
| 600 | grok.context(IApplicant) |
---|
[7136] | 601 | grok.require('waeup.viewApplication') |
---|
[6358] | 602 | icon = 'actionicon_pdf.png' |
---|
[6367] | 603 | text = 'Download application slip' |
---|
[6358] | 604 | target = 'application_slip.pdf' |
---|
| 605 | |
---|
| 606 | class ExportPDFPage(grok.View): |
---|
| 607 | """Deliver a PDF slip of the context. |
---|
| 608 | """ |
---|
| 609 | grok.context(IApplicant) |
---|
| 610 | grok.name('application_slip.pdf') |
---|
[7136] | 611 | grok.require('waeup.viewApplication') |
---|
[6358] | 612 | form_fields = grok.AutoFields(IApplicant).omit( |
---|
| 613 | 'locked').omit('course_admitted') |
---|
| 614 | form_fields['date_of_birth'].custom_widget = FriendlyDateDisplayWidget('le') |
---|
| 615 | prefix = 'form' |
---|
| 616 | |
---|
[6363] | 617 | @property |
---|
| 618 | def label(self): |
---|
| 619 | container_title = self.context.__parent__.title |
---|
| 620 | return '%s Application Record' % container_title |
---|
| 621 | |
---|
[6358] | 622 | def getCourseAdmitted(self): |
---|
| 623 | """Return title and code in html format to the certificate |
---|
| 624 | admitted. |
---|
| 625 | """ |
---|
| 626 | course_admitted = self.context.course_admitted |
---|
| 627 | if ICertificate.providedBy(course_admitted): |
---|
| 628 | title = course_admitted.title |
---|
| 629 | code = course_admitted.code |
---|
[6365] | 630 | return '%s - %s' %(code,title) |
---|
[6462] | 631 | return '' |
---|
[6358] | 632 | |
---|
| 633 | def setUpWidgets(self, ignore_request=False): |
---|
| 634 | self.adapters = {} |
---|
| 635 | self.widgets = setUpEditWidgets( |
---|
| 636 | self.form_fields, self.prefix, self.context, self.request, |
---|
| 637 | adapters=self.adapters, for_display=True, |
---|
| 638 | ignore_request=ignore_request |
---|
| 639 | ) |
---|
| 640 | |
---|
| 641 | def render(self): |
---|
[6364] | 642 | SLIP_STYLE = TableStyle( |
---|
| 643 | [('VALIGN',(0,0),(-1,-1),'TOP')] |
---|
| 644 | ) |
---|
[6358] | 645 | |
---|
| 646 | pdf = canvas.Canvas('application_slip.pdf',pagesize=A4) |
---|
[6364] | 647 | pdf.setTitle(self.label) |
---|
| 648 | pdf.setSubject('Application') |
---|
| 649 | pdf.setAuthor('%s (%s)' % (self.request.principal.title, |
---|
| 650 | self.request.principal.id)) |
---|
| 651 | pdf.setCreator('WAeUP SIRP') |
---|
[6358] | 652 | width, height = A4 |
---|
| 653 | style = getSampleStyleSheet() |
---|
[6365] | 654 | pdf.line(1*cm,height-(1.8*cm),width-(1*cm),height-(1.8*cm)) |
---|
[6363] | 655 | |
---|
[6358] | 656 | story = [] |
---|
[6365] | 657 | frame_header = Frame(1*cm,1*cm,width-(1.7*cm),height-(1.7*cm)) |
---|
[6363] | 658 | header_title = getattr(grok.getSite(), 'name', u'Sample University') |
---|
| 659 | story.append(Paragraph(header_title, style["Heading1"])) |
---|
| 660 | frame_header.addFromList(story,pdf) |
---|
| 661 | |
---|
| 662 | story = [] |
---|
[6365] | 663 | frame_body = Frame(1*cm,1*cm,width-(2*cm),height-(3.5*cm)) |
---|
[6364] | 664 | story.append(Paragraph(self.label, style["Heading2"])) |
---|
| 665 | story.append(Spacer(1, 18)) |
---|
| 666 | for msg in self.context.history.messages: |
---|
| 667 | f_msg = '<font face="Courier" size=10>%s</font>' % msg |
---|
| 668 | story.append(Paragraph(f_msg, style["Normal"])) |
---|
[6363] | 669 | story.append(Spacer(1, 24)) |
---|
[7063] | 670 | |
---|
[7068] | 671 | |
---|
[7063] | 672 | # insert passport photograph |
---|
| 673 | img = getUtility(IExtFileStore).getFileByContext(self.context) |
---|
| 674 | if img is None: |
---|
[7089] | 675 | img = open(DEFAULT_PASSPORT_IMAGE_PATH, 'rb') |
---|
[7063] | 676 | doc_img = Image(img.name, width=4*cm, height=3*cm, kind='bound') |
---|
[7068] | 677 | story.append(doc_img) |
---|
| 678 | story.append(Spacer(1, 18)) |
---|
[7063] | 679 | |
---|
| 680 | # render widget fields |
---|
[7068] | 681 | data = [] |
---|
[6358] | 682 | self.setUpWidgets() |
---|
| 683 | for widget in self.widgets: |
---|
[6462] | 684 | f_label = '<font size=12>%s</font>:' % widget.label.strip() |
---|
[6363] | 685 | f_label = Paragraph(f_label, style["Normal"]) |
---|
[7063] | 686 | f_text = '<font size=12>%s</font>' % widget() |
---|
| 687 | f_text = Paragraph(f_text, style["Normal"]) |
---|
| 688 | data.append([f_label,f_text]) |
---|
[6462] | 689 | f_label = '<font size=12>Admitted Course of Study:</font>' |
---|
[6363] | 690 | f_text = '<font size=12>%s</font>' % self.getCourseAdmitted() |
---|
| 691 | f_label = Paragraph(f_label, style["Normal"]) |
---|
| 692 | f_text = Paragraph(f_text, style["Normal"]) |
---|
| 693 | data.append([f_label,f_text]) |
---|
[6364] | 694 | table = Table(data,style=SLIP_STYLE) |
---|
[6363] | 695 | story.append(table) |
---|
| 696 | frame_body.addFromList(story,pdf) |
---|
| 697 | |
---|
[6364] | 698 | story = [] |
---|
[6365] | 699 | frame_footer = Frame(1*cm,0,width-(2*cm),1*cm) |
---|
[6364] | 700 | timestamp = datetime.now().strftime("%d/%m/%Y %H:%M:%S") |
---|
| 701 | f_text = '<font size=10>%s</font>' % timestamp |
---|
| 702 | story.append(Paragraph(f_text, style["Normal"])) |
---|
| 703 | frame_footer.addFromList(story,pdf) |
---|
| 704 | |
---|
[6358] | 705 | self.response.setHeader( |
---|
| 706 | 'Content-Type', 'application/pdf') |
---|
| 707 | return pdf.getpdfdata() |
---|
| 708 | |
---|
[6383] | 709 | class ApplicantManageActionButton(ManageActionButton): |
---|
[6198] | 710 | grok.context(IApplicant) |
---|
| 711 | grok.view(DisplayApplicant) |
---|
[7136] | 712 | grok.require('waeup.manageApplication') |
---|
[6383] | 713 | text = 'Manage application record' |
---|
[6198] | 714 | target = 'edit_full' |
---|
| 715 | |
---|
[7081] | 716 | |
---|
| 717 | def handle_img_upload(upload, context, view): |
---|
[7063] | 718 | """Handle upload of applicant image. |
---|
[7081] | 719 | |
---|
| 720 | Returns `True` in case of success or `False`. |
---|
| 721 | |
---|
| 722 | Please note that file pointer passed in (`upload`) most probably |
---|
| 723 | points to end of file when leaving this function. |
---|
[7063] | 724 | """ |
---|
[7081] | 725 | size = file_size(upload) |
---|
| 726 | if size > MAX_UPLOAD_SIZE: |
---|
| 727 | view.flash('Uploaded image is too big!') |
---|
| 728 | return False |
---|
| 729 | upload.seek(0) # file pointer moved when determining size |
---|
[7063] | 730 | store = getUtility(IExtFileStore) |
---|
| 731 | file_id = IFileStoreNameChooser(context).chooseName() |
---|
| 732 | store.createFile(file_id, upload) |
---|
[7081] | 733 | return True |
---|
[7063] | 734 | |
---|
[6196] | 735 | class EditApplicantFull(WAeUPEditFormPage): |
---|
| 736 | """A full edit view for applicant data. |
---|
| 737 | """ |
---|
| 738 | grok.context(IApplicant) |
---|
| 739 | grok.name('edit_full') |
---|
[7136] | 740 | grok.require('waeup.manageApplication') |
---|
[6476] | 741 | form_fields = grok.AutoFields(IApplicant) |
---|
[6196] | 742 | form_fields['date_of_birth'].custom_widget = FriendlyDateWidget('le-year') |
---|
| 743 | grok.template('form_edit') |
---|
[6322] | 744 | manage_applications = True |
---|
[6196] | 745 | pnav = 3 |
---|
| 746 | |
---|
| 747 | def update(self): |
---|
| 748 | datepicker.need() # Enable jQuery datepicker in date fields. |
---|
| 749 | super(EditApplicantFull, self).update() |
---|
[6353] | 750 | self.wf_info = IWorkflowInfo(self.context) |
---|
[7081] | 751 | self.max_upload_size = string_from_bytes(MAX_UPLOAD_SIZE) |
---|
[7084] | 752 | self.passport_changed = None |
---|
[6598] | 753 | upload = self.request.form.get('form.passport', None) |
---|
| 754 | if upload: |
---|
| 755 | # We got a fresh upload |
---|
[7084] | 756 | self.passport_changed = handle_img_upload( |
---|
| 757 | upload, self.context, self) |
---|
[6196] | 758 | return |
---|
| 759 | |
---|
| 760 | @property |
---|
| 761 | def title(self): |
---|
| 762 | return self.context.access_code |
---|
| 763 | |
---|
| 764 | @property |
---|
| 765 | def label(self): |
---|
| 766 | container_title = self.context.__parent__.title |
---|
| 767 | return '%s Application Form' % container_title |
---|
| 768 | |
---|
[6303] | 769 | def getTransitions(self): |
---|
[6351] | 770 | """Return a list of dicts of allowed transition ids and titles. |
---|
[6353] | 771 | |
---|
| 772 | Each list entry provides keys ``name`` and ``title`` for |
---|
| 773 | internal name and (human readable) title of a single |
---|
| 774 | transition. |
---|
[6349] | 775 | """ |
---|
[6353] | 776 | allowed_transitions = self.wf_info.getManualTransitions() |
---|
[6355] | 777 | return [dict(name='', title='No transition')] +[ |
---|
| 778 | dict(name=x, title=y) for x, y in allowed_transitions] |
---|
[6303] | 779 | |
---|
[6196] | 780 | @grok.action('Save') |
---|
| 781 | def save(self, **data): |
---|
[7084] | 782 | if self.passport_changed is False: # False is not None! |
---|
| 783 | return # error during image upload. Ignore other values |
---|
[6475] | 784 | changed_fields = self.applyData(self.context, **data) |
---|
| 785 | changed_fields = changed_fields.values() |
---|
[7063] | 786 | fields_string = '+'.join( |
---|
| 787 | ' + '.join(str(i) for i in b) for b in changed_fields) |
---|
[7084] | 788 | if self.passport_changed: |
---|
| 789 | fields_string += ' + passport' |
---|
[7094] | 790 | #self.context._p_changed = True |
---|
[6303] | 791 | form = self.request.form |
---|
[7085] | 792 | trans_id = form.get('transition', None) |
---|
| 793 | if trans_id: |
---|
| 794 | self.wf_info.fireTransition(trans_id) |
---|
[6196] | 795 | self.flash('Form has been saved.') |
---|
[6475] | 796 | ob_class = self.__implemented__.__name__.replace('waeup.sirp.','') |
---|
[6644] | 797 | if fields_string: |
---|
| 798 | self.context.loggerInfo(ob_class, 'saved: % s' % fields_string) |
---|
[6196] | 799 | return |
---|
| 800 | |
---|
| 801 | class EditApplicantStudent(EditApplicantFull): |
---|
[5982] | 802 | """An applicant-centered edit view for applicant data. |
---|
| 803 | """ |
---|
[6196] | 804 | grok.context(IApplicantEdit) |
---|
[5273] | 805 | grok.name('edit') |
---|
[6198] | 806 | grok.require('waeup.handleApplication') |
---|
[6459] | 807 | form_fields = grok.AutoFields(IApplicantEdit).omit( |
---|
[6476] | 808 | 'locked', 'course_admitted', 'student_id', |
---|
[6459] | 809 | 'screening_score', |
---|
| 810 | ) |
---|
[6054] | 811 | form_fields['date_of_birth'].custom_widget = FriendlyDateWidget('le-year') |
---|
[6196] | 812 | grok.template('form_edit') |
---|
[6322] | 813 | manage_applications = False |
---|
[6465] | 814 | title = u'Your Application Form' |
---|
[5484] | 815 | |
---|
[7145] | 816 | def emit_lock_message(self): |
---|
[6105] | 817 | self.flash('The requested form is locked (read-only).') |
---|
[5941] | 818 | self.redirect(self.url(self.context)) |
---|
| 819 | return |
---|
[6078] | 820 | |
---|
[5686] | 821 | def update(self): |
---|
[5941] | 822 | if self.context.locked: |
---|
[7145] | 823 | self.emit_lock_message() |
---|
[5941] | 824 | return |
---|
[6040] | 825 | datepicker.need() # Enable jQuery datepicker in date fields. |
---|
[5982] | 826 | super(EditApplicantStudent, self).update() |
---|
[5686] | 827 | return |
---|
[5952] | 828 | |
---|
[6196] | 829 | def dataNotComplete(self): |
---|
[6322] | 830 | if not self.request.form.get('confirm_passport', False): |
---|
[6196] | 831 | return 'Passport confirmation box not ticked.' |
---|
| 832 | return False |
---|
[5952] | 833 | |
---|
[5273] | 834 | @grok.action('Save') |
---|
| 835 | def save(self, **data): |
---|
[7084] | 836 | if self.passport_changed is False: # False is not None! |
---|
| 837 | return # error during image upload. Ignore other values |
---|
[5273] | 838 | self.applyData(self.context, **data) |
---|
[7094] | 839 | #self.context._p_changed = True |
---|
[6196] | 840 | self.flash('Form has been saved.') |
---|
[5273] | 841 | return |
---|
| 842 | |
---|
[5484] | 843 | @grok.action('Final Submit') |
---|
| 844 | def finalsubmit(self, **data): |
---|
[7084] | 845 | if self.passport_changed is False: # False is not None! |
---|
| 846 | return # error during image upload. Ignore other values |
---|
[5273] | 847 | self.applyData(self.context, **data) |
---|
[5484] | 848 | self.context._p_changed = True |
---|
[6196] | 849 | if self.dataNotComplete(): |
---|
| 850 | self.flash(self.dataNotComplete()) |
---|
[5941] | 851 | return |
---|
[6303] | 852 | state = IWorkflowState(self.context).getState() |
---|
[6322] | 853 | # This shouldn't happen, but the application officer |
---|
| 854 | # might have forgotten to lock the form after changing the state |
---|
[6303] | 855 | if state != STARTED: |
---|
[6322] | 856 | self.flash('This form cannot be submitted. Wrong state!') |
---|
[6303] | 857 | return |
---|
| 858 | IWorkflowInfo(self.context).fireTransition('submit') |
---|
[6476] | 859 | self.context.application_date = datetime.now() |
---|
[5941] | 860 | self.context.locked = True |
---|
[6196] | 861 | self.flash('Form has been submitted.') |
---|
| 862 | self.redirect(self.url(self.context)) |
---|
[5273] | 863 | return |
---|
[5941] | 864 | |
---|
[6367] | 865 | class ApplicantViewActionButton(ManageActionButton): |
---|
| 866 | grok.context(IApplicant) |
---|
[6383] | 867 | grok.view(EditApplicantFull) |
---|
[7136] | 868 | grok.require('waeup.manageApplication') |
---|
[6383] | 869 | icon = 'actionicon_view.png' |
---|
[6367] | 870 | text = 'View application record' |
---|
[6598] | 871 | target = 'index' |
---|
[7063] | 872 | |
---|
| 873 | class PassportImage(grok.View): |
---|
| 874 | """Renders the passport image for applicants. |
---|
| 875 | """ |
---|
| 876 | grok.name('passport.jpg') |
---|
| 877 | grok.context(IApplicant) |
---|
[7113] | 878 | grok.require('waeup.viewApplication') |
---|
[7063] | 879 | |
---|
| 880 | def render(self): |
---|
| 881 | # A filename chooser turns a context into a filename suitable |
---|
| 882 | # for file storage. |
---|
| 883 | image = getUtility(IExtFileStore).getFileByContext(self.context) |
---|
| 884 | self.response.setHeader( |
---|
| 885 | 'Content-Type', 'image/jpeg') |
---|
| 886 | if image is None: |
---|
| 887 | # show placeholder image |
---|
[7089] | 888 | return open(DEFAULT_PASSPORT_IMAGE_PATH, 'rb').read() |
---|
[7063] | 889 | return image |
---|