Ignore:
Timestamp:
3 Apr 2012, 20:40:17 (12 years ago)
Author:
Henrik Bettermann
Message:

Define two different application modes: create and update. The latter expects existing (imported) application records. The ApplicantRegistrationPage? renders different form fields and creates or updates application records depending on the selected mode.

The update registration mode is not yet secure enough. Further security features will be added.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/applicants
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py

    r8014 r8033  
    2424from datetime import datetime, date
    2525from zope.component import getUtility, createObject, getAdapter
     26from zope.catalog.interfaces import ICatalog
    2627from zope.i18n import translate
    2728from hurry.workflow.interfaces import (
     
    3031    IApplicant, IApplicantEdit, IApplicantsRoot,
    3132    IApplicantsContainer, IApplicantsContainerAdd,
    32     MAX_UPLOAD_SIZE, IApplicantOnlinePayment, IApplicantsUtils
     33    MAX_UPLOAD_SIZE, IApplicantOnlinePayment, IApplicantsUtils,
     34    IApplicantUpdateByRegNo
    3335    )
    3436from waeup.kofa.applicants.workflow import INITIALIZED, STARTED, PAID, SUBMITTED
     
    858860    grok.require('waeup.Anonymous')
    859861    grok.template('applicantregister')
    860     form_fields = grok.AutoFields(IApplicantEdit).select(
    861         'firstname', 'middlename', 'lastname', 'email', 'phone')
    862     form_fields['phone'].custom_widget = PhoneWidget
     862
     863    @property
     864    def form_fields(self):
     865        form_fields = None
     866        if self.context.mode == 'create':
     867            form_fields = grok.AutoFields(IApplicantEdit).select(
     868                'firstname', 'middlename', 'lastname', 'email', 'phone')
     869            form_fields['phone'].custom_widget = PhoneWidget
     870        elif self.context.mode == 'update':
     871            form_fields = grok.AutoFields(IApplicantUpdateByRegNo).select(
     872                'reg_number','email')
     873        return form_fields
    863874
    864875    @property
     
    890901            # No need to flash something.
    891902            return
    892         # Add applicant and create password
    893         applicant = createObject(u'waeup.Applicant')
    894         self.applyData(applicant, **data)
    895         self.context.addApplicant(applicant)
     903        if self.context.mode == 'create':
     904            # Add applicant
     905            applicant = createObject(u'waeup.Applicant')
     906            self.applyData(applicant, **data)
     907            self.context.addApplicant(applicant)
     908        elif self.context.mode == 'update':
     909            # Update applicant
     910            reg_number = data['reg_number']
     911            cat = getUtility(ICatalog, name='applicants_catalog')
     912            results = list(
     913                cat.searchResults(reg_number=(reg_number, reg_number)))
     914            if results:
     915                applicant = results[0]
     916                if applicant.password is not None:
     917                    self.flash(_('Your password has already been set.'))
     918                    return
     919                applicant.email = data['email']
     920            else:
     921                self.flash(_('No application record found.'))
     922                return
     923        else:
     924            return
    896925        kofa_utils = getUtility(IKofaUtils)
    897926        password = kofa_utils.genPassword()
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser_templates/applicantregister.pt

    r7811 r8033  
    1616    </tbody>
    1717  </table>
    18   <p i18n:translate="">
     18  <p i18n:translate="" tal:condition="python: context.mode=='create'">
    1919    An account will be created for you and an email with your login
     20    credentials will be sent to the address provided.
     21  </p>
     22  <p i18n:translate="" tal:condition="python: context.mode=='update'">
     23    Your application record will be looked up and an email with your login
    2024    credentials will be sent to the address provided.
    2125  </p>
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/interfaces.py

    r8016 r8033  
    2929from waeup.kofa.schema import TextLineChoice
    3030from waeup.kofa.interfaces import (
    31     IKofaObject, year_range, validate_email, academic_sessions_vocab)
     31    IKofaObject, year_range, validate_email, academic_sessions_vocab,
     32    SimpleKofaVocabulary)
    3233from waeup.kofa.interfaces import MessageFactory as _
    3334from waeup.kofa.payments.interfaces import IOnlinePayment
     
    135136#            apppins_dict[value][1],self.apppins_dict[value][0])
    136137
     138application_modes_vocab = SimpleKofaVocabulary(
     139    (_('Create Application Records'), 'create'),
     140    (_('Update Application Records'), 'update'),
     141    )
    137142
    138143class IApplicantsUtils(Interface):
     
    176181        values = year_range(),
    177182        readonly = True,
     183        )
     184
     185    mode = schema.Choice(
     186        title = _(u'Application Mode'),
     187        vocabulary = application_modes_vocab,
     188        required = True,
    178189        )
    179190
     
    202213        required = False,
    203214        default = u'''This text can been seen by anonymous users.
    204 Here we put mult-lingual information about the study courses provided, the application procedure and deadlines.
     215Here we put multi-lingual information about the study courses provided, the application procedure and deadlines.
    205216>>de<<
    206217Dieser Text kann von anonymen Benutzern gelesen werden.
     
    298309        )
    299310    reg_number = TextLineChoice(
    300         title = _(u'JAMB Registration Number'),
     311        title = _(u'Registration Number'),
    301312        readonly = False,
    302313        required = True,
     
    337348    email = schema.ASCIILine(
    338349        title = _(u'Email Address'),
    339         required = True,
     350        required = False,
    340351        constraint=validate_email,
    341352        )
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/sample_container_data.csv

    r7910 r8033  
    1 code,title,prefix,entry_level,year,provider,application_category,description,startdate,enddate,strict_deadline
    2 app2012,General Studies 2012/2013,app,100,2012,waeup.kofa.applicants.ApplicantsContainer,basic,"This text can been seen by anonymous users.
     1code,title,prefix,entry_level,year,application_category,description,startdate,enddate,strict_deadline,mode
     2app2012,General Studies 2012/2013,app,100,2012,basic,"This text can been seen by anonymous users.
    33>>de<<
    4 Dieser Text kann von anonymen Benutzern gelesen werden.",2012-03-01,2012-04-25,1
    5 app2013,General Studies 2013/2014,app,100,2012,waeup.kofa.applicants.ApplicantsContainer,basic,"This text can been seen by anonymous users.
     4Dieser Text kann von anonymen Benutzern gelesen werden.",2012-03-01,2012-04-25,1,create
     5app2013,General Studies 2013/2014,app,100,2012,basic,"This text can been seen by anonymous users.
    66>>de<<
    7 Dieser Text kann von anonymen Benutzern gelesen werden.",2013-03-01,2013-04-25,1
     7Dieser Text kann von anonymen Benutzern gelesen werden.",2013-03-01,2013-04-25,1,create
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py

    r8008 r8033  
    8484        applicantscontainer.entry_level = 100
    8585        applicantscontainer.application_category = 'basic'
     86        applicantscontainer.mode = 'create'
    8687        delta = timedelta(days=10)
    8788        applicantscontainer.startdate = date.today() - delta
     
    248249        self.browser.getControl(name="form.year").value = ['2010']
    249250        self.browser.getControl(name="form.entry_level").value = ['100']
     251        self.browser.getControl(name="form.mode").value = ['create']
    250252        self.browser.getControl(
    251253            name="form.application_category").value = ['basic']
     
    262264        self.browser.getControl(name="form.year").value = ['2010']
    263265        self.browser.getControl(name="form.entry_level").value = ['100']
     266        self.browser.getControl(name="form.mode").value = ['create']
    264267        self.browser.getControl(
    265268            name="form.application_category").value = ['basic']
     
    276279        self.browser.getControl(name="form.year").value = ['2010']
    277280        self.browser.getControl(name="form.entry_level").value = ['100']
     281        self.browser.getControl(name="form.mode").value = ['create']
    278282        #self.browser.getControl(name="form.ac_prefix").value = ['APP']
    279283        self.browser.getControl(
     
    788792    layer = FunctionalLayer
    789793
    790     def test_register_applicant(self):
     794    def test_register_applicant_create(self):
    791795        # An applicant can register himself.
    792796        self.browser.open(self.container_path)
     
    802806        self.assertEqual(self.browser.url,
    803807            self.container_path + '/registration_complete?email=xx%40yy.zz')
     808        # Now we change the application mode and check if applicants
     809        # can find and update imported records instead of creating new records.
     810        # First we check what happens if record can't be found.
     811        self.applicantscontainer.mode = 'update'
     812        self.browser.open(self.container_path + '/register')
     813        #self.browser.getControl(name="form.firstname").value = 'John'
     814        self.browser.getControl(name="form.reg_number").value = 'anynumber'
     815        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
     816        self.browser.getControl("Get login credentials").click()
     817        self.assertTrue('No application record found.'
     818            in self.browser.contents)
     819        # Now we check if password has already been set.
     820        #self.browser.getControl(name="form.firstname").value = 'John'
     821        self.browser.getControl(name="form.reg_number").value = '1234'
     822        self.browser.getControl("Get login credentials").click()
     823        self.assertTrue('Your password has already been set.'
     824            in self.browser.contents)
     825        # We unset the password and try to register again.
     826        IUserAccount(
     827            self.app['applicants']['app2009'][
     828            self.applicant.application_number]).context.password = None
     829        self.browser.open(self.container_path + '/register')
     830        #self.browser.getControl(name="form.firstname").value = 'John'
     831        self.browser.getControl(name="form.reg_number").value = '1234'
     832        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
     833        self.browser.getControl("Get login credentials").click()
     834        self.assertTrue('Your registration was successful.'
     835            in self.browser.contents)
    804836        return
    805837
Note: See TracChangeset for help on using the changeset viewer.