[5273] | 1 | ## $Id: browser.py 13886 2016-06-07 20:08:05Z henrik $ |
---|
[6078] | 2 | ## |
---|
[7192] | 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
[5273] | 4 | ## This program is free software; you can redistribute it and/or modify |
---|
| 5 | ## it under the terms of the GNU General Public License as published by |
---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | ## (at your option) any later version. |
---|
[6078] | 8 | ## |
---|
[5273] | 9 | ## This program is distributed in the hope that it will be useful, |
---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | ## GNU General Public License for more details. |
---|
[6078] | 13 | ## |
---|
[5273] | 14 | ## You should have received a copy of the GNU General Public License |
---|
| 15 | ## along with this program; if not, write to the Free Software |
---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | ## |
---|
[5824] | 18 | """UI components for basic applicants and related components. |
---|
[5273] | 19 | """ |
---|
[7063] | 20 | import os |
---|
[6082] | 21 | import sys |
---|
[5273] | 22 | import grok |
---|
[7370] | 23 | from datetime import datetime, date |
---|
[8042] | 24 | from zope.event import notify |
---|
[13152] | 25 | from zope.component import getUtility, queryUtility, createObject, getAdapter |
---|
[8033] | 26 | from zope.catalog.interfaces import ICatalog |
---|
[7714] | 27 | from zope.i18n import translate |
---|
[7322] | 28 | from hurry.workflow.interfaces import ( |
---|
| 29 | IWorkflowInfo, IWorkflowState, InvalidTransitionError) |
---|
[7811] | 30 | from waeup.kofa.applicants.interfaces import ( |
---|
[7363] | 31 | IApplicant, IApplicantEdit, IApplicantsRoot, |
---|
[7683] | 32 | IApplicantsContainer, IApplicantsContainerAdd, |
---|
[8033] | 33 | MAX_UPLOAD_SIZE, IApplicantOnlinePayment, IApplicantsUtils, |
---|
[10845] | 34 | IApplicantRegisterUpdate, ISpecialApplicant |
---|
[7363] | 35 | ) |
---|
[12247] | 36 | from waeup.kofa.utils.helpers import html2dict |
---|
[10655] | 37 | from waeup.kofa.applicants.container import ( |
---|
| 38 | ApplicantsContainer, VirtualApplicantsExportJobContainer) |
---|
[8404] | 39 | from waeup.kofa.applicants.applicant import search |
---|
[8636] | 40 | from waeup.kofa.applicants.workflow import ( |
---|
[13254] | 41 | INITIALIZED, STARTED, PAID, SUBMITTED, ADMITTED, NOT_ADMITTED, CREATED) |
---|
[7811] | 42 | from waeup.kofa.browser import ( |
---|
[9217] | 43 | # KofaPage, KofaEditFormPage, KofaAddFormPage, KofaDisplayFormPage, |
---|
[7363] | 44 | DEFAULT_PASSPORT_IMAGE_PATH) |
---|
[9217] | 45 | from waeup.kofa.browser.layout import ( |
---|
| 46 | KofaPage, KofaEditFormPage, KofaAddFormPage, KofaDisplayFormPage) |
---|
[7811] | 47 | from waeup.kofa.browser.interfaces import ICaptchaManager |
---|
| 48 | from waeup.kofa.browser.breadcrumbs import Breadcrumb |
---|
| 49 | from waeup.kofa.browser.layout import ( |
---|
[11437] | 50 | NullValidator, jsaction, action, UtilityView) |
---|
[10655] | 51 | from waeup.kofa.browser.pages import ( |
---|
| 52 | add_local_role, del_local_roles, doll_up, ExportCSVView) |
---|
[7811] | 53 | from waeup.kofa.interfaces import ( |
---|
[13177] | 54 | IKofaObject, ILocalRolesAssignable, IExtFileStore, IPDF, DOCLINK, |
---|
[7819] | 55 | IFileStoreNameChooser, IPasswordValidator, IUserAccount, IKofaUtils) |
---|
[7811] | 56 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
| 57 | from waeup.kofa.permissions import get_users_with_local_roles |
---|
| 58 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
[8186] | 59 | from waeup.kofa.utils.helpers import string_from_bytes, file_size, now |
---|
[8170] | 60 | from waeup.kofa.widgets.datewidget import ( |
---|
[10831] | 61 | FriendlyDateDisplayWidget, |
---|
[8170] | 62 | FriendlyDatetimeDisplayWidget) |
---|
[5320] | 63 | |
---|
[7819] | 64 | grok.context(IKofaObject) # Make IKofaObject the default context |
---|
[5273] | 65 | |
---|
[11437] | 66 | WARNING = _('You can not edit your application records after final submission.' |
---|
| 67 | ' You really want to submit?') |
---|
[8550] | 68 | |
---|
[8388] | 69 | class ApplicantsRootPage(KofaDisplayFormPage): |
---|
[5822] | 70 | grok.context(IApplicantsRoot) |
---|
| 71 | grok.name('index') |
---|
[6153] | 72 | grok.require('waeup.Public') |
---|
[8388] | 73 | form_fields = grok.AutoFields(IApplicantsRoot) |
---|
[13076] | 74 | label = _('Applicants Section') |
---|
[5843] | 75 | pnav = 3 |
---|
[6012] | 76 | |
---|
| 77 | def update(self): |
---|
[6067] | 78 | super(ApplicantsRootPage, self).update() |
---|
[6012] | 79 | return |
---|
| 80 | |
---|
[8388] | 81 | @property |
---|
| 82 | def introduction(self): |
---|
| 83 | # Here we know that the cookie has been set |
---|
| 84 | lang = self.request.cookies.get('kofa.language') |
---|
| 85 | html = self.context.description_dict.get(lang,'') |
---|
| 86 | if html == '': |
---|
| 87 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 88 | html = self.context.description_dict.get(portal_language,'') |
---|
| 89 | return html |
---|
| 90 | |
---|
[10097] | 91 | @property |
---|
| 92 | def containers(self): |
---|
[10098] | 93 | if self.layout.isAuthenticated(): |
---|
[13249] | 94 | return self.context.values() |
---|
[13217] | 95 | values = sorted([container for container in self.context.values() |
---|
[13249] | 96 | if not container.hidden and container.enddate], |
---|
[13222] | 97 | key=lambda value: value.enddate, reverse=True) |
---|
[13217] | 98 | return values |
---|
[10097] | 99 | |
---|
[8404] | 100 | class ApplicantsSearchPage(KofaPage): |
---|
| 101 | grok.context(IApplicantsRoot) |
---|
| 102 | grok.name('search') |
---|
| 103 | grok.require('waeup.viewApplication') |
---|
[10644] | 104 | label = _('Find applicants') |
---|
[10645] | 105 | search_button = _('Find applicant') |
---|
[8404] | 106 | pnav = 3 |
---|
| 107 | |
---|
| 108 | def update(self, *args, **kw): |
---|
| 109 | form = self.request.form |
---|
| 110 | self.results = [] |
---|
| 111 | if 'searchterm' in form and form['searchterm']: |
---|
| 112 | self.searchterm = form['searchterm'] |
---|
| 113 | self.searchtype = form['searchtype'] |
---|
| 114 | elif 'old_searchterm' in form: |
---|
| 115 | self.searchterm = form['old_searchterm'] |
---|
| 116 | self.searchtype = form['old_searchtype'] |
---|
| 117 | else: |
---|
| 118 | if 'search' in form: |
---|
[11254] | 119 | self.flash(_('Empty search string'), type='warning') |
---|
[8404] | 120 | return |
---|
| 121 | self.results = search(query=self.searchterm, |
---|
| 122 | searchtype=self.searchtype, view=self) |
---|
| 123 | if not self.results: |
---|
[11254] | 124 | self.flash(_('No applicant found.'), type='warning') |
---|
[8404] | 125 | return |
---|
| 126 | |
---|
[7819] | 127 | class ApplicantsRootManageFormPage(KofaEditFormPage): |
---|
[5828] | 128 | grok.context(IApplicantsRoot) |
---|
| 129 | grok.name('manage') |
---|
[6107] | 130 | grok.template('applicantsrootmanagepage') |
---|
[8388] | 131 | form_fields = grok.AutoFields(IApplicantsRoot) |
---|
[13076] | 132 | label = _('Manage applicants section') |
---|
[5843] | 133 | pnav = 3 |
---|
[7136] | 134 | grok.require('waeup.manageApplication') |
---|
[8388] | 135 | taboneactions = [_('Save')] |
---|
| 136 | tabtwoactions = [_('Add applicants container'), _('Remove selected')] |
---|
| 137 | tabthreeactions1 = [_('Remove selected local roles')] |
---|
| 138 | tabthreeactions2 = [_('Add local role')] |
---|
[7710] | 139 | subunits = _('Applicants Containers') |
---|
[13177] | 140 | doclink = DOCLINK + '/applicants.html' |
---|
[6078] | 141 | |
---|
[6184] | 142 | def getLocalRoles(self): |
---|
| 143 | roles = ILocalRolesAssignable(self.context) |
---|
| 144 | return roles() |
---|
| 145 | |
---|
| 146 | def getUsers(self): |
---|
| 147 | """Get a list of all users. |
---|
| 148 | """ |
---|
| 149 | for key, val in grok.getSite()['users'].items(): |
---|
| 150 | url = self.url(val) |
---|
| 151 | yield(dict(url=url, name=key, val=val)) |
---|
| 152 | |
---|
| 153 | def getUsersWithLocalRoles(self): |
---|
| 154 | return get_users_with_local_roles(self.context) |
---|
| 155 | |
---|
[7710] | 156 | @jsaction(_('Remove selected')) |
---|
[6069] | 157 | def delApplicantsContainers(self, **data): |
---|
| 158 | form = self.request.form |
---|
[9701] | 159 | if 'val_id' in form: |
---|
[8388] | 160 | child_id = form['val_id'] |
---|
| 161 | else: |
---|
[11254] | 162 | self.flash(_('No container selected!'), type='warning') |
---|
| 163 | self.redirect(self.url(self.context, '@@manage')+'#tab2') |
---|
[8388] | 164 | return |
---|
[6069] | 165 | if not isinstance(child_id, list): |
---|
| 166 | child_id = [child_id] |
---|
| 167 | deleted = [] |
---|
| 168 | for id in child_id: |
---|
| 169 | try: |
---|
| 170 | del self.context[id] |
---|
| 171 | deleted.append(id) |
---|
| 172 | except: |
---|
[7710] | 173 | self.flash(_('Could not delete:') + ' %s: %s: %s' % ( |
---|
[11254] | 174 | id, sys.exc_info()[0], sys.exc_info()[1]), type='danger') |
---|
[6069] | 175 | if len(deleted): |
---|
[7738] | 176 | self.flash(_('Successfully removed: ${a}', |
---|
| 177 | mapping = {'a':', '.join(deleted)})) |
---|
[12892] | 178 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
---|
| 179 | self.context.logger.info( |
---|
| 180 | '%s - removed: %s' % (ob_class, ', '.join(deleted))) |
---|
[11254] | 181 | self.redirect(self.url(self.context, '@@manage')+'#tab2') |
---|
[6078] | 182 | return |
---|
[5828] | 183 | |
---|
[7710] | 184 | @action(_('Add applicants container'), validator=NullValidator) |
---|
[6069] | 185 | def addApplicantsContainer(self, **data): |
---|
| 186 | self.redirect(self.url(self.context, '@@add')) |
---|
[6078] | 187 | return |
---|
| 188 | |
---|
[7710] | 189 | @action(_('Add local role'), validator=NullValidator) |
---|
[6184] | 190 | def addLocalRole(self, **data): |
---|
[7484] | 191 | return add_local_role(self,3, **data) |
---|
[6184] | 192 | |
---|
[7710] | 193 | @action(_('Remove selected local roles')) |
---|
[6184] | 194 | def delLocalRoles(self, **data): |
---|
[7484] | 195 | return del_local_roles(self,3,**data) |
---|
[6184] | 196 | |
---|
[8388] | 197 | @action(_('Save'), style='primary') |
---|
| 198 | def save(self, **data): |
---|
| 199 | self.applyData(self.context, **data) |
---|
[12247] | 200 | description = getattr(self.context, 'description', None) |
---|
| 201 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 202 | self.context.description_dict = html2dict(description, portal_language) |
---|
[8390] | 203 | self.flash(_('Form has been saved.')) |
---|
[8388] | 204 | return |
---|
| 205 | |
---|
[7819] | 206 | class ApplicantsContainerAddFormPage(KofaAddFormPage): |
---|
[5822] | 207 | grok.context(IApplicantsRoot) |
---|
[7136] | 208 | grok.require('waeup.manageApplication') |
---|
[5822] | 209 | grok.name('add') |
---|
[6107] | 210 | grok.template('applicantscontaineraddpage') |
---|
[7710] | 211 | label = _('Add applicants container') |
---|
[5843] | 212 | pnav = 3 |
---|
[6078] | 213 | |
---|
[6103] | 214 | form_fields = grok.AutoFields( |
---|
[7903] | 215 | IApplicantsContainerAdd).omit('code').omit('title') |
---|
[6078] | 216 | |
---|
[7710] | 217 | @action(_('Add applicants container')) |
---|
[6069] | 218 | def addApplicantsContainer(self, **data): |
---|
[6103] | 219 | year = data['year'] |
---|
| 220 | code = u'%s%s' % (data['prefix'], year) |
---|
[9529] | 221 | apptypes_dict = getUtility(IApplicantsUtils).APP_TYPES_DICT |
---|
| 222 | title = apptypes_dict[data['prefix']][0] |
---|
[7685] | 223 | title = u'%s %s/%s' % (title, year, year + 1) |
---|
[6087] | 224 | if code in self.context.keys(): |
---|
[6105] | 225 | self.flash( |
---|
[11254] | 226 | _('An applicants container for the same application ' |
---|
| 227 | 'type and entrance year exists already in the database.'), |
---|
| 228 | type='warning') |
---|
[5822] | 229 | return |
---|
| 230 | # Add new applicants container... |
---|
[8009] | 231 | container = createObject(u'waeup.ApplicantsContainer') |
---|
[6069] | 232 | self.applyData(container, **data) |
---|
[6087] | 233 | container.code = code |
---|
| 234 | container.title = title |
---|
| 235 | self.context[code] = container |
---|
[7710] | 236 | self.flash(_('Added:') + ' "%s".' % code) |
---|
[12892] | 237 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
---|
| 238 | self.context.logger.info('%s - added: %s' % (ob_class, code)) |
---|
[7484] | 239 | self.redirect(self.url(self.context, u'@@manage')) |
---|
[5822] | 240 | return |
---|
[6078] | 241 | |
---|
[7710] | 242 | @action(_('Cancel'), validator=NullValidator) |
---|
[6069] | 243 | def cancel(self, **data): |
---|
[7484] | 244 | self.redirect(self.url(self.context, '@@manage')) |
---|
[6078] | 245 | |
---|
[5845] | 246 | class ApplicantsRootBreadcrumb(Breadcrumb): |
---|
| 247 | """A breadcrumb for applicantsroot. |
---|
| 248 | """ |
---|
| 249 | grok.context(IApplicantsRoot) |
---|
[7710] | 250 | title = _(u'Applicants') |
---|
[6078] | 251 | |
---|
[5845] | 252 | class ApplicantsContainerBreadcrumb(Breadcrumb): |
---|
| 253 | """A breadcrumb for applicantscontainers. |
---|
| 254 | """ |
---|
| 255 | grok.context(IApplicantsContainer) |
---|
[6319] | 256 | |
---|
[10655] | 257 | |
---|
| 258 | class ApplicantsExportsBreadcrumb(Breadcrumb): |
---|
| 259 | """A breadcrumb for exports. |
---|
| 260 | """ |
---|
| 261 | grok.context(VirtualApplicantsExportJobContainer) |
---|
| 262 | title = _(u'Applicant Data Exports') |
---|
| 263 | target = None |
---|
| 264 | |
---|
[6153] | 265 | class ApplicantBreadcrumb(Breadcrumb): |
---|
| 266 | """A breadcrumb for applicants. |
---|
| 267 | """ |
---|
| 268 | grok.context(IApplicant) |
---|
[6319] | 269 | |
---|
[6153] | 270 | @property |
---|
| 271 | def title(self): |
---|
| 272 | """Get a title for a context. |
---|
| 273 | """ |
---|
[7240] | 274 | return self.context.application_number |
---|
[5828] | 275 | |
---|
[7250] | 276 | class OnlinePaymentBreadcrumb(Breadcrumb): |
---|
| 277 | """A breadcrumb for payments. |
---|
| 278 | """ |
---|
| 279 | grok.context(IApplicantOnlinePayment) |
---|
| 280 | |
---|
| 281 | @property |
---|
| 282 | def title(self): |
---|
| 283 | return self.context.p_id |
---|
| 284 | |
---|
[8563] | 285 | class ApplicantsStatisticsPage(KofaDisplayFormPage): |
---|
| 286 | """Some statistics about applicants in a container. |
---|
| 287 | """ |
---|
| 288 | grok.context(IApplicantsContainer) |
---|
| 289 | grok.name('statistics') |
---|
[8565] | 290 | grok.require('waeup.viewApplicationStatistics') |
---|
[8563] | 291 | grok.template('applicantcontainerstatistics') |
---|
| 292 | |
---|
| 293 | @property |
---|
| 294 | def label(self): |
---|
| 295 | return "%s" % self.context.title |
---|
| 296 | |
---|
[7819] | 297 | class ApplicantsContainerPage(KofaDisplayFormPage): |
---|
[5830] | 298 | """The standard view for regular applicant containers. |
---|
| 299 | """ |
---|
| 300 | grok.context(IApplicantsContainer) |
---|
| 301 | grok.name('index') |
---|
[6153] | 302 | grok.require('waeup.Public') |
---|
[6029] | 303 | grok.template('applicantscontainerpage') |
---|
[5850] | 304 | pnav = 3 |
---|
[6053] | 305 | |
---|
[9078] | 306 | @property |
---|
| 307 | def form_fields(self): |
---|
[12247] | 308 | form_fields = grok.AutoFields(IApplicantsContainer).omit( |
---|
| 309 | 'title', 'description') |
---|
[9078] | 310 | form_fields[ |
---|
| 311 | 'startdate'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 312 | form_fields[ |
---|
| 313 | 'enddate'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 314 | if self.request.principal.id == 'zope.anybody': |
---|
| 315 | form_fields = form_fields.omit( |
---|
[10101] | 316 | 'code', 'prefix', 'year', 'mode', 'hidden', |
---|
[11870] | 317 | 'strict_deadline', 'application_category', |
---|
| 318 | 'application_slip_notice') |
---|
[9078] | 319 | return form_fields |
---|
[6053] | 320 | |
---|
[5837] | 321 | @property |
---|
[7708] | 322 | def introduction(self): |
---|
[7833] | 323 | # Here we know that the cookie has been set |
---|
| 324 | lang = self.request.cookies.get('kofa.language') |
---|
[7708] | 325 | html = self.context.description_dict.get(lang,'') |
---|
[8388] | 326 | if html == '': |
---|
[7833] | 327 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7708] | 328 | html = self.context.description_dict.get(portal_language,'') |
---|
[8388] | 329 | return html |
---|
[7708] | 330 | |
---|
| 331 | @property |
---|
[7467] | 332 | def label(self): |
---|
[7493] | 333 | return "%s" % self.context.title |
---|
[5837] | 334 | |
---|
[7819] | 335 | class ApplicantsContainerManageFormPage(KofaEditFormPage): |
---|
[5837] | 336 | grok.context(IApplicantsContainer) |
---|
[5850] | 337 | grok.name('manage') |
---|
[6107] | 338 | grok.template('applicantscontainermanagepage') |
---|
[10625] | 339 | form_fields = grok.AutoFields(IApplicantsContainer) |
---|
[7710] | 340 | taboneactions = [_('Save'),_('Cancel')] |
---|
[8684] | 341 | tabtwoactions = [_('Remove selected'),_('Cancel'), |
---|
[8314] | 342 | _('Create students from selected')] |
---|
[7710] | 343 | tabthreeactions1 = [_('Remove selected local roles')] |
---|
| 344 | tabthreeactions2 = [_('Add local role')] |
---|
[5844] | 345 | # Use friendlier date widget... |
---|
[7136] | 346 | grok.require('waeup.manageApplication') |
---|
[13177] | 347 | doclink = DOCLINK + '/applicants.html' |
---|
[5850] | 348 | |
---|
| 349 | @property |
---|
| 350 | def label(self): |
---|
[7710] | 351 | return _('Manage applicants container') |
---|
[5850] | 352 | |
---|
[5845] | 353 | pnav = 3 |
---|
[5837] | 354 | |
---|
[8547] | 355 | @property |
---|
| 356 | def showApplicants(self): |
---|
[13217] | 357 | if self.context.counts[1] < 1000: |
---|
[8547] | 358 | return True |
---|
| 359 | return False |
---|
| 360 | |
---|
[6184] | 361 | def getLocalRoles(self): |
---|
| 362 | roles = ILocalRolesAssignable(self.context) |
---|
| 363 | return roles() |
---|
| 364 | |
---|
| 365 | def getUsers(self): |
---|
| 366 | """Get a list of all users. |
---|
| 367 | """ |
---|
| 368 | for key, val in grok.getSite()['users'].items(): |
---|
| 369 | url = self.url(val) |
---|
| 370 | yield(dict(url=url, name=key, val=val)) |
---|
| 371 | |
---|
| 372 | def getUsersWithLocalRoles(self): |
---|
| 373 | return get_users_with_local_roles(self.context) |
---|
| 374 | |
---|
[7714] | 375 | @action(_('Save'), style='primary') |
---|
[7489] | 376 | def save(self, **data): |
---|
[9531] | 377 | changed_fields = self.applyData(self.context, **data) |
---|
| 378 | if changed_fields: |
---|
| 379 | changed_fields = reduce(lambda x,y: x+y, changed_fields.values()) |
---|
| 380 | else: |
---|
| 381 | changed_fields = [] |
---|
[12247] | 382 | description = getattr(self.context, 'description', None) |
---|
| 383 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 384 | self.context.description_dict = html2dict(description, portal_language) |
---|
[7710] | 385 | self.flash(_('Form has been saved.')) |
---|
[9531] | 386 | fields_string = ' + '.join(changed_fields) |
---|
[12892] | 387 | self.context.writeLogMessage(self, 'saved: %s' % fields_string) |
---|
[5837] | 388 | return |
---|
[6078] | 389 | |
---|
[7710] | 390 | @jsaction(_('Remove selected')) |
---|
[6105] | 391 | def delApplicant(self, **data): |
---|
[6189] | 392 | form = self.request.form |
---|
[9701] | 393 | if 'val_id' in form: |
---|
[6189] | 394 | child_id = form['val_id'] |
---|
| 395 | else: |
---|
[11254] | 396 | self.flash(_('No applicant selected!'), type='warning') |
---|
| 397 | self.redirect(self.url(self.context, '@@manage')+'#tab2') |
---|
[6189] | 398 | return |
---|
| 399 | if not isinstance(child_id, list): |
---|
| 400 | child_id = [child_id] |
---|
| 401 | deleted = [] |
---|
| 402 | for id in child_id: |
---|
| 403 | try: |
---|
| 404 | del self.context[id] |
---|
| 405 | deleted.append(id) |
---|
| 406 | except: |
---|
[7710] | 407 | self.flash(_('Could not delete:') + ' %s: %s: %s' % ( |
---|
[11254] | 408 | id, sys.exc_info()[0], sys.exc_info()[1]), type='danger') |
---|
[6189] | 409 | if len(deleted): |
---|
[7741] | 410 | self.flash(_('Successfully removed: ${a}', |
---|
[7738] | 411 | mapping = {'a':', '.join(deleted)})) |
---|
[11254] | 412 | self.redirect(self.url(self.context, u'@@manage')+'#tab2') |
---|
[6189] | 413 | return |
---|
[6105] | 414 | |
---|
[8314] | 415 | @action(_('Create students from selected')) |
---|
| 416 | def createStudents(self, **data): |
---|
| 417 | form = self.request.form |
---|
[9701] | 418 | if 'val_id' in form: |
---|
[8314] | 419 | child_id = form['val_id'] |
---|
| 420 | else: |
---|
[11254] | 421 | self.flash(_('No applicant selected!'), type='warning') |
---|
| 422 | self.redirect(self.url(self.context, '@@manage')+'#tab2') |
---|
[8314] | 423 | return |
---|
| 424 | if not isinstance(child_id, list): |
---|
| 425 | child_id = [child_id] |
---|
| 426 | created = [] |
---|
| 427 | for id in child_id: |
---|
| 428 | success, msg = self.context[id].createStudent(view=self) |
---|
| 429 | if success: |
---|
| 430 | created.append(id) |
---|
| 431 | if len(created): |
---|
| 432 | self.flash(_('${a} students successfully created.', |
---|
| 433 | mapping = {'a': len(created)})) |
---|
| 434 | else: |
---|
[11254] | 435 | self.flash(_('No student could be created.'), type='warning') |
---|
| 436 | self.redirect(self.url(self.context, u'@@manage')+'#tab2') |
---|
[8314] | 437 | return |
---|
| 438 | |
---|
[7710] | 439 | @action(_('Cancel'), validator=NullValidator) |
---|
[5837] | 440 | def cancel(self, **data): |
---|
| 441 | self.redirect(self.url(self.context)) |
---|
| 442 | return |
---|
[5886] | 443 | |
---|
[7710] | 444 | @action(_('Add local role'), validator=NullValidator) |
---|
[6184] | 445 | def addLocalRole(self, **data): |
---|
| 446 | return add_local_role(self,3, **data) |
---|
[6105] | 447 | |
---|
[7710] | 448 | @action(_('Remove selected local roles')) |
---|
[6184] | 449 | def delLocalRoles(self, **data): |
---|
| 450 | return del_local_roles(self,3,**data) |
---|
| 451 | |
---|
[7819] | 452 | class ApplicantAddFormPage(KofaAddFormPage): |
---|
[6622] | 453 | """Add-form to add an applicant. |
---|
[6327] | 454 | """ |
---|
| 455 | grok.context(IApplicantsContainer) |
---|
[7136] | 456 | grok.require('waeup.manageApplication') |
---|
[6327] | 457 | grok.name('addapplicant') |
---|
[7240] | 458 | #grok.template('applicantaddpage') |
---|
| 459 | form_fields = grok.AutoFields(IApplicant).select( |
---|
[7356] | 460 | 'firstname', 'middlename', 'lastname', |
---|
[7240] | 461 | 'email', 'phone') |
---|
[7714] | 462 | label = _('Add applicant') |
---|
[6327] | 463 | pnav = 3 |
---|
[13177] | 464 | doclink = DOCLINK + '/applicants.html' |
---|
[6327] | 465 | |
---|
[7714] | 466 | @action(_('Create application record')) |
---|
[6327] | 467 | def addApplicant(self, **data): |
---|
[8008] | 468 | applicant = createObject(u'waeup.Applicant') |
---|
[7240] | 469 | self.applyData(applicant, **data) |
---|
| 470 | self.context.addApplicant(applicant) |
---|
[13073] | 471 | self.flash(_('Application record created.')) |
---|
[7363] | 472 | self.redirect( |
---|
| 473 | self.url(self.context[applicant.application_number], 'index')) |
---|
[6327] | 474 | return |
---|
| 475 | |
---|
[13217] | 476 | class ApplicantsContainerPrefillFormPage(KofaAddFormPage): |
---|
[13218] | 477 | """Form to pre-fill applicants containers. |
---|
[13217] | 478 | """ |
---|
| 479 | grok.context(IApplicantsContainer) |
---|
| 480 | grok.require('waeup.manageApplication') |
---|
| 481 | grok.name('prefill') |
---|
[13218] | 482 | grok.template('prefillcontainer') |
---|
[13217] | 483 | label = _('Pre-fill container') |
---|
| 484 | pnav = 3 |
---|
[13232] | 485 | doclink = DOCLINK + '/applicants/browser.html#preparation-and-maintenance-of-applicants-containers' |
---|
[13217] | 486 | |
---|
| 487 | def update(self): |
---|
| 488 | if self.context.mode == 'update': |
---|
| 489 | self.flash(_('Container must be in create mode to be pre-filled.'), |
---|
| 490 | type='danger') |
---|
| 491 | self.redirect(self.url(self.context)) |
---|
| 492 | return |
---|
| 493 | super(ApplicantsContainerPrefillFormPage, self).update() |
---|
| 494 | return |
---|
| 495 | |
---|
| 496 | @action(_('Pre-fill now'), style='primary') |
---|
[13218] | 497 | def addApplicants(self): |
---|
[13217] | 498 | form = self.request.form |
---|
| 499 | if 'number' in form and form['number']: |
---|
| 500 | number = int(form['number']) |
---|
| 501 | for i in range(number): |
---|
| 502 | applicant = createObject(u'waeup.Applicant') |
---|
| 503 | self.context.addApplicant(applicant) |
---|
| 504 | self.flash(_('%s application records created.' % number)) |
---|
| 505 | self.context.writeLogMessage(self, '%s applicants created' % (number)) |
---|
| 506 | self.redirect(self.url(self.context, 'index')) |
---|
| 507 | return |
---|
| 508 | |
---|
| 509 | @action(_('Cancel'), validator=NullValidator) |
---|
| 510 | def cancel(self, **data): |
---|
| 511 | self.redirect(self.url(self.context)) |
---|
| 512 | return |
---|
| 513 | |
---|
[13218] | 514 | class ApplicantsContainerPurgeFormPage(KofaEditFormPage): |
---|
| 515 | """Form to pre-fill applicants containers. |
---|
| 516 | """ |
---|
| 517 | grok.context(IApplicantsContainer) |
---|
| 518 | grok.require('waeup.manageApplication') |
---|
| 519 | grok.name('purge') |
---|
| 520 | grok.template('purgecontainer') |
---|
| 521 | label = _('Purge container') |
---|
| 522 | pnav = 3 |
---|
[13232] | 523 | doclink = DOCLINK + '/applicants/browser.html#preparation-and-maintenance-of-applicants-containers' |
---|
[13218] | 524 | |
---|
[13232] | 525 | @action(_('Remove initialized records'), |
---|
| 526 | tooltip=_('Don\'t use if application is in progress!'), |
---|
| 527 | warning=_('Are you really sure?'), |
---|
| 528 | style='primary') |
---|
[13218] | 529 | def purgeInitialized(self): |
---|
| 530 | form = self.request.form |
---|
| 531 | purged = 0 |
---|
| 532 | keys = [key for key in self.context.keys()] |
---|
| 533 | for key in keys: |
---|
| 534 | if self.context[key].state == 'initialized': |
---|
| 535 | del self.context[key] |
---|
| 536 | purged += 1 |
---|
| 537 | self.flash(_('%s application records purged.' % purged)) |
---|
| 538 | self.context.writeLogMessage(self, '%s applicants purged' % (purged)) |
---|
| 539 | self.redirect(self.url(self.context, 'index')) |
---|
| 540 | return |
---|
| 541 | |
---|
| 542 | @action(_('Cancel'), validator=NullValidator) |
---|
| 543 | def cancel(self, **data): |
---|
| 544 | self.redirect(self.url(self.context)) |
---|
| 545 | return |
---|
| 546 | |
---|
[7819] | 547 | class ApplicantDisplayFormPage(KofaDisplayFormPage): |
---|
[8014] | 548 | """A display view for applicant data. |
---|
| 549 | """ |
---|
[5273] | 550 | grok.context(IApplicant) |
---|
| 551 | grok.name('index') |
---|
[7113] | 552 | grok.require('waeup.viewApplication') |
---|
[7200] | 553 | grok.template('applicantdisplaypage') |
---|
[7714] | 554 | label = _('Applicant') |
---|
[5843] | 555 | pnav = 3 |
---|
[8922] | 556 | hide_hint = False |
---|
[5273] | 557 | |
---|
[8046] | 558 | @property |
---|
[13886] | 559 | def display_payments(self): |
---|
| 560 | if self.context.special: |
---|
| 561 | return True |
---|
| 562 | return getattr(self.context.__parent__, 'application_fee', None) |
---|
| 563 | |
---|
| 564 | @property |
---|
[10831] | 565 | def form_fields(self): |
---|
| 566 | if self.context.special: |
---|
[11599] | 567 | form_fields = grok.AutoFields(ISpecialApplicant).omit('locked') |
---|
[10831] | 568 | else: |
---|
| 569 | form_fields = grok.AutoFields(IApplicant).omit( |
---|
[10845] | 570 | 'locked', 'course_admitted', 'password', 'suspended') |
---|
[10831] | 571 | return form_fields |
---|
| 572 | |
---|
| 573 | @property |
---|
[10534] | 574 | def target(self): |
---|
| 575 | return getattr(self.context.__parent__, 'prefix', None) |
---|
| 576 | |
---|
| 577 | @property |
---|
[8046] | 578 | def separators(self): |
---|
| 579 | return getUtility(IApplicantsUtils).SEPARATORS_DICT |
---|
| 580 | |
---|
[7063] | 581 | def update(self): |
---|
| 582 | self.passport_url = self.url(self.context, 'passport.jpg') |
---|
[7240] | 583 | # Mark application as started if applicant logs in for the first time |
---|
[7272] | 584 | usertype = getattr(self.request.principal, 'user_type', None) |
---|
| 585 | if usertype == 'applicant' and \ |
---|
| 586 | IWorkflowState(self.context).getState() == INITIALIZED: |
---|
[7240] | 587 | IWorkflowInfo(self.context).fireTransition('start') |
---|
[10895] | 588 | if usertype == 'applicant' and self.context.state == 'created': |
---|
[10908] | 589 | session = '%s/%s' % (self.context.__parent__.year, |
---|
| 590 | self.context.__parent__.year+1) |
---|
| 591 | title = getattr(grok.getSite()['configuration'], 'name', u'Sample University') |
---|
[10895] | 592 | msg = _( |
---|
| 593 | '\n <strong>Congratulations!</strong>' + |
---|
[10933] | 594 | ' You have been offered provisional admission into the' + |
---|
[10908] | 595 | ' ${c} Academic Session of ${d}.' |
---|
| 596 | ' Your student record has been created for you.' + |
---|
| 597 | ' Please, logout again and proceed to the' + |
---|
| 598 | ' login page of the portal.' |
---|
[10895] | 599 | ' Then enter your new student credentials:' + |
---|
| 600 | ' user name= ${a}, password = ${b}.' + |
---|
| 601 | ' Change your password when you have logged in.', |
---|
| 602 | mapping = { |
---|
| 603 | 'a':self.context.student_id, |
---|
[10908] | 604 | 'b':self.context.application_number, |
---|
| 605 | 'c':session, |
---|
| 606 | 'd':title} |
---|
[10895] | 607 | ) |
---|
| 608 | self.flash(msg) |
---|
[7063] | 609 | return |
---|
| 610 | |
---|
[6196] | 611 | @property |
---|
[7240] | 612 | def hasPassword(self): |
---|
| 613 | if self.context.password: |
---|
[7714] | 614 | return _('set') |
---|
| 615 | return _('unset') |
---|
[7240] | 616 | |
---|
| 617 | @property |
---|
[6196] | 618 | def label(self): |
---|
| 619 | container_title = self.context.__parent__.title |
---|
[8096] | 620 | return _('${a} <br /> Application Record ${b}', mapping = { |
---|
[7714] | 621 | 'a':container_title, 'b':self.context.application_number}) |
---|
[6196] | 622 | |
---|
[7347] | 623 | def getCourseAdmitted(self): |
---|
| 624 | """Return link, title and code in html format to the certificate |
---|
| 625 | admitted. |
---|
| 626 | """ |
---|
| 627 | course_admitted = self.context.course_admitted |
---|
[7351] | 628 | if getattr(course_admitted, '__parent__',None): |
---|
[7347] | 629 | url = self.url(course_admitted) |
---|
| 630 | title = course_admitted.title |
---|
| 631 | code = course_admitted.code |
---|
| 632 | return '<a href="%s">%s - %s</a>' %(url,code,title) |
---|
| 633 | return '' |
---|
[6254] | 634 | |
---|
[7259] | 635 | class ApplicantBaseDisplayFormPage(ApplicantDisplayFormPage): |
---|
| 636 | grok.context(IApplicant) |
---|
| 637 | grok.name('base') |
---|
| 638 | form_fields = grok.AutoFields(IApplicant).select( |
---|
[9141] | 639 | 'applicant_id','email', 'course1') |
---|
[7259] | 640 | |
---|
[7459] | 641 | class CreateStudentPage(UtilityView, grok.View): |
---|
[8636] | 642 | """Create a student object from applicant data. |
---|
[7341] | 643 | """ |
---|
| 644 | grok.context(IApplicant) |
---|
| 645 | grok.name('createstudent') |
---|
| 646 | grok.require('waeup.manageStudent') |
---|
| 647 | |
---|
| 648 | def update(self): |
---|
[8314] | 649 | msg = self.context.createStudent(view=self)[1] |
---|
[11254] | 650 | self.flash(msg, type='warning') |
---|
[7341] | 651 | self.redirect(self.url(self.context)) |
---|
| 652 | return |
---|
| 653 | |
---|
| 654 | def render(self): |
---|
| 655 | return |
---|
| 656 | |
---|
[8636] | 657 | class CreateAllStudentsPage(UtilityView, grok.View): |
---|
| 658 | """Create all student objects from applicant data |
---|
[11874] | 659 | in the root container or in a specific applicants container only. |
---|
[11826] | 660 | Only PortalManagers can do this. |
---|
[8636] | 661 | """ |
---|
[9900] | 662 | #grok.context(IApplicantsContainer) |
---|
[8636] | 663 | grok.name('createallstudents') |
---|
| 664 | grok.require('waeup.managePortal') |
---|
| 665 | |
---|
| 666 | def update(self): |
---|
| 667 | cat = getUtility(ICatalog, name='applicants_catalog') |
---|
| 668 | results = list(cat.searchResults(state=(ADMITTED, ADMITTED))) |
---|
| 669 | created = [] |
---|
[9900] | 670 | container_only = False |
---|
| 671 | applicants_root = grok.getSite()['applicants'] |
---|
| 672 | if isinstance(self.context, ApplicantsContainer): |
---|
| 673 | container_only = True |
---|
[8636] | 674 | for result in results: |
---|
[9900] | 675 | if container_only and result.__parent__ is not self.context: |
---|
[8636] | 676 | continue |
---|
| 677 | success, msg = result.createStudent(view=self) |
---|
| 678 | if success: |
---|
| 679 | created.append(result.applicant_id) |
---|
| 680 | else: |
---|
[12893] | 681 | ob_class = self.__implemented__.__name__.replace( |
---|
| 682 | 'waeup.kofa.','') |
---|
[9900] | 683 | applicants_root.logger.info( |
---|
[8742] | 684 | '%s - %s - %s' % (ob_class, result.applicant_id, msg)) |
---|
[8636] | 685 | if len(created): |
---|
| 686 | self.flash(_('${a} students successfully created.', |
---|
| 687 | mapping = {'a': len(created)})) |
---|
| 688 | else: |
---|
[11254] | 689 | self.flash(_('No student could be created.'), type='warning') |
---|
[9900] | 690 | self.redirect(self.url(self.context)) |
---|
[8636] | 691 | return |
---|
| 692 | |
---|
| 693 | def render(self): |
---|
| 694 | return |
---|
| 695 | |
---|
[8260] | 696 | class ApplicationFeePaymentAddPage(UtilityView, grok.View): |
---|
[7250] | 697 | """ Page to add an online payment ticket |
---|
| 698 | """ |
---|
| 699 | grok.context(IApplicant) |
---|
| 700 | grok.name('addafp') |
---|
| 701 | grok.require('waeup.payApplicant') |
---|
[8243] | 702 | factory = u'waeup.ApplicantOnlinePayment' |
---|
[7250] | 703 | |
---|
[11726] | 704 | @property |
---|
| 705 | def custom_requirements(self): |
---|
| 706 | return '' |
---|
| 707 | |
---|
[7250] | 708 | def update(self): |
---|
[11726] | 709 | # Additional requirements in custom packages. |
---|
| 710 | if self.custom_requirements: |
---|
| 711 | self.flash( |
---|
| 712 | self.custom_requirements, |
---|
| 713 | type='danger') |
---|
| 714 | self.redirect(self.url(self.context)) |
---|
[11727] | 715 | return |
---|
[11575] | 716 | if not self.context.special: |
---|
| 717 | for key in self.context.keys(): |
---|
| 718 | ticket = self.context[key] |
---|
| 719 | if ticket.p_state == 'paid': |
---|
| 720 | self.flash( |
---|
| 721 | _('This type of payment has already been made.'), |
---|
| 722 | type='warning') |
---|
| 723 | self.redirect(self.url(self.context)) |
---|
| 724 | return |
---|
[8524] | 725 | applicants_utils = getUtility(IApplicantsUtils) |
---|
| 726 | container = self.context.__parent__ |
---|
[8243] | 727 | payment = createObject(self.factory) |
---|
[11254] | 728 | failure = applicants_utils.setPaymentDetails( |
---|
[10831] | 729 | container, payment, self.context) |
---|
[11254] | 730 | if failure is not None: |
---|
[13123] | 731 | self.flash(failure, type='danger') |
---|
[8524] | 732 | self.redirect(self.url(self.context)) |
---|
| 733 | return |
---|
[7250] | 734 | self.context[payment.p_id] = payment |
---|
[12893] | 735 | self.context.writeLogMessage(self, 'added: %s' % payment.p_id) |
---|
[7714] | 736 | self.flash(_('Payment ticket created.')) |
---|
[8280] | 737 | self.redirect(self.url(payment)) |
---|
[7250] | 738 | return |
---|
| 739 | |
---|
| 740 | def render(self): |
---|
| 741 | return |
---|
| 742 | |
---|
| 743 | |
---|
[7819] | 744 | class OnlinePaymentDisplayFormPage(KofaDisplayFormPage): |
---|
[7250] | 745 | """ Page to view an online payment ticket |
---|
| 746 | """ |
---|
| 747 | grok.context(IApplicantOnlinePayment) |
---|
| 748 | grok.name('index') |
---|
| 749 | grok.require('waeup.viewApplication') |
---|
[9984] | 750 | form_fields = grok.AutoFields(IApplicantOnlinePayment).omit('p_item') |
---|
[8170] | 751 | form_fields[ |
---|
| 752 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 753 | form_fields[ |
---|
| 754 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[7250] | 755 | pnav = 3 |
---|
| 756 | |
---|
| 757 | @property |
---|
| 758 | def label(self): |
---|
[7714] | 759 | return _('${a}: Online Payment Ticket ${b}', mapping = { |
---|
[8170] | 760 | 'a':self.context.__parent__.display_fullname, |
---|
| 761 | 'b':self.context.p_id}) |
---|
[7250] | 762 | |
---|
[8420] | 763 | class OnlinePaymentApprovePage(UtilityView, grok.View): |
---|
| 764 | """ Approval view |
---|
[7250] | 765 | """ |
---|
| 766 | grok.context(IApplicantOnlinePayment) |
---|
[8420] | 767 | grok.name('approve') |
---|
| 768 | grok.require('waeup.managePortal') |
---|
[7250] | 769 | |
---|
| 770 | def update(self): |
---|
[11580] | 771 | flashtype, msg, log = self.context.approveApplicantPayment() |
---|
[8428] | 772 | if log is not None: |
---|
[9771] | 773 | applicant = self.context.__parent__ |
---|
| 774 | # Add log message to applicants.log |
---|
| 775 | applicant.writeLogMessage(self, log) |
---|
| 776 | # Add log message to payments.log |
---|
| 777 | self.context.logger.info( |
---|
[9795] | 778 | '%s,%s,%s,%s,%s,,,,,,' % ( |
---|
[9771] | 779 | applicant.applicant_id, |
---|
| 780 | self.context.p_id, self.context.p_category, |
---|
| 781 | self.context.amount_auth, self.context.r_code)) |
---|
[11580] | 782 | self.flash(msg, type=flashtype) |
---|
[7250] | 783 | return |
---|
| 784 | |
---|
| 785 | def render(self): |
---|
| 786 | self.redirect(self.url(self.context, '@@index')) |
---|
| 787 | return |
---|
| 788 | |
---|
[7459] | 789 | class ExportPDFPaymentSlipPage(UtilityView, grok.View): |
---|
[7250] | 790 | """Deliver a PDF slip of the context. |
---|
| 791 | """ |
---|
| 792 | grok.context(IApplicantOnlinePayment) |
---|
[8262] | 793 | grok.name('payment_slip.pdf') |
---|
[7250] | 794 | grok.require('waeup.viewApplication') |
---|
[9984] | 795 | form_fields = grok.AutoFields(IApplicantOnlinePayment).omit('p_item') |
---|
[8173] | 796 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 797 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[7250] | 798 | prefix = 'form' |
---|
[8258] | 799 | note = None |
---|
[7250] | 800 | |
---|
| 801 | @property |
---|
[7714] | 802 | def title(self): |
---|
[7819] | 803 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[7811] | 804 | return translate(_('Payment Data'), 'waeup.kofa', |
---|
[7714] | 805 | target_language=portal_language) |
---|
| 806 | |
---|
| 807 | @property |
---|
[7250] | 808 | def label(self): |
---|
[7819] | 809 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[8262] | 810 | return translate(_('Online Payment Slip'), |
---|
[7811] | 811 | 'waeup.kofa', target_language=portal_language) \ |
---|
[7714] | 812 | + ' %s' % self.context.p_id |
---|
[7250] | 813 | |
---|
[11754] | 814 | @property |
---|
| 815 | def payment_slip_download_warning(self): |
---|
| 816 | if self.context.__parent__.state != SUBMITTED: |
---|
| 817 | return _('Please submit the application form before ' |
---|
| 818 | 'trying to download payment slips.') |
---|
| 819 | return '' |
---|
| 820 | |
---|
[7250] | 821 | def render(self): |
---|
[11754] | 822 | if self.payment_slip_download_warning: |
---|
| 823 | self.flash(self.payment_slip_download_warning, type='danger') |
---|
[11599] | 824 | self.redirect(self.url(self.context)) |
---|
| 825 | return |
---|
[7259] | 826 | applicantview = ApplicantBaseDisplayFormPage(self.context.__parent__, |
---|
[7250] | 827 | self.request) |
---|
| 828 | students_utils = getUtility(IStudentsUtils) |
---|
[8262] | 829 | return students_utils.renderPDF(self,'payment_slip.pdf', |
---|
[8258] | 830 | self.context.__parent__, applicantview, note=self.note) |
---|
[7250] | 831 | |
---|
[10571] | 832 | class ExportPDFPageApplicationSlip(UtilityView, grok.View): |
---|
[6358] | 833 | """Deliver a PDF slip of the context. |
---|
| 834 | """ |
---|
| 835 | grok.context(IApplicant) |
---|
| 836 | grok.name('application_slip.pdf') |
---|
[7136] | 837 | grok.require('waeup.viewApplication') |
---|
[6358] | 838 | prefix = 'form' |
---|
| 839 | |
---|
[8666] | 840 | def update(self): |
---|
[9051] | 841 | if self.context.state in ('initialized', 'started', 'paid'): |
---|
[8666] | 842 | self.flash( |
---|
[11254] | 843 | _('Please pay and submit before trying to download ' |
---|
| 844 | 'the application slip.'), type='warning') |
---|
[8666] | 845 | return self.redirect(self.url(self.context)) |
---|
| 846 | return |
---|
| 847 | |
---|
[6358] | 848 | def render(self): |
---|
[12395] | 849 | try: |
---|
| 850 | pdfstream = getAdapter(self.context, IPDF, name='application_slip')( |
---|
| 851 | view=self) |
---|
| 852 | except IOError: |
---|
| 853 | self.flash( |
---|
| 854 | _('Your image file is corrupted. ' |
---|
| 855 | 'Please replace.'), type='danger') |
---|
| 856 | return self.redirect(self.url(self.context)) |
---|
[6358] | 857 | self.response.setHeader( |
---|
| 858 | 'Content-Type', 'application/pdf') |
---|
[7392] | 859 | return pdfstream |
---|
[6358] | 860 | |
---|
[7081] | 861 | def handle_img_upload(upload, context, view): |
---|
[7063] | 862 | """Handle upload of applicant image. |
---|
[7081] | 863 | |
---|
| 864 | Returns `True` in case of success or `False`. |
---|
| 865 | |
---|
| 866 | Please note that file pointer passed in (`upload`) most probably |
---|
| 867 | points to end of file when leaving this function. |
---|
[7063] | 868 | """ |
---|
[7081] | 869 | size = file_size(upload) |
---|
| 870 | if size > MAX_UPLOAD_SIZE: |
---|
[11254] | 871 | view.flash(_('Uploaded image is too big!'), type='danger') |
---|
[7081] | 872 | return False |
---|
[7247] | 873 | dummy, ext = os.path.splitext(upload.filename) |
---|
| 874 | ext.lower() |
---|
| 875 | if ext != '.jpg': |
---|
[11254] | 876 | view.flash(_('jpg file extension expected.'), type='danger') |
---|
[7247] | 877 | return False |
---|
[7081] | 878 | upload.seek(0) # file pointer moved when determining size |
---|
[7063] | 879 | store = getUtility(IExtFileStore) |
---|
| 880 | file_id = IFileStoreNameChooser(context).chooseName() |
---|
| 881 | store.createFile(file_id, upload) |
---|
[7081] | 882 | return True |
---|
[7063] | 883 | |
---|
[7819] | 884 | class ApplicantManageFormPage(KofaEditFormPage): |
---|
[6196] | 885 | """A full edit view for applicant data. |
---|
| 886 | """ |
---|
| 887 | grok.context(IApplicant) |
---|
[7200] | 888 | grok.name('manage') |
---|
[7136] | 889 | grok.require('waeup.manageApplication') |
---|
[7200] | 890 | grok.template('applicanteditpage') |
---|
[6322] | 891 | manage_applications = True |
---|
[6196] | 892 | pnav = 3 |
---|
[12664] | 893 | display_actions = [[_('Save'), _('Finally Submit')], |
---|
[7714] | 894 | [_('Add online payment ticket'),_('Remove selected tickets')]] |
---|
[6196] | 895 | |
---|
[8046] | 896 | @property |
---|
[13886] | 897 | def display_payments(self): |
---|
| 898 | if self.context.special: |
---|
| 899 | return True |
---|
| 900 | return getattr(self.context.__parent__, 'application_fee', None) |
---|
| 901 | |
---|
| 902 | @property |
---|
[10831] | 903 | def form_fields(self): |
---|
| 904 | if self.context.special: |
---|
[10845] | 905 | form_fields = grok.AutoFields(ISpecialApplicant) |
---|
| 906 | form_fields['applicant_id'].for_display = True |
---|
[10831] | 907 | else: |
---|
| 908 | form_fields = grok.AutoFields(IApplicant) |
---|
| 909 | form_fields['student_id'].for_display = True |
---|
| 910 | form_fields['applicant_id'].for_display = True |
---|
| 911 | return form_fields |
---|
| 912 | |
---|
| 913 | @property |
---|
[10534] | 914 | def target(self): |
---|
| 915 | return getattr(self.context.__parent__, 'prefix', None) |
---|
| 916 | |
---|
| 917 | @property |
---|
[8046] | 918 | def separators(self): |
---|
| 919 | return getUtility(IApplicantsUtils).SEPARATORS_DICT |
---|
| 920 | |
---|
[11733] | 921 | @property |
---|
| 922 | def custom_upload_requirements(self): |
---|
| 923 | return '' |
---|
| 924 | |
---|
[6196] | 925 | def update(self): |
---|
[7200] | 926 | super(ApplicantManageFormPage, self).update() |
---|
[6353] | 927 | self.wf_info = IWorkflowInfo(self.context) |
---|
[7081] | 928 | self.max_upload_size = string_from_bytes(MAX_UPLOAD_SIZE) |
---|
[10090] | 929 | self.upload_success = None |
---|
[6598] | 930 | upload = self.request.form.get('form.passport', None) |
---|
| 931 | if upload: |
---|
[11733] | 932 | if self.custom_upload_requirements: |
---|
| 933 | self.flash( |
---|
| 934 | self.custom_upload_requirements, |
---|
| 935 | type='danger') |
---|
| 936 | self.redirect(self.url(self.context)) |
---|
| 937 | return |
---|
[10090] | 938 | # We got a fresh upload, upload_success is |
---|
| 939 | # either True or False |
---|
| 940 | self.upload_success = handle_img_upload( |
---|
[7084] | 941 | upload, self.context, self) |
---|
[10090] | 942 | if self.upload_success: |
---|
[10095] | 943 | self.context.writeLogMessage(self, 'saved: passport') |
---|
[6196] | 944 | return |
---|
| 945 | |
---|
| 946 | @property |
---|
| 947 | def label(self): |
---|
| 948 | container_title = self.context.__parent__.title |
---|
[8096] | 949 | return _('${a} <br /> Application Form ${b}', mapping = { |
---|
[7714] | 950 | 'a':container_title, 'b':self.context.application_number}) |
---|
[6196] | 951 | |
---|
[6303] | 952 | def getTransitions(self): |
---|
[6351] | 953 | """Return a list of dicts of allowed transition ids and titles. |
---|
[6353] | 954 | |
---|
| 955 | Each list entry provides keys ``name`` and ``title`` for |
---|
| 956 | internal name and (human readable) title of a single |
---|
| 957 | transition. |
---|
[6349] | 958 | """ |
---|
[8434] | 959 | allowed_transitions = [t for t in self.wf_info.getManualTransitions() |
---|
[11482] | 960 | if not t[0] in ('pay', 'create')] |
---|
[7687] | 961 | return [dict(name='', title=_('No transition'))] +[ |
---|
[6355] | 962 | dict(name=x, title=y) for x, y in allowed_transitions] |
---|
[6303] | 963 | |
---|
[7714] | 964 | @action(_('Save'), style='primary') |
---|
[6196] | 965 | def save(self, **data): |
---|
[7240] | 966 | form = self.request.form |
---|
| 967 | password = form.get('password', None) |
---|
| 968 | password_ctl = form.get('control_password', None) |
---|
| 969 | if password: |
---|
| 970 | validator = getUtility(IPasswordValidator) |
---|
| 971 | errors = validator.validate_password(password, password_ctl) |
---|
| 972 | if errors: |
---|
[11254] | 973 | self.flash( ' '.join(errors), type='danger') |
---|
[7240] | 974 | return |
---|
[10090] | 975 | if self.upload_success is False: # False is not None! |
---|
| 976 | # Error during image upload. Ignore other values. |
---|
| 977 | return |
---|
[6475] | 978 | changed_fields = self.applyData(self.context, **data) |
---|
[7199] | 979 | # Turn list of lists into single list |
---|
| 980 | if changed_fields: |
---|
| 981 | changed_fields = reduce(lambda x,y: x+y, changed_fields.values()) |
---|
[7240] | 982 | else: |
---|
| 983 | changed_fields = [] |
---|
| 984 | if password: |
---|
| 985 | # Now we know that the form has no errors and can set password ... |
---|
| 986 | IUserAccount(self.context).setPassword(password) |
---|
| 987 | changed_fields.append('password') |
---|
[7199] | 988 | fields_string = ' + '.join(changed_fields) |
---|
[7085] | 989 | trans_id = form.get('transition', None) |
---|
| 990 | if trans_id: |
---|
| 991 | self.wf_info.fireTransition(trans_id) |
---|
[7714] | 992 | self.flash(_('Form has been saved.')) |
---|
[6644] | 993 | if fields_string: |
---|
[12892] | 994 | self.context.writeLogMessage(self, 'saved: %s' % fields_string) |
---|
[6196] | 995 | return |
---|
| 996 | |
---|
[7250] | 997 | def unremovable(self, ticket): |
---|
[7330] | 998 | return False |
---|
[7250] | 999 | |
---|
| 1000 | # This method is also used by the ApplicantEditFormPage |
---|
| 1001 | def delPaymentTickets(self, **data): |
---|
| 1002 | form = self.request.form |
---|
[9701] | 1003 | if 'val_id' in form: |
---|
[7250] | 1004 | child_id = form['val_id'] |
---|
| 1005 | else: |
---|
[11254] | 1006 | self.flash(_('No payment selected.'), type='warning') |
---|
[7250] | 1007 | self.redirect(self.url(self.context)) |
---|
| 1008 | return |
---|
| 1009 | if not isinstance(child_id, list): |
---|
| 1010 | child_id = [child_id] |
---|
| 1011 | deleted = [] |
---|
| 1012 | for id in child_id: |
---|
| 1013 | # Applicants are not allowed to remove used payment tickets |
---|
| 1014 | if not self.unremovable(self.context[id]): |
---|
| 1015 | try: |
---|
| 1016 | del self.context[id] |
---|
| 1017 | deleted.append(id) |
---|
| 1018 | except: |
---|
[7714] | 1019 | self.flash(_('Could not delete:') + ' %s: %s: %s' % ( |
---|
[11254] | 1020 | id, sys.exc_info()[0], sys.exc_info()[1]), type='danger') |
---|
[7250] | 1021 | if len(deleted): |
---|
[7741] | 1022 | self.flash(_('Successfully removed: ${a}', |
---|
[7738] | 1023 | mapping = {'a':', '.join(deleted)})) |
---|
[8742] | 1024 | self.context.writeLogMessage( |
---|
| 1025 | self, 'removed: % s' % ', '.join(deleted)) |
---|
[7250] | 1026 | return |
---|
| 1027 | |
---|
[7252] | 1028 | # We explicitely want the forms to be validated before payment tickets |
---|
| 1029 | # can be created. If no validation is requested, use |
---|
[7459] | 1030 | # 'validator=NullValidator' in the action directive |
---|
[11578] | 1031 | @action(_('Add online payment ticket'), style='primary') |
---|
[7250] | 1032 | def addPaymentTicket(self, **data): |
---|
| 1033 | self.redirect(self.url(self.context, '@@addafp')) |
---|
[7252] | 1034 | return |
---|
[7250] | 1035 | |
---|
[7714] | 1036 | @jsaction(_('Remove selected tickets')) |
---|
[7250] | 1037 | def removePaymentTickets(self, **data): |
---|
| 1038 | self.delPaymentTickets(**data) |
---|
| 1039 | self.redirect(self.url(self.context) + '/@@manage') |
---|
| 1040 | return |
---|
| 1041 | |
---|
[10094] | 1042 | # Not used in base package |
---|
| 1043 | def file_exists(self, attr): |
---|
| 1044 | file = getUtility(IExtFileStore).getFileByContext( |
---|
| 1045 | self.context, attr=attr) |
---|
| 1046 | if file: |
---|
| 1047 | return True |
---|
| 1048 | else: |
---|
| 1049 | return False |
---|
| 1050 | |
---|
[7200] | 1051 | class ApplicantEditFormPage(ApplicantManageFormPage): |
---|
[5982] | 1052 | """An applicant-centered edit view for applicant data. |
---|
| 1053 | """ |
---|
[6196] | 1054 | grok.context(IApplicantEdit) |
---|
[5273] | 1055 | grok.name('edit') |
---|
[6198] | 1056 | grok.require('waeup.handleApplication') |
---|
[7200] | 1057 | grok.template('applicanteditpage') |
---|
[6322] | 1058 | manage_applications = False |
---|
[10358] | 1059 | submit_state = PAID |
---|
[5484] | 1060 | |
---|
[7250] | 1061 | @property |
---|
[10831] | 1062 | def form_fields(self): |
---|
| 1063 | if self.context.special: |
---|
[11657] | 1064 | form_fields = grok.AutoFields(ISpecialApplicant).omit( |
---|
| 1065 | 'locked', 'suspended') |
---|
[10845] | 1066 | form_fields['applicant_id'].for_display = True |
---|
[10831] | 1067 | else: |
---|
| 1068 | form_fields = grok.AutoFields(IApplicantEdit).omit( |
---|
| 1069 | 'locked', 'course_admitted', 'student_id', |
---|
[10845] | 1070 | 'suspended' |
---|
[10831] | 1071 | ) |
---|
| 1072 | form_fields['applicant_id'].for_display = True |
---|
| 1073 | form_fields['reg_number'].for_display = True |
---|
| 1074 | return form_fields |
---|
| 1075 | |
---|
| 1076 | @property |
---|
[7250] | 1077 | def display_actions(self): |
---|
[8286] | 1078 | state = IWorkflowState(self.context).getState() |
---|
[13100] | 1079 | # If the form is unlocked, applicants are allowed to save the form |
---|
| 1080 | # and remove unused tickets. |
---|
| 1081 | actions = [[_('Save')], [_('Remove selected tickets')]] |
---|
| 1082 | # Only in state started they can also add tickets. |
---|
[10358] | 1083 | if state == STARTED: |
---|
[7714] | 1084 | actions = [[_('Save')], |
---|
| 1085 | [_('Add online payment ticket'),_('Remove selected tickets')]] |
---|
[13100] | 1086 | # In state paid, they can submit the data and further add tickets |
---|
| 1087 | # if the application is special. |
---|
[11599] | 1088 | elif self.context.special and state == PAID: |
---|
[12664] | 1089 | actions = [[_('Save'), _('Finally Submit')], |
---|
[11599] | 1090 | [_('Add online payment ticket'),_('Remove selected tickets')]] |
---|
[8286] | 1091 | elif state == PAID: |
---|
[12664] | 1092 | actions = [[_('Save'), _('Finally Submit')], |
---|
[7714] | 1093 | [_('Remove selected tickets')]] |
---|
[7250] | 1094 | return actions |
---|
| 1095 | |
---|
[7330] | 1096 | def unremovable(self, ticket): |
---|
[13100] | 1097 | return ticket.r_code |
---|
[7330] | 1098 | |
---|
[7145] | 1099 | def emit_lock_message(self): |
---|
[11254] | 1100 | self.flash(_('The requested form is locked (read-only).'), |
---|
| 1101 | type='warning') |
---|
[5941] | 1102 | self.redirect(self.url(self.context)) |
---|
| 1103 | return |
---|
[6078] | 1104 | |
---|
[5686] | 1105 | def update(self): |
---|
[8665] | 1106 | if self.context.locked or ( |
---|
| 1107 | self.context.__parent__.expired and |
---|
| 1108 | self.context.__parent__.strict_deadline): |
---|
[7145] | 1109 | self.emit_lock_message() |
---|
[5941] | 1110 | return |
---|
[7200] | 1111 | super(ApplicantEditFormPage, self).update() |
---|
[5686] | 1112 | return |
---|
[5952] | 1113 | |
---|
[6196] | 1114 | def dataNotComplete(self): |
---|
[7252] | 1115 | store = getUtility(IExtFileStore) |
---|
| 1116 | if not store.getFileByContext(self.context, attr=u'passport.jpg'): |
---|
[7714] | 1117 | return _('No passport picture uploaded.') |
---|
[6322] | 1118 | if not self.request.form.get('confirm_passport', False): |
---|
[7714] | 1119 | return _('Passport picture confirmation box not ticked.') |
---|
[6196] | 1120 | return False |
---|
[5952] | 1121 | |
---|
[7252] | 1122 | # We explicitely want the forms to be validated before payment tickets |
---|
| 1123 | # can be created. If no validation is requested, use |
---|
[7459] | 1124 | # 'validator=NullValidator' in the action directive |
---|
[11578] | 1125 | @action(_('Add online payment ticket'), style='primary') |
---|
[7250] | 1126 | def addPaymentTicket(self, **data): |
---|
| 1127 | self.redirect(self.url(self.context, '@@addafp')) |
---|
[7252] | 1128 | return |
---|
[7250] | 1129 | |
---|
[7714] | 1130 | @jsaction(_('Remove selected tickets')) |
---|
[7250] | 1131 | def removePaymentTickets(self, **data): |
---|
| 1132 | self.delPaymentTickets(**data) |
---|
| 1133 | self.redirect(self.url(self.context) + '/@@edit') |
---|
| 1134 | return |
---|
| 1135 | |
---|
[7996] | 1136 | @action(_('Save'), style='primary') |
---|
[5273] | 1137 | def save(self, **data): |
---|
[10090] | 1138 | if self.upload_success is False: # False is not None! |
---|
| 1139 | # Error during image upload. Ignore other values. |
---|
| 1140 | return |
---|
[5273] | 1141 | self.applyData(self.context, **data) |
---|
[10210] | 1142 | self.flash(_('Form has been saved.')) |
---|
[5273] | 1143 | return |
---|
| 1144 | |
---|
[12664] | 1145 | @action(_('Finally Submit'), warning=WARNING) |
---|
[5484] | 1146 | def finalsubmit(self, **data): |
---|
[10090] | 1147 | if self.upload_success is False: # False is not None! |
---|
[7084] | 1148 | return # error during image upload. Ignore other values |
---|
[6196] | 1149 | if self.dataNotComplete(): |
---|
[11254] | 1150 | self.flash(self.dataNotComplete(), type='danger') |
---|
[5941] | 1151 | return |
---|
[7252] | 1152 | self.applyData(self.context, **data) |
---|
[8286] | 1153 | state = IWorkflowState(self.context).getState() |
---|
[6322] | 1154 | # This shouldn't happen, but the application officer |
---|
| 1155 | # might have forgotten to lock the form after changing the state |
---|
[10358] | 1156 | if state != self.submit_state: |
---|
[11254] | 1157 | self.flash(_('The form cannot be submitted. Wrong state!'), |
---|
| 1158 | type='danger') |
---|
[6303] | 1159 | return |
---|
| 1160 | IWorkflowInfo(self.context).fireTransition('submit') |
---|
[8589] | 1161 | # application_date is used in export files for sorting. |
---|
| 1162 | # We can thus store utc. |
---|
[8194] | 1163 | self.context.application_date = datetime.utcnow() |
---|
[7714] | 1164 | self.flash(_('Form has been submitted.')) |
---|
[6196] | 1165 | self.redirect(self.url(self.context)) |
---|
[5273] | 1166 | return |
---|
[5941] | 1167 | |
---|
[7063] | 1168 | class PassportImage(grok.View): |
---|
| 1169 | """Renders the passport image for applicants. |
---|
| 1170 | """ |
---|
| 1171 | grok.name('passport.jpg') |
---|
| 1172 | grok.context(IApplicant) |
---|
[7113] | 1173 | grok.require('waeup.viewApplication') |
---|
[7063] | 1174 | |
---|
| 1175 | def render(self): |
---|
| 1176 | # A filename chooser turns a context into a filename suitable |
---|
| 1177 | # for file storage. |
---|
| 1178 | image = getUtility(IExtFileStore).getFileByContext(self.context) |
---|
| 1179 | self.response.setHeader( |
---|
| 1180 | 'Content-Type', 'image/jpeg') |
---|
| 1181 | if image is None: |
---|
| 1182 | # show placeholder image |
---|
[7089] | 1183 | return open(DEFAULT_PASSPORT_IMAGE_PATH, 'rb').read() |
---|
[7063] | 1184 | return image |
---|
[7363] | 1185 | |
---|
[7819] | 1186 | class ApplicantRegistrationPage(KofaAddFormPage): |
---|
[7363] | 1187 | """Captcha'd registration page for applicants. |
---|
| 1188 | """ |
---|
| 1189 | grok.context(IApplicantsContainer) |
---|
| 1190 | grok.name('register') |
---|
[7373] | 1191 | grok.require('waeup.Anonymous') |
---|
[7363] | 1192 | grok.template('applicantregister') |
---|
| 1193 | |
---|
[7368] | 1194 | @property |
---|
[8033] | 1195 | def form_fields(self): |
---|
| 1196 | form_fields = None |
---|
[8128] | 1197 | if self.context.mode == 'update': |
---|
| 1198 | form_fields = grok.AutoFields(IApplicantRegisterUpdate).select( |
---|
[11738] | 1199 | 'lastname','reg_number','email') |
---|
[8128] | 1200 | else: #if self.context.mode == 'create': |
---|
[8033] | 1201 | form_fields = grok.AutoFields(IApplicantEdit).select( |
---|
| 1202 | 'firstname', 'middlename', 'lastname', 'email', 'phone') |
---|
| 1203 | return form_fields |
---|
| 1204 | |
---|
| 1205 | @property |
---|
[7368] | 1206 | def label(self): |
---|
[8078] | 1207 | return _('Apply for ${a}', |
---|
[7714] | 1208 | mapping = {'a':self.context.title}) |
---|
[7368] | 1209 | |
---|
[7363] | 1210 | def update(self): |
---|
[8665] | 1211 | if self.context.expired: |
---|
[11254] | 1212 | self.flash(_('Outside application period.'), type='warning') |
---|
[7368] | 1213 | self.redirect(self.url(self.context)) |
---|
| 1214 | return |
---|
[13394] | 1215 | blocker = grok.getSite()['configuration'].maintmode_enabled_by |
---|
| 1216 | if blocker: |
---|
| 1217 | self.flash(_('The portal is in maintenance mode ' |
---|
| 1218 | 'and registration temporarily disabled.'), |
---|
| 1219 | type='warning') |
---|
| 1220 | self.redirect(self.url(self.context)) |
---|
| 1221 | return |
---|
[7368] | 1222 | # Handle captcha |
---|
[7363] | 1223 | self.captcha = getUtility(ICaptchaManager).getCaptcha() |
---|
| 1224 | self.captcha_result = self.captcha.verify(self.request) |
---|
| 1225 | self.captcha_code = self.captcha.display(self.captcha_result.error_code) |
---|
| 1226 | return |
---|
| 1227 | |
---|
[8629] | 1228 | def _redirect(self, email, password, applicant_id): |
---|
| 1229 | # Forward only email to landing page in base package. |
---|
| 1230 | self.redirect(self.url(self.context, 'registration_complete', |
---|
| 1231 | data = dict(email=email))) |
---|
| 1232 | return |
---|
| 1233 | |
---|
[9178] | 1234 | @action(_('Send login credentials to email address'), style='primary') |
---|
[7363] | 1235 | def register(self, **data): |
---|
| 1236 | if not self.captcha_result.is_valid: |
---|
[8037] | 1237 | # Captcha will display error messages automatically. |
---|
[7363] | 1238 | # No need to flash something. |
---|
| 1239 | return |
---|
[8033] | 1240 | if self.context.mode == 'create': |
---|
[13217] | 1241 | # Check if there are unused records in this container which |
---|
| 1242 | # can be taken |
---|
| 1243 | applicant = self.context.first_unused |
---|
| 1244 | if applicant is None: |
---|
[13215] | 1245 | # Add applicant |
---|
| 1246 | applicant = createObject(u'waeup.Applicant') |
---|
| 1247 | self.context.addApplicant(applicant) |
---|
[8033] | 1248 | self.applyData(applicant, **data) |
---|
[8042] | 1249 | applicant.reg_number = applicant.applicant_id |
---|
| 1250 | notify(grok.ObjectModifiedEvent(applicant)) |
---|
[8033] | 1251 | elif self.context.mode == 'update': |
---|
| 1252 | # Update applicant |
---|
[8037] | 1253 | reg_number = data.get('reg_number','') |
---|
[11738] | 1254 | lastname = data.get('lastname','') |
---|
[8033] | 1255 | cat = getUtility(ICatalog, name='applicants_catalog') |
---|
| 1256 | results = list( |
---|
| 1257 | cat.searchResults(reg_number=(reg_number, reg_number))) |
---|
| 1258 | if results: |
---|
| 1259 | applicant = results[0] |
---|
[11738] | 1260 | if getattr(applicant,'lastname',None) is None: |
---|
[11254] | 1261 | self.flash(_('An error occurred.'), type='danger') |
---|
[8037] | 1262 | return |
---|
[11738] | 1263 | elif applicant.lastname.lower() != lastname.lower(): |
---|
[8042] | 1264 | # Don't tell the truth here. Anonymous must not |
---|
[11738] | 1265 | # know that a record was found and only the lastname |
---|
[8042] | 1266 | # verification failed. |
---|
[13099] | 1267 | self.flash( |
---|
| 1268 | _('No application record found.'), type='warning') |
---|
[8037] | 1269 | return |
---|
[8627] | 1270 | elif applicant.password is not None and \ |
---|
| 1271 | applicant.state != INITIALIZED: |
---|
| 1272 | self.flash(_('Your password has already been set and used. ' |
---|
[11254] | 1273 | 'Please proceed to the login page.'), |
---|
| 1274 | type='warning') |
---|
[8042] | 1275 | return |
---|
| 1276 | # Store email address but nothing else. |
---|
[8033] | 1277 | applicant.email = data['email'] |
---|
[8042] | 1278 | notify(grok.ObjectModifiedEvent(applicant)) |
---|
[8033] | 1279 | else: |
---|
[8042] | 1280 | # No record found, this is the truth. |
---|
[11254] | 1281 | self.flash(_('No application record found.'), type='warning') |
---|
[8033] | 1282 | return |
---|
| 1283 | else: |
---|
[8042] | 1284 | # Does not happen but anyway ... |
---|
[8033] | 1285 | return |
---|
[7819] | 1286 | kofa_utils = getUtility(IKofaUtils) |
---|
[7811] | 1287 | password = kofa_utils.genPassword() |
---|
[7380] | 1288 | IUserAccount(applicant).setPassword(password) |
---|
[7365] | 1289 | # Send email with credentials |
---|
[7399] | 1290 | login_url = self.url(grok.getSite(), 'login') |
---|
[8853] | 1291 | url_info = u'Login: %s' % login_url |
---|
[7714] | 1292 | msg = _('You have successfully been registered for the') |
---|
[7811] | 1293 | if kofa_utils.sendCredentials(IUserAccount(applicant), |
---|
[8853] | 1294 | password, url_info, msg): |
---|
[8629] | 1295 | email_sent = applicant.email |
---|
[7380] | 1296 | else: |
---|
[8629] | 1297 | email_sent = None |
---|
| 1298 | self._redirect(email=email_sent, password=password, |
---|
| 1299 | applicant_id=applicant.applicant_id) |
---|
[7380] | 1300 | return |
---|
| 1301 | |
---|
[7819] | 1302 | class ApplicantRegistrationEmailSent(KofaPage): |
---|
[7380] | 1303 | """Landing page after successful registration. |
---|
[8629] | 1304 | |
---|
[7380] | 1305 | """ |
---|
| 1306 | grok.name('registration_complete') |
---|
| 1307 | grok.require('waeup.Public') |
---|
| 1308 | grok.template('applicantregemailsent') |
---|
[7714] | 1309 | label = _('Your registration was successful.') |
---|
[7380] | 1310 | |
---|
[8629] | 1311 | def update(self, email=None, applicant_id=None, password=None): |
---|
[7380] | 1312 | self.email = email |
---|
[8629] | 1313 | self.password = password |
---|
| 1314 | self.applicant_id = applicant_id |
---|
[7380] | 1315 | return |
---|
[10655] | 1316 | |
---|
[13254] | 1317 | class ApplicantCheckStatusPage(KofaPage): |
---|
| 1318 | """Captcha'd status checking page for applicants. |
---|
| 1319 | """ |
---|
| 1320 | grok.context(IApplicantsRoot) |
---|
| 1321 | grok.name('checkstatus') |
---|
| 1322 | grok.require('waeup.Anonymous') |
---|
| 1323 | grok.template('applicantcheckstatus') |
---|
| 1324 | buttonname = _('Submit') |
---|
| 1325 | |
---|
| 1326 | def label(self): |
---|
| 1327 | if self.result: |
---|
[13429] | 1328 | return _('Admission status of ${a}', |
---|
[13254] | 1329 | mapping = {'a':self.applicant.applicant_id}) |
---|
[13428] | 1330 | return _('Check your admission status') |
---|
[13254] | 1331 | |
---|
| 1332 | def update(self, SUBMIT=None): |
---|
| 1333 | form = self.request.form |
---|
| 1334 | self.result = False |
---|
| 1335 | # Handle captcha |
---|
| 1336 | self.captcha = getUtility(ICaptchaManager).getCaptcha() |
---|
| 1337 | self.captcha_result = self.captcha.verify(self.request) |
---|
| 1338 | self.captcha_code = self.captcha.display(self.captcha_result.error_code) |
---|
| 1339 | if SUBMIT: |
---|
| 1340 | if not self.captcha_result.is_valid: |
---|
| 1341 | # Captcha will display error messages automatically. |
---|
| 1342 | # No need to flash something. |
---|
| 1343 | return |
---|
[13363] | 1344 | unique_id = form.get('unique_id', None) |
---|
[13254] | 1345 | lastname = form.get('lastname', None) |
---|
[13363] | 1346 | if not unique_id or not lastname: |
---|
[13254] | 1347 | self.flash( |
---|
| 1348 | _('Required input missing.'), type='warning') |
---|
| 1349 | return |
---|
| 1350 | cat = getUtility(ICatalog, name='applicants_catalog') |
---|
| 1351 | results = list( |
---|
[13363] | 1352 | cat.searchResults(applicant_id=(unique_id, unique_id))) |
---|
| 1353 | if not results: |
---|
| 1354 | results = list( |
---|
| 1355 | cat.searchResults(reg_number=(unique_id, unique_id))) |
---|
[13254] | 1356 | if results: |
---|
| 1357 | applicant = results[0] |
---|
[13282] | 1358 | if applicant.lastname.lower().strip() != lastname.lower(): |
---|
[13254] | 1359 | # Don't tell the truth here. Anonymous must not |
---|
| 1360 | # know that a record was found and only the lastname |
---|
| 1361 | # verification failed. |
---|
| 1362 | self.flash( |
---|
| 1363 | _('No application record found.'), type='warning') |
---|
| 1364 | return |
---|
| 1365 | else: |
---|
| 1366 | self.flash(_('No application record found.'), type='warning') |
---|
| 1367 | return |
---|
| 1368 | self.applicant = applicant |
---|
| 1369 | self.entry_session = "%s/%s" % ( |
---|
| 1370 | applicant.__parent__.year, |
---|
| 1371 | applicant.__parent__.year+1) |
---|
| 1372 | course_admitted = getattr(applicant, 'course_admitted', None) |
---|
| 1373 | self.course_admitted = False |
---|
| 1374 | if course_admitted is not None: |
---|
| 1375 | self.course_admitted = True |
---|
| 1376 | self.longtitle = course_admitted.longtitle |
---|
| 1377 | self.department = course_admitted.__parent__.__parent__.longtitle |
---|
| 1378 | self.faculty = course_admitted.__parent__.__parent__.__parent__.longtitle |
---|
| 1379 | self.result = True |
---|
| 1380 | self.admitted = False |
---|
| 1381 | self.not_admitted = False |
---|
| 1382 | self.submitted = False |
---|
| 1383 | self.not_submitted = False |
---|
[13356] | 1384 | self.created = False |
---|
[13254] | 1385 | if applicant.state in (ADMITTED, CREATED): |
---|
| 1386 | self.admitted = True |
---|
[13356] | 1387 | if applicant.state in (CREATED): |
---|
| 1388 | self.created = True |
---|
[13365] | 1389 | self.student_id = applicant.student_id |
---|
| 1390 | self.password = applicant.application_number |
---|
[13254] | 1391 | if applicant.state in (NOT_ADMITTED,): |
---|
| 1392 | self.not_admitted = True |
---|
| 1393 | if applicant.state in (SUBMITTED,): |
---|
| 1394 | self.submitted = True |
---|
| 1395 | if applicant.state in (INITIALIZED, STARTED, PAID): |
---|
| 1396 | self.not_submitted = True |
---|
| 1397 | return |
---|
| 1398 | |
---|
[10655] | 1399 | class ExportJobContainerOverview(KofaPage): |
---|
| 1400 | """Page that lists active applicant data export jobs and provides links |
---|
| 1401 | to discard or download CSV files. |
---|
| 1402 | |
---|
| 1403 | """ |
---|
| 1404 | grok.context(VirtualApplicantsExportJobContainer) |
---|
| 1405 | grok.require('waeup.manageApplication') |
---|
| 1406 | grok.name('index.html') |
---|
| 1407 | grok.template('exportjobsindex') |
---|
[11254] | 1408 | label = _('Data Exports') |
---|
[10655] | 1409 | pnav = 3 |
---|
| 1410 | |
---|
| 1411 | def update(self, CREATE=None, DISCARD=None, job_id=None): |
---|
| 1412 | if CREATE: |
---|
| 1413 | self.redirect(self.url('@@start_export')) |
---|
| 1414 | return |
---|
| 1415 | if DISCARD and job_id: |
---|
| 1416 | entry = self.context.entry_from_job_id(job_id) |
---|
| 1417 | self.context.delete_export_entry(entry) |
---|
| 1418 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
---|
| 1419 | self.context.logger.info( |
---|
| 1420 | '%s - discarded: job_id=%s' % (ob_class, job_id)) |
---|
| 1421 | self.flash(_('Discarded export') + ' %s' % job_id) |
---|
| 1422 | self.entries = doll_up(self, user=self.request.principal.id) |
---|
| 1423 | return |
---|
| 1424 | |
---|
| 1425 | class ExportJobContainerJobStart(KofaPage): |
---|
| 1426 | """Page that starts an applicants export job. |
---|
| 1427 | |
---|
| 1428 | """ |
---|
| 1429 | grok.context(VirtualApplicantsExportJobContainer) |
---|
| 1430 | grok.require('waeup.manageApplication') |
---|
| 1431 | grok.name('start_export') |
---|
| 1432 | |
---|
| 1433 | def update(self): |
---|
[13152] | 1434 | utils = queryUtility(IKofaUtils) |
---|
| 1435 | if not utils.expensive_actions_allowed(): |
---|
| 1436 | self.flash(_( |
---|
| 1437 | "Currently, exporters cannot be started due to high " |
---|
| 1438 | "system load. Please try again later."), type='danger') |
---|
| 1439 | self.entries = doll_up(self, user=None) |
---|
| 1440 | return |
---|
[10655] | 1441 | exporter = 'applicants' |
---|
| 1442 | container_code = self.context.__parent__.code |
---|
| 1443 | job_id = self.context.start_export_job(exporter, |
---|
| 1444 | self.request.principal.id, |
---|
| 1445 | container=container_code) |
---|
| 1446 | |
---|
| 1447 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') |
---|
| 1448 | self.context.logger.info( |
---|
| 1449 | '%s - exported: %s (%s), job_id=%s' |
---|
| 1450 | % (ob_class, exporter, container_code, job_id)) |
---|
| 1451 | self.flash(_('Export started.')) |
---|
| 1452 | self.redirect(self.url(self.context)) |
---|
| 1453 | return |
---|
| 1454 | |
---|
| 1455 | def render(self): |
---|
| 1456 | return |
---|
| 1457 | |
---|
| 1458 | class ExportJobContainerDownload(ExportCSVView): |
---|
| 1459 | """Page that downloads a students export csv file. |
---|
| 1460 | |
---|
| 1461 | """ |
---|
| 1462 | grok.context(VirtualApplicantsExportJobContainer) |
---|
[11253] | 1463 | grok.require('waeup.manageApplication') |
---|