2013-02-01 16:33:45 +01:00
|
|
|
from django.conf import settings
|
|
|
|
from django.core import exceptions
|
|
|
|
from django.utils.importlib import import_module
|
|
|
|
|
|
|
|
from openslides.config.models import config
|
|
|
|
ugettext = lambda s: s
|
|
|
|
|
|
|
|
_workflow = None
|
|
|
|
|
2013-02-02 10:52:13 +01:00
|
|
|
|
2013-02-01 16:33:45 +01:00
|
|
|
class State(object):
|
2013-02-02 10:24:28 +01:00
|
|
|
def __init__(self, id, name, next_states=[], create_poll=False, support=False,
|
2013-02-03 13:24:29 +01:00
|
|
|
edit_as_submitter=False, version_permission=True):
|
2013-02-01 16:33:45 +01:00
|
|
|
self.id = id
|
|
|
|
self.name = name
|
|
|
|
self.next_states = next_states
|
2013-02-02 10:24:28 +01:00
|
|
|
self.create_poll = create_poll
|
2013-02-01 16:33:45 +01:00
|
|
|
self.support = support
|
2013-02-02 10:52:13 +01:00
|
|
|
self.edit_as_submitter = edit_as_submitter
|
2013-02-03 13:24:29 +01:00
|
|
|
self.version_permission = version_permission
|
2013-02-01 16:33:45 +01:00
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
2013-02-02 10:52:13 +01:00
|
|
|
|
2013-02-01 16:44:06 +01:00
|
|
|
class WorkflowError(Exception):
|
|
|
|
pass
|
|
|
|
|
2013-02-01 16:33:45 +01:00
|
|
|
|
|
|
|
def motion_workflow_choices():
|
|
|
|
for workflow in settings.MOTION_WORKFLOW:
|
|
|
|
yield workflow[0], workflow[1]
|
|
|
|
|
|
|
|
|
|
|
|
def get_state(state='default'):
|
|
|
|
global _workflow
|
|
|
|
if _workflow is not None:
|
2013-02-01 17:20:11 +01:00
|
|
|
try:
|
|
|
|
return _workflow[state]
|
|
|
|
except KeyError:
|
|
|
|
raise WorkflowError('Unknown state: %s' % state)
|
2013-02-01 16:33:45 +01:00
|
|
|
_workflow = {}
|
|
|
|
for workflow in settings.MOTION_WORKFLOW:
|
|
|
|
if workflow[0] == config['motion_workflow']:
|
|
|
|
try:
|
|
|
|
wf_module, wf_default_state_name = workflow[2].rsplit('.', 1)
|
|
|
|
except ValueError:
|
|
|
|
raise exceptions.ImproperlyConfigured(
|
|
|
|
'%s isn\'t a workflow module' % workflow[2])
|
|
|
|
try:
|
|
|
|
mod = import_module(wf_module)
|
|
|
|
except ImportError as e:
|
|
|
|
raise exceptions.ImproperlyConfigured(
|
|
|
|
'Error importing workflow %s: "%s"' % (wf_module, e))
|
|
|
|
try:
|
|
|
|
default_state = getattr(mod, wf_default_state_name)
|
|
|
|
except AttributeError:
|
|
|
|
raise exceptions.ImproperlyConfigured(
|
|
|
|
'Workflow module "%s" does not define a "%s" State'
|
|
|
|
% (wf_module, wf_default_state_name))
|
|
|
|
_workflow['default'] = default_state
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
raise ImproperlyConfigured('Unknown workflow %s' % conf['motion_workflow'])
|
|
|
|
|
|
|
|
populate_workflow(default_state, _workflow)
|
|
|
|
return get_state(state)
|
|
|
|
|
2013-02-02 10:24:28 +01:00
|
|
|
|
2013-02-01 16:33:45 +01:00
|
|
|
def populate_workflow(state, workflow):
|
|
|
|
workflow[state.id] = state
|
|
|
|
for s in state.next_states:
|
|
|
|
if s.id not in workflow:
|
|
|
|
populate_workflow(s, workflow)
|
|
|
|
|
|
|
|
|
2013-02-02 10:24:28 +01:00
|
|
|
DUMMY_STATE = State('dummy', ugettext('Unknwon state'))
|
|
|
|
|
2013-02-03 13:24:29 +01:00
|
|
|
default_workflow = State('pub', ugettext('Published'), support=True,
|
|
|
|
edit_as_submitter=True, version_permission=False)
|
|
|
|
|
2013-02-03 14:14:07 +01:00
|
|
|
default_workflow.next_states = [
|
2013-02-02 10:52:13 +01:00
|
|
|
State('per', ugettext('Permitted'), create_poll=True, edit_as_submitter=True, next_states=[
|
|
|
|
State('acc', ugettext('Accepted')),
|
|
|
|
State('rej', ugettext('Rejected')),
|
|
|
|
State('wit', ugettext('Withdrawed')),
|
|
|
|
State('adj', ugettext('Adjourned')),
|
|
|
|
State('noc', ugettext('Not Concerned')),
|
|
|
|
State('com', ugettext('Commited a bill')),
|
|
|
|
State('rev', ugettext('Needs Review'))]),
|
2013-02-03 13:24:29 +01:00
|
|
|
State('nop', ugettext('Rejected (not authorized)'))]
|