source: main/waeup.kofa/branches/uli-diazo-themed/src/waeup/kofa/applicants/browser.py @ 11060

Last change on this file since 11060 was 11016, checked in by Henrik Bettermann, 11 years ago

Remove resources and theming completely.

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