in trac/trac/ticket/query.py [0:0]
def template_data(self, context, tickets, orig_list=None, orig_time=None,
req=None):
clauses = []
for clause in self.constraints:
constraints = {}
for k, v in clause.items():
constraint = {'values': [], 'mode': ''}
for val in v:
neg = val.startswith('!')
if neg:
val = val[1:]
mode = ''
if val[:1] in ('~', '^', '$') \
and not val in self.substitutions:
mode, val = val[:1], val[1:]
if req:
val = val.replace('$USER', req.authname)
constraint['mode'] = ('!' if neg else '') + mode
constraint['values'].append(val)
constraints[k] = constraint
clauses.append(constraints)
cols = self.get_columns()
labels = TicketSystem(self.env).get_ticket_field_labels()
wikify = set(f['name'] for f in self.fields
if f['type'] == 'text' and f.get('format') == 'wiki')
headers = [{
'name': col, 'label': labels.get(col, _('Ticket')),
'wikify': col in wikify,
'href': self.get_href(context.href, order=col,
desc=(col == self.order and not self.desc))
} for col in cols]
fields = {'id': {'type': 'id', 'label': _("Ticket")}}
for field in self.fields:
name = field['name']
if name == 'owner' and field['type'] == 'select':
# Make $USER work when restrict_owner = true
field = field.copy()
field['options'].insert(0, '$USER')
if name == 'milestone':
milestones = [Milestone(self.env, opt)
for opt in field['options']]
milestones = [m for m in milestones
if 'MILESTONE_VIEW' in context.perm(m.resource)]
groups = group_milestones(milestones, True)
field['options'] = []
field['optgroups'] = [
{'label': label, 'options': [m.name for m in milestones]}
for (label, milestones) in groups]
fields[name] = field
groups = {}
groupsequence = []
for ticket in tickets:
if orig_list:
# Mark tickets added or changed since the query was first
# executed
if ticket['time'] > orig_time:
ticket['added'] = True
elif ticket['changetime'] > orig_time:
ticket['changed'] = True
if self.group:
group_key = ticket[self.group]
# If grouping by datetime field use days (Bloodhound #68)
if self.group in ('changetime', 'time'):
group_key = format_date(group_key)
groups.setdefault(group_key, []).append(ticket)
if not groupsequence or group_key not in groupsequence:
groupsequence.append(group_key)
groupsequence = [(value, groups[value]) for value in groupsequence]
# detect whether the last group continues on the next page,
# by checking if the extra (max+1)th ticket is in the last group
last_group_is_partial = False
if groupsequence and self.max and len(tickets) == self.max + 1:
del tickets[-1]
if len(groupsequence[-1][1]) == 1:
# additional ticket started a new group
del groupsequence[-1] # remove that additional group
else:
# additional ticket stayed in the group
last_group_is_partial = True
del groupsequence[-1][1][-1] # remove the additional ticket
results = Paginator(tickets,
self.page - 1,
self.max,
self.num_items)
if req:
if results.has_next_page:
next_href = self.get_href(req.href, max=self.max,
page=self.page + 1)
add_link(req, 'next', next_href, _('Next Page'))
if results.has_previous_page:
prev_href = self.get_href(req.href, max=self.max,
page=self.page - 1)
add_link(req, 'prev', prev_href, _('Previous Page'))
else:
results.show_index = False
pagedata = []
shown_pages = results.get_shown_pages(21)
for page in shown_pages:
pagedata.append([self.get_href(context.href, page=page), None,
str(page), _('Page %(num)d', num=page)])
results.shown_pages = [dict(zip(['href', 'class', 'string', 'title'],
p)) for p in pagedata]
results.current_page = {'href': None, 'class': 'current',
'string': str(results.page + 1),
'title':None}
return {'query': self,
'context': context,
'col': cols,
'row': self.rows,
'clauses': clauses,
'headers': headers,
'fields': fields,
'modes': self.get_modes(),
'tickets': tickets,
'groups': groupsequence or [(None, tickets)],
'last_group_is_partial': last_group_is_partial,
'paginator': results}