本文整理汇总了Python中trac.ticket.api.TicketSystem.get_ticket_fields方法的典型用法代码示例。如果您正苦于以下问题:Python TicketSystem.get_ticket_fields方法的具体用法?Python TicketSystem.get_ticket_fields怎么用?Python TicketSystem.get_ticket_fields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.ticket.api.TicketSystem
的用法示例。
在下文中一共展示了TicketSystem.get_ticket_fields方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from trac.ticket.api import TicketSystem [as 别名]
# 或者: from trac.ticket.api.TicketSystem import get_ticket_fields [as 别名]
def __init__(self):
self.log.debug('Starting Sqa Testing System API')
ts = TicketSystem(self.env)
'''
When the object is created collect
a set of tickets configured in this
running instance of track
'''
self.ticket_fields = ts.get_ticket_fields()
示例2: _translation_deactivated
# 需要导入模块: from trac.ticket.api import TicketSystem [as 别名]
# 或者: from trac.ticket.api.TicketSystem import get_ticket_fields [as 别名]
def _translation_deactivated(ticket=None):
t = deactivate()
if ticket is not None:
ts = TicketSystem(ticket.env)
translated_fields = ticket.fields
ticket.fields = ts.get_ticket_fields()
try:
yield
finally:
if ticket is not None:
ticket.fields = translated_fields
reactivate(t)
示例3: _get_ticket_fields
# 需要导入模块: from trac.ticket.api import TicketSystem [as 别名]
# 或者: from trac.ticket.api.TicketSystem import get_ticket_fields [as 别名]
def _get_ticket_fields(self, data):
""" Return a list of the ticket fields corresponding to the output columns
The data returned is used for ticket field input
"""
ts = TicketSystem(self.env)
fields = ts.get_ticket_fields()
results = []
for header in data['headers'][1:]:
for field in fields:
if field['name'] == header['name']:
results.append(field)
continue
continue
return results
示例4: TicketSystemTestCase
# 需要导入模块: from trac.ticket.api import TicketSystem [as 别名]
# 或者: from trac.ticket.api.TicketSystem import get_ticket_fields [as 别名]
class TicketSystemTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub(default_data=True)
self.perm = PermissionSystem(self.env)
self.ticket_system = TicketSystem(self.env)
self.req = Mock()
def tearDown(self):
self.env.reset_db()
def _get_actions(self, ticket_dict):
ts = TicketSystem(self.env)
ticket = Ticket(self.env)
ticket.populate(ticket_dict)
id = ticket.insert()
return ts.get_available_actions(self.req, Ticket(self.env, id))
def _get_ticket_field(self, field_name):
fields = TicketSystem(self.env).get_ticket_fields()
return (i for i in fields if i['name'] == field_name).next()
def test_custom_field_text(self):
self.env.config.set('ticket-custom', 'test', 'text')
self.env.config.set('ticket-custom', 'test.label', 'Test')
self.env.config.set('ticket-custom', 'test.value', 'Foo bar')
self.env.config.set('ticket-custom', 'test.format', 'wiki')
fields = TicketSystem(self.env).get_custom_fields()
self.assertEqual({'name': 'test', 'type': 'text', 'label': 'Test',
'value': 'Foo bar', 'order': 0, 'format': 'wiki',
'custom': True},
fields[0])
def test_custom_field_select(self):
self.env.config.set('ticket-custom', 'test', 'select')
self.env.config.set('ticket-custom', 'test.label', 'Test')
self.env.config.set('ticket-custom', 'test.value', '1')
self.env.config.set('ticket-custom', 'test.options', 'option1|option2')
fields = TicketSystem(self.env).get_custom_fields()
self.assertEqual({'name': 'test', 'type': 'select', 'label': 'Test',
'value': '1', 'options': ['option1', 'option2'],
'order': 0, 'custom': True},
fields[0])
def test_custom_field_optional_select(self):
self.env.config.set('ticket-custom', 'test', 'select')
self.env.config.set('ticket-custom', 'test.label', 'Test')
self.env.config.set('ticket-custom', 'test.value', '1')
self.env.config.set('ticket-custom', 'test.options', '|option1|option2')
fields = TicketSystem(self.env).get_custom_fields()
self.assertEqual({'name': 'test', 'type': 'select', 'label': 'Test',
'value': '1', 'options': ['option1', 'option2'],
'order': 0, 'optional': True, 'custom': True},
fields[0])
def test_custom_field_textarea(self):
self.env.config.set('ticket-custom', 'test', 'textarea')
self.env.config.set('ticket-custom', 'test.label', 'Test')
self.env.config.set('ticket-custom', 'test.value', 'Foo bar')
self.env.config.set('ticket-custom', 'test.rows', '4')
self.env.config.set('ticket-custom', 'test.format', 'wiki')
fields = TicketSystem(self.env).get_custom_fields()
self.assertEqual({'name': 'test', 'type': 'textarea', 'label': 'Test',
'value': 'Foo bar', 'height': 4, 'order': 0,
'format': 'wiki', 'custom': True},
fields[0])
def test_custom_field_time(self):
self.env.config.set('ticket-custom', 'test', 'time')
self.env.config.set('ticket-custom', 'test.label', 'Test')
self.env.config.set('ticket-custom', 'test.value', '')
fields = TicketSystem(self.env).get_custom_fields()
self.assertEqual({'name': 'test', 'type': 'time', 'label': 'Test',
'value': '', 'order': 0, 'format': 'datetime',
'custom': True},
fields[0])
def test_custom_field_order(self):
self.env.config.set('ticket-custom', 'test1', 'text')
self.env.config.set('ticket-custom', 'test1.order', '2')
self.env.config.set('ticket-custom', 'test2', 'text')
self.env.config.set('ticket-custom', 'test2.order', '1')
fields = TicketSystem(self.env).get_custom_fields()
self.assertEqual('test2', fields[0]['name'])
self.assertEqual('test1', fields[1]['name'])
def test_custom_field_label(self):
self.env.config.set('ticket-custom', '_test_one', 'text')
self.env.config.set('ticket-custom', 'test_two', 'text')
self.env.config.set('ticket-custom', 'test_two.label', 'test_2')
fields = TicketSystem(self.env).get_custom_fields()
self.assertEqual('Test one', fields[0]['label'])
self.assertEqual('test_2', fields[1]['label'])
def test_available_actions_full_perms(self):
self.perm.grant_permission('anonymous', 'TICKET_CREATE')
self.perm.grant_permission('anonymous', 'TICKET_MODIFY')
self.req.perm = PermissionCache(self.env)
self.assertEqual(['leave', 'resolve', 'reassign', 'accept'],
self._get_actions({'status': 'new'}))
#.........这里部分代码省略.........
示例5: _header_fields
# 需要导入模块: from trac.ticket.api import TicketSystem [as 别名]
# 或者: from trac.ticket.api.TicketSystem import get_ticket_fields [as 别名]
def _header_fields(self, ticket):
headers = self.ticket_email_header_fields
if len(headers) and headers[0].strip() == '*':
tsystem = TicketSystem(self.env)
headers = map(lambda x: x['name'], tsystem.get_ticket_fields())
return headers
示例6: update
# 需要导入模块: from trac.ticket.api import TicketSystem [as 别名]
# 或者: from trac.ticket.api.TicketSystem import get_ticket_fields [as 别名]
def update(self, req, id, comment, attributes={}, notify=False, author='', when=None):
""" Update a ticket, returning the new ticket in the same form as
get(). 'New-style' call requires two additional items in attributes:
(1) 'action' for workflow support (including any supporting fields
as retrieved by getActions()),
(2) '_ts' changetime token for detecting update collisions (as received
from get() or update() calls).
''Calling update without 'action' and '_ts' changetime token is
deprecated, and will raise errors in a future version.'' """
t = model.Ticket(self.env, id)
# custom author?
if author and not (req.authname == 'anonymous' \
or 'TICKET_ADMIN' in req.perm(t.resource)):
# only allow custom author if anonymous is permitted or user is admin
self.log.warn("RPC ticket.update: %r not allowed to change author "
"to %r for comment on #%d", req.authname, author, id)
author = ''
author = author or req.authname
# custom change timestamp?
if when and not 'TICKET_ADMIN' in req.perm(t.resource):
self.log.warn("RPC ticket.update: %r not allowed to update #%d with "
"non-current timestamp (%r)", author, id, when)
when = None
when = when or to_datetime(None, utc)
# and action...
if not 'action' in attributes:
# FIXME: Old, non-restricted update - remove soon!
self.log.warning("Rpc ticket.update for ticket %d by user %s " \
"has no workflow 'action'." % (id, req.authname))
req.perm(t.resource).require('TICKET_MODIFY')
time_changed = attributes.pop('_ts', None)
if time_changed and \
str(time_changed) != str(to_utimestamp(t.time_changed)):
raise TracError("Ticket has been updated since last get().")
for k, v in attributes.iteritems():
t[k] = v
t.save_changes(author, comment, when=when)
else:
ts = TicketSystem(self.env)
tm = TicketModule(self.env)
# TODO: Deprecate update without time_changed timestamp
time_changed = attributes.pop('_ts', to_utimestamp(t.time_changed))
try:
time_changed = int(time_changed)
except ValueError:
raise TracError("RPC ticket.update: Wrong '_ts' token " \
"in attributes (%r)." % time_changed)
action = attributes.get('action')
avail_actions = ts.get_available_actions(req, t)
if not action in avail_actions:
raise TracError("Rpc: Ticket %d by %s " \
"invalid action '%s'" % (id, req.authname, action))
controllers = list(tm._get_action_controllers(req, t, action))
all_fields = [field['name'] for field in ts.get_ticket_fields()]
for k, v in attributes.iteritems():
if k in all_fields and k != 'status':
t[k] = v
# TicketModule reads req.args - need to move things there...
req.args.update(attributes)
req.args['comment'] = comment
# Collision detection: 0.11+0.12 timestamp
req.args['ts'] = str(from_utimestamp(time_changed))
# Collision detection: 0.13/1.0+ timestamp
req.args['view_time'] = str(time_changed)
changes, problems = tm.get_ticket_changes(req, t, action)
for warning in problems:
add_warning(req, "Rpc ticket.update: %s" % warning)
valid = problems and False or tm._validate_ticket(req, t)
if not valid:
raise TracError(
" ".join([warning for warning in req.chrome['warnings']]))
else:
tm._apply_ticket_changes(t, changes)
self.log.debug("Rpc ticket.update save: %s" % repr(t.values))
t.save_changes(author, comment, when=when)
# Apply workflow side-effects
for controller in controllers:
controller.apply_action_side_effects(req, t, action)
if notify:
try:
tn = TicketNotifyEmail(self.env)
tn.notify(t, newticket=False, modtime=when)
except Exception, e:
self.log.exception("Failure sending notification on change of "
"ticket #%s: %s" % (t.id, e))
示例7: expand_macro
# 需要导入模块: from trac.ticket.api import TicketSystem [as 别名]
# 或者: from trac.ticket.api.TicketSystem import get_ticket_fields [as 别名]
def expand_macro(self, formatter, name, content, args=[]):
try:
cols = [] # Sentinel
group = '' # Sentinel
groups = {}
lines = content.split('\r\n')
for line in lines:
if line.startswith('||= href =||= '):
cols = line[14:].split(' =||= ')
elif line.startswith('|| group: '):
group = line[10:]
if group in [u'', u'None']:
group = None
groups[group] = [] # initialize for the group
elif line.startswith('|| '):
values = iter(line[3:].split(' || '))
ticket = {'href': values.next()}
for col in cols:
ticket[col] = values.next()
groups[group].append(ticket)
else:
pass
ticketsystem = TicketSystem(self.env)
#
labels = ticketsystem.get_ticket_field_labels()
headers = [{'name': col, 'label': labels.get(col, _('Ticket'))} for col in cols]
#
fields = {}
ticket_fields = ticketsystem.get_ticket_fields()
for field in ticket_fields:
fields[field['name']] = {'label': field['label']} # transform list to expected dict
# fail safe
fields[None] = 'NONE'
for group in groups.keys():
if not 'group' in fields:
fields[group] = group
#
group_name = 'group' in args and args['group'] or None
if group_name not in fields:
group_name = None
query = {'group': group_name}
#
groups = [(name, groups[name]) for name in groups] # transform dict to expected tuple
#
data = {
'paginator': None,
'headers': headers,
'query': query,
'fields': fields,
'groups': groups,
}
add_stylesheet(formatter.req, 'common/css/report.css')
chrome = Chrome(self.env)
data = chrome.populate_data(formatter.req, data)
template = chrome.load_template('query_results.html')
content = template.generate(**data)
# ticket id list as static
tickets = ''
if 'id' in cols:
ticket_id_list = [ticket.get('id') for group in groups for ticket in group[1]]
if len(ticket_id_list) > 0:
tickets = '([ticket:' + ','.join(ticket_id_list) + ' query by ticket id])'
return tag.div(content, format_to_html(self.env, formatter.context, tickets))
except StopIteration:
errorinfo = _('Not Enough fields in ticket: %s') % line
except Exception:
errorinfo = sys.exc_info()
return tag.div(tag.div(errorinfo, class_='message'), class_='error', id='content')
示例8: invoke
# 需要导入模块: from trac.ticket.api import TicketSystem [as 别名]
# 或者: from trac.ticket.api.TicketSystem import get_ticket_fields [as 别名]
def invoke(self, message, warnings):
"""reply to a ticket"""
ticket = self.ticket
reporter = self._reporter(message)
# get the mailBody and attachments
mailBody, attachments = get_body_and_attachments(message)
if not mailBody:
warnings.append("Seems to be a reply to %s but I couldn't find a comment")
return message
#go throught work
ts = TicketSystem(self.env)
tm = TicketModule(self.env)
perm = PermissionSystem(self.env)
# TODO: Deprecate update without time_changed timestamp
mockReq = self._MockReq(perm.get_user_permissions(reporter), reporter)
avail_actions = ts.get_available_actions(mockReq, ticket)
mailBody, inBodyFields, actions = self._get_in_body_fields(mailBody, avail_actions, reporter)
if inBodyFields or actions :
# check permissions
perm = PermissionSystem(self.env)
#we have properties movement, cheking user permission to do so
if not perm.check_permission('MAIL2TICKET_PROPERTIES', reporter) : # None -> 'anoymous'
raise ("%s does not have MAIL2TICKET_PROPERTIES permissions" % (user or 'anonymous'))
action = None
if actions :
action = actions.keys()[0]
controllers = list(tm._get_action_controllers(mockReq, ticket, action))
all_fields = [field['name'] for field in ts.get_ticket_fields()]
#impact changes find in inBodyFields
for field in inBodyFields :
ticket._old[field] = ticket[field]
ticket.values[field] = inBodyFields[field]
mockReq.args[field] = inBodyFields[field]
if action :
mockReq.args['action_%s_reassign_owner' % action] = ticket['owner']
mockReq.args['comment'] = mailBody
mockReq.args['ts'] = datetime.now()#to_datetime(None, utc)
mockReq.args['ts'] = str(ticket.time_changed)
changes, problems = tm.get_ticket_changes(mockReq, ticket, action)
valid = problems and False or tm._validate_ticket(mockReq, ticket)
tm._apply_ticket_changes(ticket, changes)
# add attachments to the ticket
add_attachments(self.env, ticket, attachments)
ticket.save_changes(reporter, mailBody)
for controller in controllers:
controller.apply_action_side_effects(mockReq, ticket, action)
# Call ticket change listeners
for listener in ts.change_listeners:
listener.ticket_changed(ticket, mailBody, reporter, ticket._old)
tn = TicketNotifyEmail(self.env)
tn.notify(ticket, newticket=0, modtime=ticket.time_changed)