Ignore:
Timestamp:
15 Jun 2011, 23:45:04 (13 years ago)
Author:
uli
Message:

Improve accesscode triggers.

File:
1 edited

Legend:

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

    r6359 r6374  
    66from BTrees.OIBTree import OIBTree
    77from datetime import datetime
    8 from hurry.workflow.interfaces import IWorkflowInfo
     8from hurry.workflow.interfaces import IWorkflowInfo, InvalidTransitionError
    99from random import SystemRandom as random
    1010from waeup.sirp.interfaces import IWAeUPSIRPPluggable
     
    1212    IAccessCode, IAccessCodeBatch, IAccessCodeBatchContainer
    1313    )
    14 from waeup.sirp.accesscodes.workflow import DISABLED
     14from waeup.sirp.accesscodes.workflow import DISABLED, INITIALIZED
    1515
    1616class ManageACBatches(grok.Permission):
     
    448448    return code
    449449
     450def _fire_transition(info, arg, toward=False):
     451    try:
     452        if toward:
     453            info.fireTransitionToward(arg)
     454        else:
     455            info.fireTransition(arg)
     456    except InvalidTransitionError:
     457        return False
     458    return True
     459
    450460def invalidate_accesscode(access_code):
     461    """Invalidate AccessCode denoted by string ``access_code``.
     462
     463    The access code that belongs to the passed string must exist.
     464
     465    Fires an appropriate transition to perform the task.
     466
     467    Returns ``True`` if the ac was invalidated, ``False`` else.
     468    """
    451469    ac = get_access_code(access_code)
    452470    info = IWorkflowInfo(ac)
    453     info.fireTransition('use')
    454     return
     471    return _fire_transition(info, 'use')
    455472
    456473def disable_accesscode(access_code):
     474    """Disable AccessCode denoted by string ``access_code``.
     475
     476    The access code that belongs to the passed string must exist.
     477
     478    Fires an appropriate transition to perform the task.
     479
     480    Returns ``True`` if the ac was disabled, ``False`` else.
     481    """
    457482    ac = get_access_code(access_code)
    458483    info = IWorkflowInfo(ac)
    459     info.fireTransitionToward(DISABLED)
    460     return
     484    return _fire_transition(info, DISABLED, toward=True)
    461485
    462486def reenable_accesscode(access_code):
     487    """Reenable AccessCode denoted by string ``access_code``.
     488
     489    The access code that belongs to the passed string must exist.
     490
     491    Fires an appropriate transition to perform the task.
     492
     493    Returns ``True`` if the ac was reenabled, ``False`` else.
     494    """
    463495    ac = get_access_code(access_code)
    464496    info = IWorkflowInfo(ac)
    465     info.fireTransition('reenable')
    466     return
     497    return _fire_transition(info, 'reenable')
Note: See TracChangeset for help on using the changeset viewer.