Changeset 6380 for main


Ignore:
Timestamp:
16 Jun 2011, 18:54:14 (13 years ago)
Author:
uli
Message:

Rollback 6379 (too complicated)

File:
1 edited

Legend:

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

    r6379 r6380  
    448448    return code
    449449
    450 def fire_transition(access_code, arg, toward=False):
    451     """Fire workflow transition for access code.
    452 
    453     The access code instance is looked up via `access_code` (a string
    454     like ``APP-1-12345678``).
    455 
    456     `arg` tells what kind of transition to trigger. This will be a
    457     transition id like ``'use'`` or ``'init'``, or some transition
    458     target like :var:`waeup.sirp.accesscodes.workflow.INITIALIZED`.
    459 
    460     If `toward` is ``False`` (the default) you have to pass a
    461     transition id as `arg`, otherwise you must give a transition
    462     target.
    463 
    464     :func:`fire_transition` might raise exceptions depending on the
    465     reason why the requested transition cannot be performed.
    466 
    467     The following exceptions can occur during processing:
    468 
    469     :exc:`KeyError`:
    470       signals not existent access code, batch or site.
    471 
    472     :exc:`ValueError`:
    473       signals illegal format of `access_code` string. The regular format is
    474       ``APP-N-XXXXXXXX``.
    475 
    476     :exc:`hurry.workflow.interfaces.InvalidTransitionError`:
    477       the transition requested cannot be performed because the workflow
    478       rules forbid it.
    479 
    480     :exc:`Unauthorized`:
    481       the current user is not allowed to perform the requested transition.
    482 
    483     """
     450def _fire_transition(info, arg, toward=False):
    484451    try:
    485         batch_id, ac_id = access_code.rsplit('-', 1)
    486     except ValueError:
    487         raise ValueError(
    488             'Invalid access code format: %s (use: APP-N-XXXXXXXX)' % (
    489                 access_code,))
    490     try:
    491         ac = grok.getSite()['accesscodes'][batch_id].getAccessCode(access_code)
    492     except TypeError:
    493         raise KeyError(
    494             'No site available for looking up accesscodes')
    495     info = IWorkflowInfo(ac)
    496     if toward:
    497         info.fireTransitionToward(arg)
    498     else:
    499         info.fireTransition(arg)
     452        if toward:
     453            info.fireTransitionToward(arg)
     454        else:
     455            info.fireTransition(arg)
     456    except InvalidTransitionError:
     457        return False
    500458    return True
    501459
     
    503461    """Invalidate AccessCode denoted by string ``access_code``.
    504462
     463    The access code that belongs to the passed string must exist.
     464
    505465    Fires an appropriate transition to perform the task.
    506466
    507     See :func:`fire_transition` for possible exceptions and their
    508     meanings.
     467    Returns ``True`` if the ac was invalidated, ``False`` else.
    509468    """
    510     return fire_transition(access_code, 'use')
     469    ac = get_access_code(access_code)
     470    info = IWorkflowInfo(ac)
     471    return _fire_transition(info, 'use')
    511472
    512473def disable_accesscode(access_code):
    513474    """Disable AccessCode denoted by string ``access_code``.
    514475
     476    The access code that belongs to the passed string must exist.
     477
    515478    Fires an appropriate transition to perform the task.
    516479
    517     See :func:`fire_transition` for possible exceptions and their
    518     meanings.
     480    Returns ``True`` if the ac was disabled, ``False`` else.
    519481    """
    520     return fire_transition(access_code, DISABLED, toward=True)
     482    ac = get_access_code(access_code)
     483    info = IWorkflowInfo(ac)
     484    return _fire_transition(info, DISABLED, toward=True)
    521485
    522486def reenable_accesscode(access_code):
    523487    """Reenable AccessCode denoted by string ``access_code``.
    524488
     489    The access code that belongs to the passed string must exist.
     490
    525491    Fires an appropriate transition to perform the task.
    526492
    527     See :func:`fire_transition` for possible exceptions and their
    528     meanings.
     493    Returns ``True`` if the ac was reenabled, ``False`` else.
    529494    """
    530     return fire_transition(access_code, 'reenable')
     495    ac = get_access_code(access_code)
     496    info = IWorkflowInfo(ac)
     497    return _fire_transition(info, 'reenable')
Note: See TracChangeset for help on using the changeset viewer.