Changeset 6408
- Timestamp:
- 19 Jun 2011, 22:44:54 (14 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/accesscodes
- Files:
-
- 1 edited
- 5 copied
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.py
r6387 r6408 394 394 return code 395 395 396 def _fire_transition(info, arg, toward=False): 396 def fire_transition(access_code, arg, toward=False): 397 """Fire workflow transition for access code. 398 399 The access code instance is looked up via `access_code` (a string 400 like ``APP-1-12345678``). 401 402 `arg` tells what kind of transition to trigger. This will be a 403 transition id like ``'use'`` or ``'init'``, or some transition 404 target like :var:`waeup.sirp.accesscodes.workflow.INITIALIZED`. 405 406 If `toward` is ``False`` (the default) you have to pass a 407 transition id as `arg`, otherwise you must give a transition 408 target. 409 410 :func:`fire_transition` might raise exceptions depending on the 411 reason why the requested transition cannot be performed. 412 413 The following exceptions can occur during processing: 414 415 :exc:`KeyError`: 416 signals not existent access code, batch or site. 417 418 :exc:`ValueError`: 419 signals illegal format of `access_code` string. The regular format is 420 ``APP-N-XXXXXXXX``. 421 422 :exc:`hurry.workflow.interfaces.InvalidTransitionError`: 423 the transition requested cannot be performed because the workflow 424 rules forbid it. 425 426 :exc:`Unauthorized`: 427 the current user is not allowed to perform the requested transition. 428 429 """ 397 430 try: 398 if toward: 399 info.fireTransitionToward(arg) 400 else: 401 info.fireTransition(arg) 402 except InvalidTransitionError: 403 return False 431 batch_id, ac_id = access_code.rsplit('-', 1) 432 except ValueError: 433 raise ValueError( 434 'Invalid access code format: %s (use: APP-N-XXXXXXXX)' % ( 435 access_code,)) 436 try: 437 ac = grok.getSite()['accesscodes'][batch_id].getAccessCode(access_code) 438 except TypeError: 439 raise KeyError( 440 'No site available for looking up accesscodes') 441 info = IWorkflowInfo(ac) 442 if toward: 443 info.fireTransitionToward(arg) 444 else: 445 info.fireTransition(arg) 404 446 return True 405 447 … … 407 449 """Invalidate AccessCode denoted by string ``access_code``. 408 450 409 The access code that belongs to the passed string must exist.410 411 451 Fires an appropriate transition to perform the task. 412 452 413 Returns ``True`` if the ac was invalidated, ``False`` else. 453 See :func:`fire_transition` for possible exceptions and their 454 meanings. 414 455 """ 415 456 ac = get_access_code(access_code) … … 423 464 """Disable AccessCode denoted by string ``access_code``. 424 465 425 The access code that belongs to the passed string must exist.426 427 466 Fires an appropriate transition to perform the task. 428 467 429 Returns ``True`` if the ac was disabled, ``False`` else. 430 """ 431 ac = get_access_code(access_code) 432 info = IWorkflowInfo(ac) 433 return _fire_transition(info, DISABLED, toward=True) 468 See :func:`fire_transition` for possible exceptions and their 469 meanings. 470 """ 471 return fire_transition(access_code, DISABLED, toward=True) 434 472 435 473 def reenable_accesscode(access_code): 436 474 """Reenable AccessCode denoted by string ``access_code``. 437 475 438 The access code that belongs to the passed string must exist.439 440 476 Fires an appropriate transition to perform the task. 441 477 442 Returns ``True`` if the ac was reenabled, ``False`` else. 443 """ 444 ac = get_access_code(access_code) 445 info = IWorkflowInfo(ac) 446 return _fire_transition(info, 'reenable') 478 See :func:`fire_transition` for possible exceptions and their 479 meanings. 480 """ 481 return fire_transition(access_code, 'reenable')
Note: See TracChangeset for help on using the changeset viewer.