Coverage for lino/core/workflows.py : 62%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: UTF-8 -*- # Copyright 2012-2016 Luc Saffre # License: BSD (see file COPYING for details) :class:`State` and :class:`Workflow`, :class:`ChangeStateAction`.
""" # import six # str = six.text_type
# from django.utils.encoding import force_text # from django.utils.functional import lazy # def _string_format(tpl, *args, **kwargs): # args = tuple([force_text(s) for s in args]) # return tpl.format(*args, **kwargs) # string_format = lazy(_string_format, basestring)
"""A `State` is a specialized :class:`Choice <lino.core.choicelists.Choice>` that adds the :meth:`add_transition` method.
"""
help_text=None, notify=False, name=None, #~ icon_file=None, icon_name=None, debug_permissions=None, required_states=None, required_roles=None): """Declare or create a `ChangeStateAction` which makes the object enter this state. `label` can be either a string or a subclass of :class:`ChangeStateAction`.
You can specify an explicit `name` in order to allow replacing the transition action later by another action.
""" #~ name = 'mark_' + self.value
raise Exception( "Duplicate transition name {0}".format(name))
kw.update(help_text=help_text) kw.update(icon_name=icon_name) # it's a subclass of ChangeStateAction assert isinstance(label, type) assert issubclass(label, ChangeStateAction) if required_roles: raise Exception( "Cannot specify requirements when using your own class") if required_states: raise Exception( "Cannot specify requirements when using your own class") if notify: raise Exception( "Cannot specify notify=True when using your own class") if debug_permissions: raise Exception( "Cannot specify debug_permissions " "when using your own class") for a in workflow_actions: if isinstance(a, label): raise Exception("Duplicate transition label %s" % a) a = label(self, **kw) else: cl = NotifyingChangeStateAction else: label = self.text a.debug_permissions = debug_permissions
"""A Workflow is a specialized ChoiceList used for defining the states of a workflow.
"""
def on_analyze(cls, site): """Add workflow actions to the models using this workflow so that we can access them as InstanceActions.
""" # logger.info("20150602 Workflow.on_analyze %s", cls) # logger.info("20150602 %s, %s", model, cls.workflow_actions) # if not a.action_name.startswith('wf'):
def before_state_change(cls, obj, ar, oldstate, newstate): pass
def after_state_change(cls, obj, ar, oldstate, newstate): pass
def override_transition(cls, **kw): """ """ for name, cl in list(kw.items()): found = False for i, a in enumerate(cls.workflow_actions): if a.action_name == name: new = cl( a.target_state, a.required_roles, sort_index=a.sort_index) new.attach_to_workflow(cls, name) cls.workflow_actions[i] = new found = True break if not found: raise Exception( "There is no workflow action named {0}".format(name))
"""This is the class used when generating automatic "state actions". For each possible value of the Actor's :attr:`workflow_state_field` there will be an automatic action called `mark_XXX`
"""
help_text=None, **kw): new_required |= required_roles
raise Exception("20150621 was allow_transition still used?!") assert 'allowed' not in required_roles
def allow(action, user, obj, state): return m(obj, user, target_state) new_required.update(allow=allow)
# help_text = string_format( # _("Mark this as {0}"), target_state.text) _("Mark this as"), ' ', target_state.text)
#~ logger.info('20120930 ChangeStateAction %s %s', actor,target_state) self.help_text = string_concat(self.label, '. ', self.help_text)
for row in ar.selected_rows: self.execute(ar, row) ar.set_response(refresh=True) ar.success()
return obj.set_workflow_state( ar, ar.actor.workflow_state_field, self.target_state)
|