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

PIN stuff.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.