Ignore:
Timestamp:
16 Dec 2011, 13:50:40 (13 years ago)
Author:
uli
Message:

Add pages for captcha-driven applicant registration.

File:
1 edited

Legend:

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

    r7356 r7363  
    3434    Table, Spacer)
    3535from reportlab.platypus.tables import TableStyle
     36from waeup.sirp.applicants.interfaces import (
     37    IApplicant, IApplicantEdit, IApplicantsRoot,
     38    IApplicantsContainer, IApplicantsContainerAdd, application_types_vocab,
     39    MAX_UPLOAD_SIZE, IApplicantOnlinePayment,
     40    )
     41from waeup.sirp.applicants.workflow import INITIALIZED, STARTED, PAID, SUBMITTED
    3642from waeup.sirp.browser import (
    37     SIRPPage, SIRPEditFormPage, SIRPAddFormPage, SIRPDisplayFormPage)
     43    SIRPPage, SIRPEditFormPage, SIRPAddFormPage, SIRPDisplayFormPage,
     44    DEFAULT_PASSPORT_IMAGE_PATH)
     45from waeup.sirp.browser.interfaces import ICaptchaManager
    3846from waeup.sirp.browser.breadcrumbs import Breadcrumb
    3947from waeup.sirp.browser.layout import NullValidator, jsaction, JSAction
     
    4553    IFileStoreNameChooser, IPasswordValidator, IUserAccount)
    4654from waeup.sirp.permissions import get_users_with_local_roles
    47 from waeup.sirp.browser import DEFAULT_PASSPORT_IMAGE_PATH
     55from waeup.sirp.students.viewlets import PrimaryStudentNavTab
     56from waeup.sirp.students.interfaces import IStudentsUtils
    4857from waeup.sirp.university.interfaces import ICertificate
    4958from waeup.sirp.utils.helpers import string_from_bytes, file_size
     
    5160    FriendlyDateWidget, FriendlyDateDisplayWidget,
    5261    FriendlyDatetimeDisplayWidget)
     62from waeup.sirp.widgets.phonewidget import PhoneWidget
    5363from waeup.sirp.widgets.restwidget import ReSTDisplayWidget
    54 from waeup.sirp.applicants.interfaces import (
    55     IApplicant, IApplicantEdit, IApplicantsRoot,
    56     IApplicantsContainer, IApplicantsContainerAdd, application_types_vocab,
    57     MAX_UPLOAD_SIZE, IApplicantOnlinePayment,
    58     )
    59 from waeup.sirp.applicants.workflow import INITIALIZED, STARTED, PAID, SUBMITTED
    60 from waeup.sirp.students.viewlets import PrimaryStudentNavTab
    61 from waeup.sirp.students.interfaces import IStudentsUtils
    6264
    6365grok.context(ISIRPObject) # Make ISIRPObject the default context
     
    303305    text = 'Manage applicants container'
    304306
    305 #class ApplicantLoginActionButton(ManageActionButton):
    306 #    grok.order(2)
    307 #    grok.context(IApplicantsContainer)
    308 #    grok.view(ApplicantsContainerPage)
    309 #    grok.require('waeup.Anonymous')
    310 #    icon = 'login.png'
    311 #    text = 'Login for applicants'
    312 #    target = 'login'
    313 
    314307class ApplicantsContainerManageFormPage(SIRPEditFormPage):
    315308    grok.context(IApplicantsContainer)
     
    429422        self.context.addApplicant(applicant)
    430423        self.flash('Applicant record created.')
    431         self.redirect(self.url(self.context[applicant.application_number], 'index'))
     424        self.redirect(
     425            self.url(self.context[applicant.application_number], 'index'))
    432426        return
    433427
     
    520514            return
    521515        timestamp = "%d" % int(time()*1000)
    522         #order_id = "%s%s" % (student_id[1:],timestamp)
    523516        for key in self.context.keys():
    524517            ticket = self.context[key]
     
    557550    grok.require('waeup.viewApplication')
    558551    form_fields = grok.AutoFields(IApplicantOnlinePayment)
    559     form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
    560     form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
     552    form_fields[
     553        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
     554    form_fields[
     555        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
    561556    pnav = 3
    562557
     
    952947            self.flash('Successfully removed: %s' % ', '.join(deleted))
    953948            ob_class = self.__implemented__.__name__.replace('waeup.sirp.','')
    954             self.context.loggerInfo(ob_class, 'removed: % s' % ', '.join(deleted))
     949            self.context.loggerInfo(
     950                ob_class, 'removed: % s' % ', '.join(deleted))
    955951        return
    956952
     
    980976        )
    981977    form_fields['date_of_birth'].custom_widget = FriendlyDateWidget('le-year')
     978    #form_fields['phone'].custom_widget = PhoneWidget
    982979    grok.template('applicanteditpage')
    983980    manage_applications = False
     
    10911088            return open(DEFAULT_PASSPORT_IMAGE_PATH, 'rb').read()
    10921089        return image
     1090
     1091class ApplicantRegistrationSuccessful(SIRPPage):
     1092    """Info page when applicant registration was successful.
     1093    """
     1094    grok.context(IApplicantsContainer)
     1095    grok.name('register_success')
     1096    grok.require('waeup.Public')
     1097    grok.template('applicantregister_succ')
     1098    label = 'Applicant Registration Successful'
     1099    title = label
     1100
     1101    def update(self, app_id=None):
     1102        if app_id is None:
     1103            self.redirect(self.url(self.context, 'register'))
     1104        self.app_id = app_id
     1105        self.login_url = self.url(grok.getSite(), 'login')
     1106
     1107class ApplicantRegistrationPage(SIRPAddFormPage):
     1108    """Captcha'd registration page for applicants.
     1109    """
     1110    grok.context(IApplicantsContainer)
     1111    grok.name('register')
     1112    grok.require('waeup.Public')
     1113    grok.template('applicantregister')
     1114    label = 'Applicant Registration'
     1115    title = label
     1116    form_fields = grok.AutoFields(IApplicantEdit).select(
     1117        'firstname', 'middlename', 'lastname', 'email', 'phone')
     1118    form_fields['phone'].custom_widget = PhoneWidget
     1119
     1120    def update(self):
     1121        # handle captcha
     1122        self.captcha = getUtility(ICaptchaManager).getCaptcha()
     1123        self.captcha_result = self.captcha.verify(self.request)
     1124        self.captcha_code = self.captcha.display(self.captcha_result.error_code)
     1125        return
     1126
     1127    @grok.action('Register')
     1128    def register(self, **data):
     1129        if not self.captcha_result.is_valid:
     1130            # captcha will display error messages automatically.
     1131            # No need to flash something.
     1132            return
     1133
     1134        # handle password field manually
     1135        form = self.request.form
     1136        password = form.get('password', None)
     1137        password_ctl = form.get('control_password', None)
     1138        if password:
     1139            validator = getUtility(IPasswordValidator)
     1140            errors = validator.validate_password(password, password_ctl)
     1141            if errors:
     1142                self.flash( ' '.join(errors))
     1143                return
     1144
     1145        # add applicant and redirect to success page
     1146        applicant = createObject('waeup.Applicant')
     1147        self.applyData(applicant, **data)
     1148        self.context.addApplicant(applicant)
     1149        IUserAccount(applicant).setPassword(password)
     1150        app_id = applicant.applicant_id
     1151        self.redirect(self.url(self.context, 'register_success',
     1152                               data=dict(app_id=app_id)))
     1153        return
Note: See TracChangeset for help on using the changeset viewer.