Changeset 6359 for main/waeup.sirp/trunk


Ignore:
Timestamp:
12 Jun 2011, 12:00:19 (14 years ago)
Author:
uli
Message:

PIN stuff.

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/__init__.py

    r5447 r6359  
    11# Make this a package.
    2 from waeup.sirp.accesscodes.accesscodes import get_access_code
     2from waeup.sirp.accesscodes.accesscodes import (
     3    get_access_code, invalidate_accesscode)
    34
    45# Public API of this submodule
    56__all__ = [
    6     get_access_code
     7    get_access_code,
     8    invalidate_accesscode,
    79    ]
    810
  • main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.py

    r6124 r6359  
    66from BTrees.OIBTree import OIBTree
    77from datetime import datetime
     8from hurry.workflow.interfaces import IWorkflowInfo
    89from random import SystemRandom as random
    910from waeup.sirp.interfaces import IWAeUPSIRPPluggable
     
    1112    IAccessCode, IAccessCodeBatch, IAccessCodeBatchContainer
    1213    )
     14from waeup.sirp.accesscodes.workflow import DISABLED
    1315
    1416class ManageACBatches(grok.Permission):
    1517    grok.name('waeup.manageACBatches')
    1618
    17 class AccessCode(grok.Context):
     19class AccessCode(grok.Model):
    1820    grok.implements(IAccessCode)
    1921
     
    2527        self.student_id = student_id
    2628        self._disabled = disabled
     29        IWorkflowInfo(self).fireTransition('init')
    2730
    2831    @property
     
    155158        self.invalidated_num += 1
    156159
    157     def disable(self, ac_id, user_id):
     160    def disable(self, ac_id, user_id=None):
    158161        """Disable the AC with ID ``ac_id``.
    159162
     
    389392        return
    390393
     394    def invalidate(self, ac_id):
     395        """Invalidate the AC with ID ``ac_id``.
     396        """
     397        ac = self.getAccessCode(ac_id)
     398        if ac is None:
     399            return
     400        ac.__parent__.invalidate(ac_id)
     401        return
     402
    391403
    392404class AccessCodePlugin(grok.GlobalUtility):
     
    430442    if batch is None:
    431443        return None
    432 
    433444    try:
    434445        code = batch.getAccessCode(access_code)
     
    436447        return None
    437448    return code
     449
     450def invalidate_accesscode(access_code):
     451    ac = get_access_code(access_code)
     452    info = IWorkflowInfo(ac)
     453    info.fireTransition('use')
     454    return
     455
     456def disable_accesscode(access_code):
     457    ac = get_access_code(access_code)
     458    info = IWorkflowInfo(ac)
     459    info.fireTransitionToward(DISABLED)
     460    return
     461
     462def reenable_accesscode(access_code):
     463    ac = get_access_code(access_code)
     464    info = IWorkflowInfo(ac)
     465    info.fireTransition('reenable')
     466    return
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser.py

    r6358 r6359  
    3232
    3333from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
    34 
    3534from reportlab.pdfgen import canvas
    3635
     36from waeup.sirp.accesscodes import invalidate_accesscode
    3737from waeup.sirp.browser import (
    3838    WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage, WAeUPDisplayFormPage)
     
    415415            return
    416416        pin = self.request.principal.access_code
    417         if pin not in self.context.keys():
    418             # Create applicant record
    419             applicant = Applicant()
    420             applicant.access_code = pin
    421             self.context[pin] = applicant
     417        if pin in self.context.keys():
     418            self.redirect(self.url(self.context[pin], 'edit'))
     419            return
     420
     421        # Mark pin as used
     422        invalidate_accesscode(pin)
     423
     424        # Create applicant record
     425        applicant = Applicant()
     426        applicant.access_code = pin
     427        self.context[pin] = applicant
     428
    422429        # Assign current principal the owner role on created applicant
    423430        # record
Note: See TracChangeset for help on using the changeset viewer.