~ubuntu-branches/ubuntu/precise/trac/precise

« back to all changes in this revision

Viewing changes to sample-plugins/workflow/VoteOperation.py

  • Committer: Bazaar Package Importer
  • Author(s): Luis Matos
  • Date: 2008-07-13 23:46:20 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080713234620-13ynpdpkbaymfg1z
Tags: 0.11-2
* Re-added python-setup-tools to build dependences. Closes: #490320 #468705
* New upstream release Closes: 489727
* Added sugestion for other vcs support available: git bazaar mercurial 
* Added spamfilter plugin to sugests
* Moved packaging from python-support to python-central
* Added an entry to the NEWS about the cgi Closes: #490275
* Updated 10_remove_trac_suffix_from_title patch to be used in 0.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from genshi.builder import tag
 
2
 
 
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)
 
8
 
 
9
revision = "$Rev: 6326 $"
 
10
url = "$URL: http://svn.edgewall.org/repos/trac/branches/0.11-stable/sample-plugins/workflow/VoteOperation.py $"
 
11
 
 
12
class VoteOperation(Component):
 
13
    """Provides a simplistic vote feature.
 
14
 
 
15
    This is a sample action controller illustrating how to create additional
 
16
    ''operations''.
 
17
 
 
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:
 
20
 
 
21
    workflow = ConfigurableTicketWorkflow,VoteOperation
 
22
    """
 
23
    
 
24
    implements(ITicketActionController)
 
25
 
 
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')
 
29
 
 
30
    def get_all_status(self):
 
31
        return []
 
32
 
 
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']
 
37
        return ("vote",
 
38
                tag.select([tag.option(x, selected=(x == selected_value or
 
39
                                                    None))
 
40
                            for x in options], name=id, id=id),
 
41
                "Vote on the issue, raising or lowering its priority")
 
42
 
 
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)
 
50
        if selected == 'for':
 
51
            # priorities are 1-based, not 0-based
 
52
            new_value = max(1, current_priority - 1)
 
53
        else:
 
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]}
 
58
 
 
59
    def apply_action_side_effects(self, req, ticket, action):
 
60
        pass