1
from genshi.builder import tag
3
from trac.core import implements,Component
4
from trac.ticket.api import ITicketActionController
5
from trac.ticket.default_workflow import ConfigurableTicketWorkflow
6
from trac.ticket.model import Priority, Ticket
7
#from trac.perm import IPermissionRequestor # (TODO)
9
revision = "$Rev: 6326 $"
10
url = "$URL: http://svn.edgewall.org/repos/trac/branches/0.11-stable/sample-plugins/workflow/VoteOperation.py $"
12
class VoteOperation(Component):
13
"""Provides a simplistic vote feature.
15
This is a sample action controller illustrating how to create additional
18
Don't forget to add `VoteOperation` to the workflow option in [ticket].
19
If there is no workflow option, the line will look like this:
21
workflow = ConfigurableTicketWorkflow,VoteOperation
24
implements(ITicketActionController)
26
def get_ticket_actions(self, req, ticket):
27
controller = ConfigurableTicketWorkflow(self.env)
28
return controller.get_actions_by_operation_for_req(req, ticket, 'vote')
30
def get_all_status(self):
33
def render_ticket_action_control(self, req, ticket, action):
34
id = 'vote_%s_result' % (action, )
35
selected_value = req.args.get(id, 'for')
36
options = ['for', 'against']
38
tag.select([tag.option(x, selected=(x == selected_value or
40
for x in options], name=id, id=id),
41
"Vote on the issue, raising or lowering its priority")
43
def get_ticket_changes(self, req, ticket, action):
44
id = 'vote_%s_result' % (action, )
45
selected = req.args.get(id, 'for')
46
priorities = list(Priority.select(self.env))
47
orig_ticket = Ticket(self.env, ticket.id)
48
current_priority = int(Priority(self.env, name=
49
orig_ticket['priority']).value)
51
# priorities are 1-based, not 0-based
52
new_value = max(1, current_priority - 1)
54
maxval = max([int(p.value) for p in priorities])
55
new_value = min(maxval, current_priority + 1)
56
return {'priority': [p.name for p in priorities
57
if int(p.value) == new_value][0]}
59
def apply_action_side_effects(self, req, ticket, action):