# Plugin for trac 0.11
from genshi.builder import tag
from genshi.filters import Transformer
from trac.core import *
from trac.web import IRequestHandler
from trac.web import ITemplateStreamFilter
class ITicketSubmitPolicy(Interface):
def name():
"""name of the policy"""
class TicketRequires(Component):
implements(ITicketSubmitPolicy)
def name(self):
return 'requires'
class TicketExcludes(Component):
implements(ITicketSubmitPolicy)
def name(self):
return 'excludes'
class TicketSubmitPolicyPlugin(Component):
"""
get the selected option from HTML like this:
<select id="field-type" name="field_type">
<option selected="selected">defect</option><option>enhancement</option><option>task</option>
</select>
Notes to self:
Generalizing this would be:
type == defect -> requires(version)
type != defect -> excludes(version)
Does this work for http://trac.openplans.org/trac/ticket/5 and the confirmed box?
state != resolved -> excludes(confirmed)
So yes, I think
"""
implements(ITemplateStreamFilter)
policies = ExtensionPoint(ITicketSubmitPolicy)
def policy_dict(self):
retval = {}
for policy in self.policies:
retval[policy.name()] = policy
return retval
# method for ITemplateStreamFilter
def filter_stream(self, req, method, filename, stream, data):
# temporary staging ground for ticket policy behavior
# XXX things here should be abstracted
policies = [ {'contingentfield': 'type', 'value': 'defect',
'function': self.requires, 'args': [ 'version' ]},
{'contingentfield': 'type', 'value': 'defect',
'function': self.excludes, 'args': [ 'version' ]},
]
self.onload = []
policy_dict = self.policy_dict()
import pdb; pdb.set_trace()