source: main/waeup.sirp/branches/accesscodes-with-workflow/src/waeup/sirp/accesscodes/workflow.py @ 6411

Last change on this file since 6411 was 6403, checked in by Henrik Bettermann, 14 years ago

Comment out the code which refers to iold invalidation and disabling methods. Make all tests work again.

File size: 3.7 KB
Line 
1##
2## workflow.py
3## Login : <uli@pu.smp.net>
4## Started on  Sat Jun 11 00:35:16 2011 Uli Fouquet
5## $Id$
6##
7## Copyright (C) 2011 Uli Fouquet
8## This program is free software; you can redistribute it and/or modify
9## it under the terms of the GNU General Public License as published by
10## the Free Software Foundation; either version 2 of the License, or
11## (at your option) any later version.
12##
13## This program is distributed in the hope that it will be useful,
14## but WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16## GNU General Public License for more details.
17##
18## You should have received a copy of the GNU General Public License
19## along with this program; if not, write to the Free Software
20## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21##
22"""
23Workflows for access codes/pins.
24"""
25import grok
26from datetime import datetime
27from hurry.workflow.workflow import Transition, WorkflowState, NullCondition
28from hurry.workflow.interfaces import IWorkflowState, IWorkflowTransitionEvent
29from waeup.sirp.accesscodes.interfaces import IAccessCode
30from waeup.sirp.interfaces import IObjectHistory, IWAeUPWorkflowInfo
31from waeup.sirp.workflow import WAeUPWorkflow, WAeUPWorkflowInfo
32
33INITIALIZED = 'initialized'
34USED = 'used'
35DISABLED = 'disabled'
36
37#def invalidate_action(wf, context):
38#    batch = getattr(context, '__parent__', None)
39#    if batch is None:
40#        return
41#    pin = context.representation
42#    batch.invalidate(pin)
43#    return
44
45#def disable_action(wf, context):
46#    batch = getattr(context, '__parent__', None)
47#    if batch is None:
48#        return
49#    pin = context.representation
50#    batch.disable(pin)
51#    return
52
53#def reenable_action(wf, context):
54#    batch = getattr(context, '__parent__', None)
55#    if batch is None:
56#        return
57#    pin = context.representation
58#    batch.enable(pin)
59#    return
60
61ACCESSCODE_TRANSITIONS = (
62    Transition(
63        transition_id = 'init',
64        title = 'Initialize PIN',
65        source = None,
66        condition = NullCondition,
67        destination = INITIALIZED),
68
69    Transition(
70        transition_id = 'use',
71        title = 'Use PIN',
72        source = INITIALIZED,
73        destination = USED),
74        #action = invalidate_action),
75
76    Transition(
77        transition_id = 'disable_unused',
78        title = 'Disable unused PIN',
79        source = INITIALIZED,
80        destination = DISABLED),
81        #action = disable_action),
82
83    Transition(
84        transition_id = 'disable_used',
85        title = 'Disable used PIN',
86        source = USED,
87        destination = DISABLED),
88        #action = disable_action),
89
90    Transition(
91        transition_id = 'reenable',
92        title = 'Reenable disabled PIN',
93        source = DISABLED,
94        destination = INITIALIZED),
95        #action = reenable_action),
96    )
97
98accesscode_workflow = WAeUPWorkflow(ACCESSCODE_TRANSITIONS)
99
100class AccessCodeWorkflowState(WorkflowState, grok.Adapter):
101    grok.context(IAccessCode)
102    grok.provides(IWorkflowState)
103
104    state_key = 'wf.accesscode.state'
105    state_id = 'wf.accesscode.id'
106
107class AccessCodeWorkflowInfo(WAeUPWorkflowInfo, grok.Adapter):
108    grok.context(IAccessCode)
109    grok.provides(IWAeUPWorkflowInfo)
110
111    def __init__(self, context):
112        self.context = context
113        self.wf = accesscode_workflow
114
115@grok.subscribe(IAccessCode, IWorkflowTransitionEvent)
116def handle_accesscode_transition_event(obj, event):
117    # append message to history
118    timestamp = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
119    msg = '%s - %s (new state: %s)' % (
120        timestamp, event.destination.title, event.destination)
121    history = IObjectHistory(obj)
122    history.addMessage(msg)
123    return
Note: See TracBrowser for help on using the repository browser.