- Timestamp:
- 16 Jun 2011, 18:54:14 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.py
r6379 r6380 448 448 return code 449 449 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 """ 450 def _fire_transition(info, arg, toward=False): 484 451 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 500 458 return True 501 459 … … 503 461 """Invalidate AccessCode denoted by string ``access_code``. 504 462 463 The access code that belongs to the passed string must exist. 464 505 465 Fires an appropriate transition to perform the task. 506 466 507 See :func:`fire_transition` for possible exceptions and their 508 meanings. 467 Returns ``True`` if the ac was invalidated, ``False`` else. 509 468 """ 510 return fire_transition(access_code, 'use') 469 ac = get_access_code(access_code) 470 info = IWorkflowInfo(ac) 471 return _fire_transition(info, 'use') 511 472 512 473 def disable_accesscode(access_code): 513 474 """Disable AccessCode denoted by string ``access_code``. 514 475 476 The access code that belongs to the passed string must exist. 477 515 478 Fires an appropriate transition to perform the task. 516 479 517 See :func:`fire_transition` for possible exceptions and their 518 meanings. 480 Returns ``True`` if the ac was disabled, ``False`` else. 519 481 """ 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) 521 485 522 486 def reenable_accesscode(access_code): 523 487 """Reenable AccessCode denoted by string ``access_code``. 524 488 489 The access code that belongs to the passed string must exist. 490 525 491 Fires an appropriate transition to perform the task. 526 492 527 See :func:`fire_transition` for possible exceptions and their 528 meanings. 493 Returns ``True`` if the ac was reenabled, ``False`` else. 529 494 """ 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.