Skip to content

Commit

Permalink
http://luc.lino-framework.org/blog/2017/0407.html
Browse files Browse the repository at this point in the history
  • Loading branch information
lsaffre committed Apr 7, 2017
1 parent a8b9229 commit f8168b6
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions lino_noi/lib/tickets/workflows.py
Expand Up @@ -37,7 +37,7 @@ class TicketAction(dd.ChangeStateAction):
Make sure that only *triagers* can act on tickets of other users.
"""
required_vote_states = set([])
required_vote_states = set([]) # probably deprecated
veto_vote_states = set([])

def attach_to_actor(self, *args):
Expand All @@ -56,17 +56,17 @@ def get_action_permission(self, ar, obj, state):

def before_execute(self, ar, obj):
if len(self.veto_vote_states) or len(self.required_vote_states):
has_required = False
has_required = len(self.required_vote_states) == 0
for v in rt.models.votes.Vote.objects.filter(votable=obj):
if v.state in self.required_vote_states:
has_required = True
if v.state in self.veto_vote_states:
msg = _("Cannot {action} because {vote} is {state}.")
msg = _("Cannot mark as {action} because {vote} is {state}.")
raise Warning(msg.format(
vote=v, user=v.user, action=self.label, state=v.state))

if not has_required:
msg = _("Cannot {action} because there is "
msg = _("Cannot mark as {action} because there is "
"no vote marked as {states} .")
raise Warning(msg.format(
action=self.label, states=self.required_vote_states))
Expand All @@ -83,6 +83,7 @@ def before_execute(self, ar, obj):
class MarkTicketOpened(TicketAction):
"""Mark this ticket as open.
"""
action_name = 'mark_opened'
label = pgettext("verb", "Open")
required_states = 'talk new closed'
# show_in_bbar = True
Expand All @@ -96,46 +97,40 @@ class MarkTicketOpened(TicketAction):
class MarkTicketStarted(TicketAction):
"""Mark this ticket as started.
"""
action_name = 'mark_started'
label = pgettext("verb", "Start")
required_states = 'new talk opened'

def unused_before_execute(self, ar, obj):
for v in rt.models.votes.Vote.objects.filter(votable=obj):
if v.state == rt.actors.votes.VoteStates.assigned:
return # ok
raise Warning(
_("Cannot start when nobody is assigned"))

# def get_notify_subject(self, ar, obj):
# subject = _("{user} activated {ticket}.").format(
# user=ar.get_user(), ticket=obj)
# return subject

class MarkTicketReady(TicketAction):
"""Mark this ticket as ready.
"""
action_name = 'mark_ready'
required_states = "new opened started talk"

class MarkTicketClosed(TicketAction):
"""Mark this ticket as closed.
"""
# label = pgettext("verb", "Close")
action_name = 'mark_closed'
required_states = 'talk started opened ready'
veto_vote_states = 'assigned'
required_vote_states = 'done cancelled'
# required_vote_states = 'done cancelled'

class MarkTicketRefused(TicketAction):
"""Mark this ticket as refused.
"""
required_states = 'talk started opened ready'
veto_vote_states = 'assigned'
action_name = 'mark_refused'


class MarkTicketTalk(TicketAction):
"""Mark this ticket as talk.
"""
label = pgettext("verb", "Talk")
required_states = "new opened started sleeping ready"
action_name = 'mark_talk'

# def get_notify_subject(self, ar, obj):
# subject = _("{user} wants to talk about {ticket}.").format(
Expand Down

0 comments on commit f8168b6

Please sign in to comment.