本文整理匯總了Python中trac.ticket.api.TicketSystem.get方法的典型用法代碼示例。如果您正苦於以下問題:Python TicketSystem.get方法的具體用法?Python TicketSystem.get怎麽用?Python TicketSystem.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類trac.ticket.api.TicketSystem
的用法示例。
在下文中一共展示了TicketSystem.get方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: expand_macro
# 需要導入模塊: from trac.ticket.api import TicketSystem [as 別名]
# 或者: from trac.ticket.api.TicketSystem import get [as 別名]
def expand_macro(self, formatter, name, content):
env = self.env
req = formatter.req
args, kw = parse_args(content)
# Use macro arguments (most likely wiki macro calls).
realms = 'realm' in kw and kw['realm'].split('|') or []
tag_system = TagSystem(env)
all_realms = [p.get_taggable_realm()
for p in tag_system.tag_providers]
self.all_realms = all_realms
self.realms = realms
if name == 'TagCloud':
args.append(' or '.join(['realm:%s' % r for r in realms]))
all_tags = tag_system.get_all_tags(req, ' '.join(args))
mincount = 'mincount' in kw and kw['mincount'] or None
return self.render_cloud(req, all_tags,
caseless_sort=self.caseless_sort,
mincount=mincount)
elif name == 'ListTagged':
if _OBSOLETE_ARGS_RE.search(content):
data = {'warning': 'obsolete_args'}
else:
data = {'warning': None}
context=formatter.context
# Use TagsQuery arguments (most likely wiki macro calls).
cols = 'cols' in kw and kw['cols'] or self.default_cols
format = 'format' in kw and kw['format'] or self.default_format
query = args and args[0].strip() or None
if query and not realms:
# First read query arguments (most likely a web-UI call).
for realm in all_realms:
if re.search('(^|\W)realm:%s(\W|$)' % (realm), query):
realms = realms and realms.append(realm) or [realm]
if not realms:
# Apply ListTagged defaults to macro call w/o realm.
realms = list(set(all_realms)-set(self.exclude_realms))
if not realms:
return ''
else:
self.query = query
self.realms = realms
query = '(%s) (%s)' % (query or '', ' or '.join(['realm:%s' % (r)
for r in realms]))
env.log.debug('LISTTAGGED_QUERY: ' + query)
query_result = tag_system.query(req, query)
if not query_result:
return ''
def _link(resource):
if resource.realm == 'tag':
# Keep realm selection in tag links.
return builder.a(resource.id,
href=self.get_href(req, tag=resource))
elif resource.realm == 'ticket':
# Return resource link including ticket status dependend
# class to allow for common Trac ticket link style.
ticket = Ticket(env, resource.id)
return builder.a('#%s' % ticket.id,
class_=ticket['status'],
href=formatter.href.ticket(ticket.id),
title=shorten_line(ticket['summary']))
return render_resource_link(env, context, resource, 'compact')
if format == 'table':
cols = [col for col in cols.split('|')
if col in self.supported_cols]
# Use available translations from Trac core.
try:
labels = TicketSystem(env).get_ticket_field_labels()
labels['id'] = _('Id')
except AttributeError:
# Trac 0.11 neither has the attribute nor uses i18n.
labels = {'id': 'Id', 'description': 'Description'}
labels['realm'] = _('Realm')
labels['tags'] = _('Tags')
headers = [{'label': labels.get(col)}
for col in cols]
data.update({'cols': cols,
'headers': headers})
results = sorted(query_result, key=lambda r: \
embedded_numbers(to_unicode(r[0].id)))
results = self._paginate(req, results)
rows = []
for resource, tags in results:
desc = tag_system.describe_tagged_resource(req, resource)
tags = sorted(tags)
if tags:
rendered_tags = [_link(Resource('tag', tag))
for tag in tags]
if 'oldlist' == format:
resource_link = _link(resource)
else:
desc = desc or \
get_resource_description(env, resource,
context=context)
resource_link = builder.a(desc, href=get_resource_url(
env, resource, context.href))
#.........這裏部分代碼省略.........
示例2: expand_macro
# 需要導入模塊: from trac.ticket.api import TicketSystem [as 別名]
# 或者: from trac.ticket.api.TicketSystem import get [as 別名]
def expand_macro(self, formatter, name, content, realms=[]):
"""Evaluate macro call and render results.
Calls from web-UI come with pre-processed realm selection.
"""
env = self.env
req = formatter.req
tag_system = TagSystem(env)
all_realms = tag_system.get_taggable_realms()
if not all_realms:
# Tag providers are required, no result without at least one.
return ''
args, kw = parse_args(content)
query = args and args[0].strip() or None
if not realms:
# Check macro arguments for realms (typical wiki macro call).
realms = 'realm' in kw and kw['realm'].split('|') or []
if query:
# Add realms from query expression.
realms.extend(query_realms(query, all_realms))
# Remove redundant realm selection for performance.
if set(realms) == all_realms:
query = re.sub('(^|\W)realm:\S+(\W|$)', ' ', query).strip()
if name == 'TagCloud':
# Set implicit 'all tagged realms' as default.
if not realms:
realms = all_realms
if query:
all_tags = Counter()
# Require per resource query including view permission checks.
for resource, tags in tag_system.query(req, query):
all_tags.update(tags)
else:
# Allow faster per tag query, side steps permission checks.
all_tags = tag_system.get_all_tags(req, realms=realms)
mincount = 'mincount' in kw and kw['mincount'] or None
return self.render_cloud(req, all_tags,
caseless_sort=self.caseless_sort,
mincount=mincount, realms=realms)
elif name == 'ListTagged':
if content and _OBSOLETE_ARGS_RE.search(content):
data = {'warning': 'obsolete_args'}
else:
data = {'warning': None}
context = formatter.context
# Use TagsQuery arguments (most likely wiki macro calls).
cols = 'cols' in kw and kw['cols'] or self.default_cols
format = 'format' in kw and kw['format'] or self.default_format
if not realms:
# Apply ListTagged defaults to macro call w/o realm.
realms = list(set(all_realms)-set(self.exclude_realms))
if not realms:
return ''
query = '(%s) (%s)' % (query or '', ' or '.join(['realm:%s' % (r)
for r in realms]))
query_result = tag_system.query(req, query)
excludes = [exc.strip()
for exc in kw.get('exclude', '' ).split(':')
if exc.strip()]
if excludes and query_result:
filtered_result = [(resource, tags)
for resource, tags in query_result
if not any(fnmatchcase(resource.id, exc)
for exc in excludes)]
query_result = filtered_result
if not query_result:
return ''
def _link(resource):
if resource.realm == 'tag':
# Keep realm selection in tag links.
return builder.a(resource.id,
href=self.get_href(req, realms,
tag=resource))
elif resource.realm == 'ticket':
# Return resource link including ticket status dependend
# class to allow for common Trac ticket link style.
ticket = Ticket(env, resource.id)
return builder.a('#%s' % ticket.id,
class_=ticket['status'],
href=formatter.href.ticket(ticket.id),
title=shorten_line(ticket['summary']))
return render_resource_link(env, context, resource, 'compact')
if format == 'table':
cols = [col for col in cols.split('|')
if col in self.supported_cols]
# Use available translations from Trac core.
try:
labels = TicketSystem(env).get_ticket_field_labels()
labels['id'] = _('Id')
except AttributeError:
# Trac 0.11 neither has the attribute nor uses i18n.
labels = {'id': 'Id', 'description': 'Description'}
labels['realm'] = _('Realm')
labels['tags'] = _('Tags')
headers = [{'label': labels.get(col)}
for col in cols]
#.........這裏部分代碼省略.........
示例3: display_html
# 需要導入模塊: from trac.ticket.api import TicketSystem [as 別名]
# 或者: from trac.ticket.api.TicketSystem import get [as 別名]
def display_html(self, req, query):
"""returns the HTML according to a query for /hours view"""
db = self.env.get_db_cnx()
# The most recent query is stored in the user session;
orig_list = None
orig_time = datetime.now(utc)
query_time = int(req.session.get("query_time", 0))
query_time = datetime.fromtimestamp(query_time, utc)
query_constraints = unicode(query.constraints)
if query_constraints != req.session.get("query_constraints") or query_time < orig_time - timedelta(hours=1):
tickets = query.execute(req, db)
# New or outdated query, (re-)initialize session vars
req.session["query_constraints"] = query_constraints
req.session["query_tickets"] = " ".join([str(t["id"]) for t in tickets])
else:
orig_list = [int(id) for id in req.session.get("query_tickets", "").split()]
tickets = query.execute(req, db, orig_list)
orig_time = query_time
context = Context.from_request(req, "query")
ticket_data = query.template_data(context, tickets, orig_list, orig_time, req)
# For clients without JavaScript, we add a new constraint here if
# requested
constraints = ticket_data["clauses"][0]
if "add" in req.args:
field = req.args.get("add_filter")
if field:
constraint = constraints.setdefault(field, {})
constraint.setdefault("values", []).append("")
# FIXME: '' not always correct (e.g. checkboxes)
req.session["query_href"] = query.get_href(context.href)
req.session["query_time"] = to_timestamp(orig_time)
req.session["query_tickets"] = " ".join([str(t["id"]) for t in tickets])
# data dictionary for genshi
data = {}
# get data for saved queries
query_id = req.args.get("query_id")
if query_id:
try:
query_id = int(query_id)
except ValueError:
add_warning(req, "query_id should be an integer, you put '%s'" % query_id)
query_id = None
if query_id:
data["query_id"] = query_id
query_data = self.get_query(query_id)
data["query_title"] = query_data["title"]
data["query_description"] = query_data["description"]
data.setdefault("report", None)
data.setdefault("description", None)
data["all_columns"] = query.get_all_columns() + self.get_columns()
# Don't allow the user to remove the id column
data["all_columns"].remove("id")
data["all_textareas"] = query.get_all_textareas()
# need to re-get the cols because query will remove our fields
cols = req.args.get("col")
if isinstance(cols, basestring):
cols = [cols]
if not cols:
cols = query.get_columns() + self.get_default_columns()
data["col"] = cols
now = datetime.now()
# get the date range for the query
if "from_year" in req.args:
from_date = get_date(req.args["from_year"], req.args.get("from_month"), req.args.get("from_day"))
else:
from_date = datetime(now.year, now.month, now.day)
from_date = from_date - timedelta(days=7) # 1 week ago, by default
if "to_year" in req.args:
to_date = get_date(req.args["to_year"], req.args.get("to_month"), req.args.get("to_day"), end_of_day=True)
else:
to_date = now
data["prev_week"] = from_date - timedelta(days=7)
data["months"] = list(enumerate(calendar.month_name))
data["years"] = range(now.year, now.year - 10, -1)
data["days"] = range(1, 32)
data["users"] = get_all_users(self.env)
data["cur_worker_filter"] = req.args.get("worker_filter", "*any")
data["from_date"] = from_date
data["to_date"] = to_date
ticket_ids = [t["id"] for t in tickets]
# generate data for ticket_times
time_records = self.get_ticket_hours(
ticket_ids, from_date=from_date, to_date=to_date, worker_filter=data["cur_worker_filter"]
#.........這裏部分代碼省略.........