本文整理汇总了Python中trac.ticket.query.Query.execute方法的典型用法代码示例。如果您正苦于以下问题:Python Query.execute方法的具体用法?Python Query.execute怎么用?Python Query.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.ticket.query.Query
的用法示例。
在下文中一共展示了Query.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_permitted_tickets
# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import execute [as 别名]
def _get_permitted_tickets(self, req, constraints=None, columns=None):
"""
If we don't pass a list of column/field values, the Query module
defaults to the first seven colums - see get_default_columns().
"""
if columns is None:
columns = []
else:
columns = columns[:] # avoid mutating callers list
# make sure that we get certain ticket fields
for f in ('summary', 'type', 'remaininghours', 'effort', 'date'):
if f not in columns:
columns.append(f)
# what field data should we get
query = Query(self.env, constraints=constraints, max=0, cols=columns)
tickets = []
for ticket in query.execute(req):
if 'TICKET_VIEW' in req.perm('ticket', ticket['id']):
for k in ('effort', 'remaininghours'):
try:
ticket[k] = float(ticket[k])
except KeyError:
pass
except TypeError:
ticket[k] = 0.0
tickets.append(ticket)
return tickets
示例2: _sticky_from_report
# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import execute [as 别名]
def _sticky_from_report(self, req, data):
ids = []
for value_for_group, row_group in data['row_groups']:
ids.extend([int(row['id']) for row in row_group
if row['resource'] and
row['resource'].realm == 'ticket' and
'TICKET_VIEW' in req.perm(row['resource'])])
cols = ['id', 'summary', 'type']
for col in self._fields:
if col not in cols:
cols.append(col)
if hasattr(self.env, 'get_read_db'):
db = self.env.get_read_db()
else:
db = self.env.get_db_cnx()
start = 0
count = 100
tickets = []
while start < len(ids):
constraints = [{
'id': [str(id) for id in ids[start:start + count]],
}]
query = Query(self.env, constraints=constraints, cols=cols, max=0)
tickets.extend(query.execute(req, db))
start += count
tickets_dict = dict((int(ticket['id']), ticket) for ticket in tickets)
tickets = [tickets_dict[id] for id in ids if id in tickets_dict]
return self._sticky(req, tickets)
示例3: test_all_ordered_by_id_verbose
# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import execute [as 别名]
def test_all_ordered_by_id_verbose(self):
query = Query(self.env, order='id', verbose=1)
sql, args = query.get_sql()
self.assertEqualSQL(sql,
"""SELECT t.id AS id,t.summary AS summary,t.owner AS owner,t.type AS type,t.status AS status,t.priority AS priority,t.milestone AS milestone,t.reporter AS reporter,t.description AS description,t.time AS time,t.changetime AS changetime,priority.value AS priority_value
FROM ticket AS t
LEFT OUTER JOIN enum AS priority ON (priority.type='priority' AND priority.name=priority)
ORDER BY COALESCE(t.id,0)=0,t.id""")
self.assertEqual([], args)
tickets = query.execute(self.req)
示例4: test_all_ordered_by_priority_desc
# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import execute [as 别名]
def test_all_ordered_by_priority_desc(self):
query = Query(self.env, desc=1) # priority is default order
sql, args = query.get_sql()
self.assertEqual(sql,
"""SELECT t.id AS id,t.summary AS summary,t.owner AS owner,t.type AS type,t.status AS status,t.priority AS priority,t.milestone AS milestone,t.time AS time,t.changetime AS changetime,priority.value AS priority_value
FROM ticket AS t
LEFT OUTER JOIN enum AS priority ON (priority.type='priority' AND priority.name=priority)
ORDER BY COALESCE(t.priority,'')='' DESC,priority.value DESC,t.id""")
self.assertEqual([], args)
tickets = query.execute(Mock(href=self.env.href))
示例5: test_all_ordered_by_id_desc
# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import execute [as 别名]
def test_all_ordered_by_id_desc(self):
query = Query(self.env, order='id', desc=1)
sql, args = query.get_sql()
self.assertEqualSQL(sql,
"""SELECT t.id AS id,t.summary AS summary,t.owner AS owner,t.type AS type,t.status AS status,t.priority AS priority,t.product AS product,t.time AS time,t.changetime AS changetime,priority.value AS priority_value
FROM ticket AS t
LEFT OUTER JOIN enum AS priority ON (priority.type='priority' AND priority.name=priority)
ORDER BY COALESCE(t.id,0)=0 DESC,t.id DESC""")
self.assertEqual([], args)
tickets = query.execute(self.req)
示例6: test_grouped_by_priority
# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import execute [as 别名]
def test_grouped_by_priority(self):
query = Query(self.env, group='priority')
sql, args = query.get_sql()
self.assertEqualSQL(sql,
"""SELECT t.id AS id,t.summary AS summary,t.owner AS owner,t.type AS type,t.status AS status,t.product AS product,t.milestone AS milestone,t.priority AS priority,t.time AS time,t.changetime AS changetime,priority.value AS priority_value
FROM ticket AS t
LEFT OUTER JOIN enum AS priority ON (priority.type='priority' AND priority.name=priority)
ORDER BY COALESCE(priority.value,'')='',%(cast_priority)s,t.id""" % {
'cast_priority': self.env.get_read_db().cast('priority.value', 'int')})
self.assertEqual([], args)
tickets = query.execute(self.req)
示例7: test_all_grouped_by_milestone_desc
# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import execute [as 别名]
def test_all_grouped_by_milestone_desc(self):
query = Query(self.env, order='id', group='milestone', groupdesc=1)
sql, args = query.get_sql()
self.assertEqualSQL(sql,
"""SELECT t.id AS id,t.summary AS summary,t.owner AS owner,t.type AS type,t.status AS status,t.priority AS priority,t.product AS product,t.milestone AS milestone,t.time AS time,t.changetime AS changetime,priority.value AS priority_value
FROM ticket AS t
LEFT OUTER JOIN enum AS priority ON (priority.type='priority' AND priority.name=priority)
LEFT OUTER JOIN milestone ON (milestone.name=milestone)
ORDER BY COALESCE(t.milestone,'')='' DESC,COALESCE(milestone.completed,0)=0 DESC,milestone.completed DESC,COALESCE(milestone.due,0)=0 DESC,milestone.due DESC,t.milestone DESC,COALESCE(t.id,0)=0,t.id""")
self.assertEqual([], args)
tickets = query.execute(self.req)
示例8: test_all_ordered_by_version_desc
# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import execute [as 别名]
def test_all_ordered_by_version_desc(self):
query = Query(self.env, order='version', desc=1)
sql, args = query.get_sql()
self.assertEqualSQL(sql,
"""SELECT t.id AS id,t.summary AS summary,t.owner AS owner,t.type AS type,t.status AS status,t.priority AS priority,t.version AS version,t.time AS time,t.changetime AS changetime,priority.value AS priority_value
FROM ticket AS t
LEFT OUTER JOIN enum AS priority ON (priority.type='priority' AND priority.name=priority)
LEFT OUTER JOIN version ON (version.name=version)
ORDER BY COALESCE(t.version,'')='' DESC,COALESCE(version.time,0)=0 DESC,version.time DESC,t.version DESC,t.id""")
self.assertEqual([], args)
tickets = query.execute(self.req)
示例9: test_all_ordered_by_priority_desc
# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import execute [as 别名]
def test_all_ordered_by_priority_desc(self):
query = Query(self.env, desc=1) # priority is default order
sql, args = query.get_sql()
self.assertEqualSQL(sql,
"""SELECT t.id AS id,t.summary AS summary,t.owner AS owner,t.type AS type,t.status AS status,t.priority AS priority,t.milestone AS milestone,t.time AS time,t.changetime AS changetime,priority.value AS priority_value
FROM ticket AS t
LEFT OUTER JOIN enum AS priority ON (priority.type='priority' AND priority.name=priority)
ORDER BY COALESCE(priority.value,'')='' DESC,%(cast_priority)s DESC,t.id""" % {
'cast_priority': self.env.get_db_cnx().cast('priority.value', 'int')})
self.assertEqual([], args)
tickets = query.execute(self.req)
示例10: test_grouped_by_custom_field
# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import execute [as 别名]
def test_grouped_by_custom_field(self):
self.env.config.set('ticket-custom', 'foo', 'text')
query = Query(self.env, group='foo', order='id')
sql, args = query.get_sql()
self.assertEqual(sql,
"""SELECT t.id AS id,t.summary AS summary,t.owner AS owner,t.type AS type,t.status AS status,t.priority AS priority,t.milestone AS milestone,t.time AS time,t.changetime AS changetime,priority.value AS priority_value,foo.value AS foo
FROM ticket AS t
LEFT OUTER JOIN ticket_custom AS foo ON (id=foo.ticket AND foo.name='foo')
LEFT OUTER JOIN enum AS priority ON (priority.type='priority' AND priority.name=priority)
ORDER BY COALESCE(foo.value,'')='',foo.value,COALESCE(t.id,0)=0,t.id""")
self.assertEqual([], args)
tickets = query.execute(Mock(href=self.env.href))
示例11: test_grouped_by_custom_field
# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import execute [as 别名]
def test_grouped_by_custom_field(self):
self.env.config.set('ticket-custom', 'foo', 'text')
query = Query(self.env, group='foo', order='id')
sql, args = query.get_sql()
foo = self.env.get_read_db().quote('foo')
self.assertEqualSQL(sql,
"""SELECT t.id AS id,t.summary AS summary,t.owner AS owner,t.type AS type,t.status AS status,t.priority AS priority,t.product AS product,t.time AS time,t.changetime AS changetime,priority.value AS priority_value,%s.value AS %s
FROM ticket AS t
LEFT OUTER JOIN ticket_custom AS %s ON (id=%s.ticket AND %s.name='foo')
LEFT OUTER JOIN enum AS priority ON (priority.type='priority' AND priority.name=priority)
ORDER BY COALESCE(%s.value,'')='',%s.value,COALESCE(t.id,0)=0,t.id""" %
((foo,) * 7))
self.assertEqual([], args)
tickets = query.execute(self.req)
示例12: test_grouped_by_custom_field
# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import execute [as 别名]
def test_grouped_by_custom_field(self):
self.env.config.set("ticket-custom", "foo", "text")
query = Query(self.env, group="foo", order="id")
sql, args = query.get_sql()
foo = self.env.get_read_db().quote("foo")
self.assertEqualSQL(
sql,
"""SELECT t.id AS id,t.summary AS summary,t.owner AS owner,t.type AS type,t.status AS status,t.priority AS priority,t.milestone AS milestone,t.time AS time,t.changetime AS changetime,priority.value AS priority_value,c.%s AS %s
FROM ticket AS t
LEFT JOIN (SELECT id AS ticket,
(SELECT c.value FROM ticket_custom c WHERE c.ticket=t.id AND c.name='foo') AS %s
FROM ticket t) AS c ON (c.ticket=t.id)
LEFT OUTER JOIN enum AS priority ON (priority.type='priority' AND priority.name=priority)
ORDER BY COALESCE(c.%s,'')='',c.%s,COALESCE(t.id,0)=0,t.id"""
% ((foo,) * 5),
)
self.assertEqual([], args)
tickets = query.execute(self.req)
示例13: save_change
# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import execute [as 别名]
def save_change(self, req, milestone):
"""Try to save changes and return new data, else return error dict.
As with getting ticket data, we check for a custom save method,
and else use the standard implementation
"""
try:
ticket_id = int(req.args.get("ticket"))
except (ValueError, TypeError):
return self._save_error(req, ["Must supply a ticket to change"])
field = req.args.get("group_name")
if not field or re.search("[^a-zA-Z0-9_]", field):
return self._save_error(req, ["Invalid field name"])
else:
# Check to see if we process this field in a unique way
try:
save_f = getattr(self, "_save_%s_change" % field)
except AttributeError:
save_f = self._save_standard_change_
# Try to save the ticket using the relevant save method
try:
if save_f.__name__ == "_save_standard_change_":
save_f(req, ticket_id, field, req.args.get("value"))
else:
save_f(req, ticket_id, req.args.get("action"))
# Retrieve new ticket information
query = Query(self.env,
constraints={'id': [str(ticket_id)]},
cols=['id', 'type', 'effort', 'remaininghours'])
results = query.execute(req)
req.perm('ticket', ticket_id).require('TICKET_VIEW')
for k in ('effort', 'remaininghours'):
try:
results[0][k] = float(results[0][k])
except KeyError:
pass
return self.get_ticket_data(req, milestone, field, results)
except ValueError, e:
return self._save_error(req, list(e))
except TracError, e:
return self._save_error(req, [e])
示例14: process_request
# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import execute [as 别名]
def process_request(self, req):
realm = req.args['realm']
id = req.args['id']
#Urls to generate the depgraph for a ticket is /depgraph/ticketnum
#Urls to generate the depgraph for a milestone is /depgraph/milestone/milestone_name
#List of tickets to generate the depgraph for
tkt_ids = []
if realm == 'milestone':
#we need to query the list of tickets in the milestone
query = Query(self.env, constraints={'milestone': [id]}, max=0)
tkt_ids = [fields['id'] for fields in query.execute(req)]
else:
#the list is a single ticket
tkt_ids = [int(id)]
#the summary argument defines whether we place the ticket id or
#its summary in the node's label
label_summary = 0
if 'summary' in req.args:
label_summary = int(req.args.get('summary'))
g = self._build_graph(req, tkt_ids, label_summary=label_summary)
if req.path_info.endswith('/depgraph.png') or 'format' in req.args:
format = req.args.get('format')
if format == 'text':
#in case g.__str__ returns unicode, we need to convert it in ascii
req.send(to_unicode(g).encode('ascii', 'replace'), 'text/plain')
elif format == 'debug':
import pprint
req.send(
pprint.pformat(
[TicketLinks(self.env, tkt_id) for tkt_id in tkt_ids]
),
'text/plain')
elif format is not None:
if format in self.acceptable_formats:
req.send(g.render(self.dot_path, format), 'text/plain')
else:
raise TracError(_("The %(format)s format is not allowed.", format=format))
if self.use_gs:
ps = g.render(self.dot_path, 'ps2')
gs = subprocess.Popen(
[self.gs_path, '-q', '-dTextAlphaBits=4', '-dGraphicsAlphaBits=4', '-sDEVICE=png16m',
'-sOutputFile=%stdout%', '-'],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
img, err = gs.communicate(ps)
if err:
self.log.debug('MasterTickets: Error from gs: %s', err)
else:
img = g.render(self.dot_path)
req.send(img, 'image/png')
else:
data = {}
#add a context link to enable/disable labels in nodes
if label_summary:
add_ctxtnav(req, 'Without labels', req.href(req.path_info, summary=0))
else:
add_ctxtnav(req, 'With labels', req.href(req.path_info, summary=1))
if realm == 'milestone':
add_ctxtnav(req, 'Back to Milestone: %s' % id, req.href.milestone(id))
data['milestone'] = id
else:
data['ticket'] = id
add_ctxtnav(req, 'Back to Ticket #%s' % id, req.href.ticket(id))
data['graph'] = g
data['graph_render'] = partial(g.render, self.dot_path)
data['use_gs'] = self.use_gs
return 'depgraph.html', data, None
示例15: _process_export
# 需要导入模块: from trac.ticket.query import Query [as 别名]
# 或者: from trac.ticket.query.Query import execute [as 别名]
def _process_export(self, req):
fields = [ {'name':'id', 'label':'id'} ]
fields.extend( TicketSystem(self.env).get_ticket_fields() )
fieldsFormat = self._get_fields_format(fields)
fieldsExport = self._get_fields_export(fields)
fieldsWeight = self._get_fields_weight(fields)
comment_changeset = req.args.get('export.changeset') and req.args.get('export.changeset') == 'True'
fields = [c for c in fields if fieldsExport[ c['name'] ] ]
fieldnames = [c['name'] for c in fields]
fields.sort( lambda a, b : fieldsWeight[a['name']]-fieldsWeight[b['name']] )
# ticket #8805 : unavailable for python 2.4 or 2.5
#content = BytesIO()
content = cStringIO.StringIO()
headerStyle = xlwt.easyxf('font: bold on; pattern: pattern solid, fore-colour grey25; borders: top thin, bottom thin, left thin, right thin')
wb = xlwt.Workbook()
sheetName = ( 'Tickets - %s' % self.config.get('project','name', '') );
try:
ws = wb.add_sheet( sheetName )
except:
# Project name incompatible with sheet name constraints.
sheetName = 'Tickets'
ws = wb.add_sheet( sheetName )
colIndex = {}
c = 0
for f in fields:
ws.write(0, c, unicode(f['label']),headerStyle)
colIndex[f['name']] = c
c += 1
if comment_changeset:
ws.write(0, c, unicode('Comments in change log'),headerStyle)
constraints = {}
if req.args.get('filter.type') and len(req.args['filter.type']) > 0 :
if type( req.args['filter.type'] ) == list :
constraints['type'] = req.args['filter.type']
else:
constraints['type'] = [ req.args['filter.type'] ]
if req.args.get('filter.version') and len(req.args['filter.version']) > 0 :
if type( req.args['filter.version'] ) == list :
constraints['version'] = req.args['filter.version']
else:
constraints['version'] = [ req.args['filter.version'] ]
if req.args.get('filter.milestone') and len(req.args['filter.milestone']) > 0 :
if type( req.args['filter.milestone'] ) == list :
constraints['milestone'] = req.args['filter.milestone']
else:
constraints['milestone'] = [ req.args['filter.milestone'] ]
if req.args.get('filter.component') and len(req.args['filter.component']) > 0 :
if type( req.args['filter.component'] ) == list :
constraints['component'] = req.args['filter.component']
else:
constraints['component'] = [ req.args['filter.component'] ]
if req.args.get('filter.status') and len(req.args['filter.status']) > 0 :
if type( req.args['filter.status'] ) == list :
constraints['status'] = req.args['filter.status']
else:
constraints['status'] = [ req.args['filter.status'] ]
if req.args.get('filter.priority') and len(req.args['filter.priority']) > 0 :
if type( req.args['filter.priority'] ) == list :
constraints['priority'] = req.args['filter.priority']
else:
constraints['priority'] = [ req.args['filter.priority'] ]
if req.args.get('filter.severity') and len(req.args['filter.severity']) > 0 :
if type( req.args['filter.severity'] ) == list :
constraints['severity'] = req.args['filter.severity']
else:
constraints['severity'] = [ req.args['filter.severity'] ]
if req.args.get('filter.resolution') and len(req.args['filter.resolution']) > 0 :
if type( req.args['filter.resolution'] ) == list :
constraints['resolution'] = req.args['filter.resolution']
else:
constraints['resolution'] = [ req.args['filter.resolution'] ]
query = Query(self.env, cols=fieldnames, order='id', max=sys.maxint, constraints=constraints)
results = query.execute(req)
r = 0
cols = query.get_columns()
for result in results:
r += 1
for col in cols:
value = result[col]
format = self.formats[ fieldsFormat[col] ]
value = format.convert(value)
style = format.get_style(value)
ws.write(r, colIndex[col], value, style)
if comment_changeset:
#.........这里部分代码省略.........