def render_macro(self, req, name, content): intertracs = {} for key, value in self.config.options('intertrac'): idx = key.rfind('.') # rsplit only in 2.4 if idx > 0: # 0 itself doesn't help much: .xxx = ... prefix, attribute = key[:idx], key[idx+1:] intertrac = intertracs.setdefault(prefix, {}) intertrac[attribute] = value else: intertracs[key] = value # alias def generate_prefix(prefix): intertrac = intertracs[prefix] if isinstance(intertrac, basestring): yield html.TR(html.TD(html.B(prefix)), html.TD('Alias pour ', html.B(intertrac))) else: url = intertrac.get('url', '') if url: title = intertrac.get('title', url) yield html.TR(html.TD(html.A(html.B(prefix), href=url + '/timeline')), html.TD(html.A(title, href=url))) return html.TABLE(class_="wiki intertrac")( html.TR(html.TH(html.EM('Prefix')), html.TH(html.EM('Site Trac'))), [generate_prefix(p) for p in sorted(intertracs.keys())])
def render_macro(self, req, name, content): from trac.util import sorted from trac.util.html import html as _ interwikis = [] for k in sorted(self.keys()): prefix, url, title = self[k] interwikis.append({ 'prefix': prefix, 'url': url, 'title': title, 'rc_url': self._expand_or_append(url, ['RecentChanges']), 'description': title == prefix and url or title }) return _.TABLE(_.TR(_.TH(_.EM("Prefix")), _.TH(_.EM("Site"))), [ _.TR(_.TD(_.A(w['prefix'], href=w['rc_url'])), _.TD(_.A(w['description'], href=w['url']))) for w in interwikis ], class_="wiki interwiki")
def _format_link(self, formatter, ns, query, label): if query.startswith('?'): return html.A(label, class_='query', href=formatter.href.query() + query.replace(' ', '+')) else: try: query = Query.from_string(formatter.env, query) return html.A(label, href=query.get_href(formatter), # Hack class_='query') except QuerySyntaxError, e: return html.EM('[Error: %s]' % e, class_='error')
def get_timeline_events(self, req, db, type, format, start, stop, display): """Return an iterable of events suitable for ITimelineEventProvider. `display` is a callback for formatting the attachment's parent """ for change, type, id, filename, time, descr, author in \ self.get_history(start, stop, type): title = html.EM(os.path.basename(filename)) + \ ' attached to ' + display(id) if format == 'rss': title = Markup(title).striptags() descr = wiki_to_html(descr or '--', self.env, req, db, absurls=True) href = req.abs_href else: descr = wiki_to_oneliner(descr, self.env, db, shorten=True) title += Markup(' by %s', author) href = req.href yield('attachment', href.attachment(type, id, filename), title, time, author, descr)
def get_timeline_events(self, req, start, stop, filters): # timeline动作的输入 if 'wiki' in filters: wiki = WikiSystem(self.env) format = req.args.get('format') href = format == 'rss' and req.abs_href or req.href db = self.env.get_db_cnx() cursor = db.cursor() cursor.execute( "SELECT time,name,comment,author,version " "FROM wiki WHERE time>=%s AND time<=%s", (start, stop)) for t, name, comment, author, version in cursor: title = Markup('<em>%s</em> ' + u"编辑者 %s", wiki.format_page_name(name), author) diff_link = html.A(u'变化', href=href.wiki(name, action='diff', version=version)) if format == 'rss': comment = wiki_to_html(comment or '--', self.env, req, db, absurls=True) else: comment = wiki_to_oneliner(comment, self.env, db, shorten=True) if version > 1: comment = Markup('%s (%s)', comment, diff_link) yield 'wiki', href.wiki(name), title, t, author, comment # Attachments att = AttachmentModule(self.env) for event in att.get_timeline_events(req, db, 'wiki', format, start, stop, lambda id: html.EM(id)): yield event
def check_quickjump(self, req, kwd): noquickjump = int(req.args.get('noquickjump', '0')) # Source quickjump quickjump_href = None if kwd[0] == '/': quickjump_href = req.href.browser(kwd) name = kwd description = 'Browse repository path ' + kwd else: link = wiki_to_link(kwd, self.env, req) if isinstance(link, Element): quickjump_href = link.attr['href'] name = link.children description = link.attr.get('title', '') if quickjump_href: if noquickjump: req.hdf['search.quickjump'] = { 'href': quickjump_href, 'name': html.EM(name), 'description': description } else: req.redirect(quickjump_href)
def display(id): return Markup('ticket %s', html.EM('#', id))
def display_html(self, req, query): req.hdf['title'] = u'自定义查询' add_stylesheet(req, 'common/css/report.css') add_script(req, 'common/js/query.js') db = self.env.get_db_cnx() ZhField = { 'Status': u'状态', 'Description': u'详细描述', 'Reporter': u'报表人', 'Cc': u'抄送', 'Resolution': u'方案', 'Component': u'组件', 'Summary': u'描述', 'Priority': u'优先级', 'Keywords': u'关键字', 'Version': u'版本', 'Milestone': u'里程碑', 'Owner': u'属主', 'Type': u'类型' } for field in query.fields: if field['type'] == 'textarea': continue hdf = {} # 下面两句话是不能交换的!!! field['label'] = ZhField.get(field['label'], field['label']) hdf.update(field) del hdf['name'] req.hdf['query.fields.' + field['name']] = hdf req.hdf['query.modes'] = self._get_constraint_modes() # For clients without JavaScript, we add a new constraint here if # requested if req.args.has_key('add'): field = req.args.get('add_filter') if field: idx = 0 if query.constraints.has_key(field): idx = len(query.constraints[field]) req.hdf['query.constraints.%s.values.%d' % (field, idx)] = '' cols = query.get_columns() ZhCol = { 'Id': u'传票号', 'Status': u'状态', 'Priority': u'优先级', 'Report': u'报表', 'Title': u'标题', 'Ticket': u'传票', 'Summary': u'描述', 'Component': u'组件', 'Version': u'版本', 'Milestone': u'里程碑', 'Type': u'类型', 'Owner': u'属主', 'Created': u'创建日期' } for idx, col in enumerate(cols): req.hdf['query.headers.%d' % idx] = { 'name': col, 'label': ZhCol.get(col.capitalize(), col), 'href': query.get_href(req, order=col, desc=(col == query.order and not query.desc)) } href = req.href.query(group=query.group, groupdesc=query.groupdesc and 1 or None, verbose=query.verbose and 1 or None, **query.constraints) req.hdf['query.order'] = query.order req.hdf['query.href'] = href if query.desc: req.hdf['query.desc'] = True if query.group: req.hdf['query.group'] = query.group if query.groupdesc: req.hdf['query.groupdesc'] = True if query.verbose: req.hdf['query.verbose'] = True tickets = query.execute(req, db) req.hdf['query.num_matches'] = len(tickets) # The most recent query is stored in the user session orig_list = rest_list = None orig_time = int(time.time()) query_constraints = unicode(query.constraints) if query_constraints != req.session.get('query_constraints') \ or int(req.session.get('query_time', 0)) < orig_time - 3600: # 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() ] rest_list = orig_list[:] orig_time = int(req.session.get('query_time', 0)) req.session['query_href'] = query.get_href(req) req.session['query_time'] = orig_time # Find out which tickets originally in the query results no longer # match the constraints if rest_list: for tid in [t['id'] for t in tickets if t['id'] in rest_list]: rest_list.remove(tid) for rest_id in rest_list: try: ticket = Ticket(self.env, int(rest_id), db=db) data = { 'id': ticket.id, 'time': ticket.time_created, 'changetime': ticket.time_changed, 'removed': True, 'href': req.href.ticket(ticket.id) } data.update(ticket.values) except TracError, e: data = { 'id': rest_id, 'time': 0, 'changetime': 0, 'summary': html.EM(e) } tickets.insert(orig_list.index(rest_id), data)
def display_html(self, req, query): req.hdf['title'] = 'Custom Query' add_stylesheet(req, 'common/css/report.css') add_script(req, 'common/js/query.js') db = self.env.get_db_cnx() for field in query.fields: if field['type'] == 'textarea': continue hdf = {} hdf.update(field) del hdf['name'] req.hdf['query.fields.' + field['name']] = hdf req.hdf['query.modes'] = self._get_constraint_modes() # For clients without JavaScript, we add a new constraint here if # requested if req.args.has_key('add'): field = req.args.get('add_filter') if field: idx = 0 if query.constraints.has_key(field): idx = len(query.constraints[field]) req.hdf['query.constraints.%s.values.%d' % (field, idx)] = '' cols = query.get_columns() labels = dict([(f['name'], f['label']) for f in query.fields]) for idx, col in enumerate(cols): req.hdf['query.headers.%d' % idx] = { 'name': col, 'label': labels.get(col, 'Ticket'), 'href': query.get_href(req, order=col, desc=(col == query.order and not query.desc)) } href = req.href.query(group=query.group, groupdesc=query.groupdesc and 1 or None, verbose=query.verbose and 1 or None, **query.constraints) req.hdf['query.order'] = query.order req.hdf['query.href'] = href if query.desc: req.hdf['query.desc'] = True if query.group: req.hdf['query.group'] = query.group if query.groupdesc: req.hdf['query.groupdesc'] = True if query.verbose: req.hdf['query.verbose'] = True tickets = query.execute(req, db) req.hdf['query.num_matches'] = len(tickets) # The most recent query is stored in the user session orig_list = rest_list = None orig_time = int(time.time()) query_constraints = unicode(query.constraints) if query_constraints != req.session.get('query_constraints') \ or int(req.session.get('query_time', 0)) < orig_time - 3600: # 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() ] rest_list = orig_list[:] orig_time = int(req.session.get('query_time', 0)) req.session['query_href'] = query.get_href(req) req.session['query_time'] = orig_time # Find out which tickets originally in the query results no longer # match the constraints if rest_list: for tid in [t['id'] for t in tickets if t['id'] in rest_list]: rest_list.remove(tid) for rest_id in rest_list: try: ticket = Ticket(self.env, int(rest_id), db=db) data = { 'id': ticket.id, 'time': ticket.time_created, 'changetime': ticket.time_changed, 'removed': True, 'href': req.href.ticket(ticket.id) } data.update(ticket.values) except TracError, e: data = { 'id': rest_id, 'time': 0, 'changetime': 0, 'summary': html.EM(e) } tickets.insert(orig_list.index(rest_id), data)