def wiki( req, argument_text, env): args = argument_text.split( ARG_DELIMITER ) name = args[0].replace( "'", "''") if not name: raise util.TracError( help ) from trac.wiki import model page = model.WikiPage( env, name) header = wiki_to_html( '[wiki:%(name)s] / %(argument_text)s:\n' % locals(), env,req) text = '' if page.exists: text = page.text for i in range(1,len(args)): arg = args[i] try: #keyword-args key,value = arg.split('=') except ValueError: #positional args format = '{{%(i)d}}' value = arg else: format = '{{%(key)s}}' text = text.replace( format % locals(), value ) text = wiki_to_html( text, env, req) return text, header
def export_rss(self, req, ticket): db = self.env.get_db_cnx() changes = [] change_summary = {} description = wiki_to_html(ticket['description'], self.env, req, db) req.hdf['ticket.description.formatted'] = unicode(description) for change in self.grouped_changelog_entries(ticket, db): changes.append(change) # compute a change summary change_summary = {} # wikify comment if 'comment' in change: comment = change['comment'] change['comment'] = unicode(wiki_to_html( comment, self.env, req, db, absurls=True)) change_summary['added'] = ['comment'] for field, values in change['fields'].iteritems(): if field == 'description': change_summary.setdefault('changed', []).append(field) else: chg = 'changed' if not values['old']: chg = 'set' elif not values['new']: chg = 'deleted' change_summary.setdefault(chg, []).append(field) change['title'] = '; '.join(['%s %s' % (', '.join(v), k) for k, v \ in change_summary.iteritems()]) req.hdf['ticket.changes'] = changes return (req.hdf.render('ticket_rss.cs'), 'application/rss+xml')
def export_rss(self, req, ticket): db = self.env.get_db_cnx() changes = [] change_summary = {} description = wiki_to_html(ticket['description'], self.env, req, db) req.hdf['ticket.description.formatted'] = unicode(description) for change in self.grouped_changelog_entries(ticket, db): changes.append(change) # compute a change summary change_summary = {} # wikify comment if 'comment' in change: comment = change['comment'] change['comment'] = unicode( wiki_to_html(comment, self.env, req, db, absurls=True)) change_summary['added'] = ['comment'] for field, values in change['fields'].iteritems(): if field == 'description': change_summary.setdefault('changed', []).append(field) else: chg = 'changed' if not values['old']: chg = 'set' elif not values['new']: chg = 'deleted' change_summary.setdefault(chg, []).append(field) change['title'] = '; '.join(['%s %s' % (', '.join(v), k) for k, v \ in change_summary.iteritems()]) req.hdf['ticket.changes'] = changes return (req.hdf.render('ticket_rss.cs'), 'application/rss+xml')
def render_discussion(self, req): # Get request mode group, forum, topic, message = self._get_items(req) modes = self._get_modes(req, group, forum, topic, message) self.log.debug('modes: %s' % modes) # Determine moderator rights. if forum: is_moderator = (req.authname in forum['moderators']) or \ req.perm.has_permission('DISCUSSION_ADMIN') else: is_moderator = req.perm.has_permission('DISCUSSION_ADMIN') # Perform mode actions self._do_action(req, modes, group, forum, topic, message, is_moderator) # Add CSS styles add_stylesheet(req, 'common/css/wiki.css') add_stylesheet(req, 'discussion/css/discussion.css') add_stylesheet(req, 'discussion/css/admin.css') add_link(req, 'alternate', '/timeline?discussion=on&max=50&daysback=90&format=rss', 'POPFile forums', 'application/rss+xml') # Fill up HDF structure and return template req.hdf['discussion.authname'] = req.authname req.hdf['discussion.is_moderator'] = is_moderator title = 'POPFile Forums' if group: group['name'] = wiki_to_oneliner(group['name'], self.env) group['description'] = wiki_to_oneliner(group['description'], self.env) req.hdf['discussion.group'] = group if forum: forum['name'] = wiki_to_oneliner(forum['name'], self.env) forum['description'] = wiki_to_oneliner(forum['description'], self.env) forum['subject'] = wiki_to_oneliner(forum['subject'], self.env) forum['time'] = format_datetime(forum['time']) req.hdf['discussion.forum'] = forum title = 'POPFile ' + forum['name'] + ' Forum' if topic: topic['subject'] = wiki_to_oneliner(topic['subject'], self.env) topic['author'] = wiki_to_oneliner(topic['author'], self.env) topic['body'] = wiki_to_html(topic['body'], self.env, req, None, False, True) topic['time'] = format_datetime(topic['time']) req.hdf['discussion.topic'] = topic if message: message['author'] = wiki_to_oneliner(message['author'], self.env) message['body'] = wiki_to_html(message['body'], self.env, req, None, False, True) message['time'] = format_datetime(message['time']) req.hdf['discussion.message'] = message req.hdf['discussion.mode'] = modes[-1] req.hdf['discussion.time'] = format_datetime(time.time()) req.hdf['title'] = title return modes[-1] + '.cs', None
def notify(self, cr_dict): self.cr_dict = cr_dict cr = CodeReview(self.env, cr_dict['cr_id']) cursor = self.env.get_db_cnx().cursor() cursor.execute("SELECT author, message FROM revision WHERE rev='%s'" % cr_dict['cr_id']) recordset = cursor.fetchall() if not recordset: return cs_author = recordset[0][0] cs_message = recordset[0][1] if cs_author == "anonymous" and cr_dict['cr_author'] == "anonymous": return subject = "[TracNotify] ChangeSet r%s by %s reviewed by %s" % \ (cr_dict['cr_id'], cs_author, ','.join(cr.get_reviewers())) if cr_dict['priority'] == 'critical': subject = '[Critical]' + subject ticket_info = self.get_ticket_info(cs_message, cr_dict['cr_message']) self.hdf['trac_name'] = self.env.config.get('project', 'name') absurl = self.env.config.get('codereview', 'absurl') self.hdf['absurl'] = absurl self.hdf['r_content'] = wiki_to_html(cr_dict['cr_message'], self.env, cr_dict['req'], absurls = absurl) self.hdf['ticket_len'] = len(ticket_info) self.hdf['t_info'] = ticket_info self.hdf['cs_id'] = cr_dict['cr_id'] self.hdf['cs_author'] = cs_author self.hdf['cs_message'] = wiki_to_html(cs_message, self.env, cr_dict['req'], absurls = absurl, escape_newlines=True) self.hdf['r_author'] = ', '.join(cr.get_reviewers()) self.hdf['r_priority'] = cr_dict['priority'] self.subject = subject self.smtp_server = self.config['notification'].get('smtp_server') self.smtp_port = self.config['notification'].getint('smtp_port') self.from_email = self.config['notification'].get('smtp_from') self.replyto_email = self.config['notification'].get('smtp_replyto') self.from_email = self.from_email or self.replyto_email if not self.from_email and not self.replyto_email: raise TracError(Markup('Unable to send email due to identity ' 'crisis.<p>Neither <b>notification.from</b> ' 'nor <b>notification.reply_to</b> are ' 'specified in the configuration.</p>'), 'SMTP Notification Error') # Authentication info (optional) self.user_name = self.config['notification'].get('smtp_user') self.password = self.config['notification'].get('smtp_password') Notify.notify(self, cr_dict['cr_id'])
def render_discussion(self, req, cursor): # Get request mode group, forum, topic, message = self._get_items(req, cursor) modes = self._get_modes(req, group, forum, topic, message) self.log.debug('modes: %s' % modes) # Determine moderator rights. if forum: is_moderator = (req.authname in forum['moderators']) or \ req.perm.has_permission('DISCUSSION_ADMIN') else: is_moderator = req.perm.has_permission('DISCUSSION_ADMIN') # Perform mode actions self._do_action(req, cursor, modes, group, forum, topic, message, is_moderator) # Add CSS styles add_stylesheet(req, 'common/css/wiki.css') add_stylesheet(req, 'discussion/css/discussion.css') add_stylesheet(req, 'discussion/css/admin.css') # Fill up HDF structure and return template req.hdf['discussion.authname'] = req.authname req.hdf['discussion.is_moderator'] = is_moderator if group: group['name'] = wiki_to_oneliner(group['name'], self.env) group['description'] = wiki_to_oneliner(group['description'], self.env) req.hdf['discussion.group'] = group if forum: forum['name'] = wiki_to_oneliner(forum['name'], self.env) forum['description'] = wiki_to_oneliner(forum['description'], self.env) forum['subject'] = wiki_to_oneliner(forum['subject'], self.env) forum['time'] = format_datetime(forum['time']) req.hdf['discussion.forum'] = forum if topic: topic['subject'] = wiki_to_oneliner(topic['subject'], self.env) topic['author'] = wiki_to_oneliner(topic['author'], self.env) topic['body'] = wiki_to_html(topic['body'], self.env, req) topic['time'] = format_datetime(topic['time']) req.hdf['discussion.topic'] = topic if message: message['author'] = wiki_to_oneliner(message['author'], self.env) message['body'] = wiki_to_html(message['body'], self.env, req) message['time'] = format_datetime(message['time']) req.hdf['discussion.message'] = message req.hdf['discussion.mode'] = modes[-1] req.hdf['discussion.time'] = format_datetime(time.time()) return modes[-1] + '.cs', None
def get_timeline_events(self, req, start, stop, filters): if 'changeset' in filters: format = req.args.get('format') wiki_format = self.wiki_format_messages show_files = self.timeline_show_files db = self.env.get_db_cnx() repos = self.env.get_repository(req.authname) for chgset in repos.get_changesets(start, stop): message = chgset.message or '--' if wiki_format: shortlog = wiki_to_oneliner(message, self.env, db, shorten=True) else: shortlog = shorten_line(message) if format == 'rss': title = Markup(u'변경사항 [%s]: %s', chgset.rev, shortlog) href = req.abs_href.changeset(chgset.rev) if wiki_format: message = wiki_to_html(message, self.env, req, db, absurls=True) else: message = html.PRE(message) else: title = Markup(u'변경사항 <em>[%s]</em> : %s에 의해 수정됨', chgset.rev, chgset.author) href = req.href.changeset(chgset.rev) if wiki_format: if self.timeline_long_messages: message = wiki_to_html(message, self.env, req, db, absurls=True) else: message = wiki_to_oneliner(message, self.env, db, shorten=True) else: message = shortlog if show_files and req.perm.has_permission('BROWSER_VIEW'): files = [] for chg in chgset.get_changes(): if show_files > 0 and len(files) >= show_files: files.append(html.LI(Markup('…'))) break files.append(html.LI(html.DIV(class_=chg[2]), chg[0] or '/')) message = html.UL(files, class_="changes") + message yield 'changeset', href, title, chgset.date, chgset.author,\ message
def get_timeline_events(self, req, start, stop, filters): if 'changeset' in filters: format = req.args.get('format') wiki_format = self.wiki_format_messages show_files = self.timeline_show_files db = self.env.get_db_cnx() repos = self.env.get_repository(req.authname) for chgset in repos.get_changesets(start, stop): message = chgset.message or '--' if wiki_format: shortlog = wiki_to_oneliner(message, self.env, db, shorten=True) else: shortlog = shorten_line(message) if format == 'rss': title = Markup('Changeset [%s]: %s', chgset.rev, shortlog) href = req.abs_href.changeset(chgset.rev) if wiki_format: message = wiki_to_html(message, self.env, req, db, absurls=True) else: message = html.PRE(message) else: title = Markup('Changeset <em>[%s]</em> by %s', chgset.rev, chgset.author) href = req.href.changeset(chgset.rev) if wiki_format: if self.timeline_long_messages: message = wiki_to_html(message, self.env, req, db, absurls=True) else: message = wiki_to_oneliner(message, self.env, db, shorten=True) else: message = shortlog if show_files and req.perm.has_permission('BROWSER_VIEW'): files = [] for chg in chgset.get_changes(): if show_files > 0 and len(files) >= show_files: files.append(html.LI(Markup('…'))) break files.append(html.LI(html.DIV(class_=chg[2]), chg[0] or '/')) message = html.UL(files, class_="changes") + message yield 'changeset', href, title, chgset.date, chgset.author,\ message
def parse(hdf, txt, env): req = None txt = txt.lstrip() if (0 == len(txt)): return "" html = "" match = re.search( r"^(from:?\s+?)?(.*)$\s+?^(sent:?\s*)?(.*)$\s+?^\s*to:?\s+?(.*)$\s+?^(\s*cc:?\s+?(.*)$\s+?)?^\s*subject:?\s+(.*)$", txt, re.IGNORECASE | re.MULTILINE) if match: if (-1 == match.start(1)): pre_content = match.string[0:match.start(2)] else: pre_content = match.string[0:match.start(1)] from1 = match.group(2) date = match.group(4) to = match.group(5) if (-1 != match.start(6)) and (-1 != match.start(7)): cc = match.group(7) else: cc = '' subject = match.group(8) content = match.string[match.end(8):] else: return wiki_to_html(txt, env, req, escape_newlines=True) html = '%s<br />'\ '<fieldset style="%s">'\ '<legend style="%s">%s</legend>'\ 'From: %s<br />'\ 'To: %s<br />' % (wiki_to_html(pre_content, env, req, escape_newlines=True), STYLE, STYLE, date, from1.replace("<", "<"), to.replace("<", "<")) if (0 < len(cc)): html += 'Cc: %s<br />' % cc.replace("<", "<") html += 'Subject: %s<br />'\ '</fieldset><br />'\ '%s<br />' % (subject, parse(hdf, content, env)) return html
def get_timeline_events(self, req, start, stop, filters): self.log.debug("start: %s, stop: %s, filters: %s" % (start, stop, filters)) if 'downloads' in filters: # Create database context db = self.env.get_db_cnx() cursor = db.cursor() # Get API component. api = self.env[DownloadsApi] format = req.args.get('format') self.log.debug("format: %s" % (format)) # Get message events for download in api.get_new_downloads(req, cursor, start, stop): kind = 'newticket' title = Markup("New download <em>%s</em> created by %s" % (download['file'], download['author'])) time = download['time'] author = download['author'] if format == 'rss': href = req.abs_href.downloads(download['id']) message = wiki_to_html(download['description'], self.env, req) else: href = req.href.downloads(download['id']) message = wiki_to_oneliner(download['description'], self.env) yield kind, href, title, time, author, message
def get_timeline_events(self, req, start, stop, filters): self.log.debug("start: %s, stop: %s, filters: %s" % (start, stop, filters)) if "downloads" in filters: # Create database context db = self.env.get_db_cnx() cursor = db.cursor() # Get API component. api = self.env[DownloadsApi] format = req.args.get("format") self.log.debug("format: %s" % (format)) # Get message events for download in api.get_new_downloads(req, cursor, start, stop): kind = "newticket" title = Markup("New download <em>%s</em> created by %s" % (download["file"], download["author"])) time = download["time"] author = download["author"] if format == "rss": href = req.abs_href.downloads(download["id"]) message = wiki_to_html(download["description"], self.env, req) else: href = req.href.downloads(download["id"]) message = wiki_to_oneliner(download["description"], self.env) yield kind, href, title, time, author, message
def get_timeline_events(self, req, start, stop, filters): if 'milestone' in filters: format = req.args.get('format') db = self.env.get_db_cnx() cursor = db.cursor() cursor.execute( "SELECT completed,name,description FROM milestone " "WHERE completed>=%s AND completed<=%s", ( start, stop, )) for completed, name, description in cursor: title = Markup('Milestone <em>%s</em> completed', name) if format == 'rss': href = req.abs_href.milestone(name) message = wiki_to_html(description, self.env, req, db, absurls=True) else: href = req.href.milestone(name) message = wiki_to_oneliner(description, self.env, db, shorten=True) yield 'milestone', href, title, completed, None, message or '--'
def get_changes(env, repos, revs, full=None, req=None, format=None): db = env.get_db_cnx() changes = {} for rev in revs: changeset = repos.get_changeset(rev) message = changeset.message or '--' files = None if format == 'changelog': files = [change[0] for change in changeset.get_changes()] elif message: if not full: message = wiki_to_oneliner(message, env, db, shorten=True) else: message = wiki_to_html(message, env, req, db, absurls=(format == 'rss'), escape_newlines=True) if not message: message = '--' changes[rev] = { 'date_seconds': changeset.date, 'date': format_datetime(changeset.date), 'age': pretty_timedelta(changeset.date), 'author': changeset.author or 'anonymous', 'message': message, 'shortlog': shorten_line(message), 'files': files } return changes
def get_topics(self, req, cursor, forum_id, order_by='time', desc=False): if not order_by in ( 'replies', 'lastreply', ): order_by = 't.' + order_by columns = ('id', 'forum', 'time', 'subject', 'body', 'author', 'replies', 'lastreply') sql = "SELECT t.id, t.forum, t.time, t.subject, t.body, t.author," \ " m.replies, m.lastreply FROM topic t LEFT JOIN (SELECT COUNT(id)" \ " AS replies, MAX(time) AS lastreply, topic FROM message GROUP BY" \ " topic) m ON t.id = m.topic WHERE t.forum = %s ORDER BY " \ + order_by + (" ASC", " DESC")[bool(desc)] self.log.debug(sql % (forum_id, )) cursor.execute(sql, (forum_id, )) topics = [] for row in cursor: row = dict(zip(columns, row)) row['author'] = wiki_to_oneliner(row['author'], self.env) row['body'] = wiki_to_html(row['body'], self.env, req) if row['lastreply']: row['lastreply'] = pretty_timedelta(float(row['lastreply'])) else: row['lastreply'] = 'No replies' if not row['replies']: row['replies'] = 0 row['time'] = format_datetime(row['time']) topics.append(row) return topics
def process_request(self, req): req.perm.assert_permission('MESSAGE_VIEW') data = { 'placeholder': wiki_to_html(self.placeholder_text, self.env, req=req) } return 'multiproject_messages_dialog.html', data, None
def get_messages(self, req, cursor, topic, time, order_by = 'ORDER BY time ASC'): columns = ('id', 'replyto', 'time', 'author', 'body') sql = "SELECT id, replyto, time, author, body FROM message WHERE" \ " topic = %s " + order_by self.log.debug(sql % (topic,)) cursor.execute(sql, (topic,)) messagemap = {} messages = [] for row in cursor: row = dict(zip(columns, row)) row['author'] = wiki_to_oneliner(row['author'], self.env) row['body'] = wiki_to_html(row['body'], self.env, req) if int(row['time']) > time: row['new'] = True row['time'] = format_datetime(row['time']) messagemap[row['id']] = row # Add top-level messages to the main list, in order of time if row['replyto'] == -1: messages.append(row) # Second pass, add replies for message in messagemap.values(): if message['replyto'] != -1: parent = messagemap[message['replyto']] if 'replies' in parent: parent['replies'].append(message) else: parent['replies'] = [message] return messages;
def get_messages(self, req, cursor, topic, time, order_by='ORDER BY time ASC'): columns = ('id', 'replyto', 'time', 'author', 'body') sql = "SELECT id, replyto, time, author, body FROM message WHERE" \ " topic = %s " + order_by self.log.debug(sql % (topic, )) cursor.execute(sql, (topic, )) messagemap = {} messages = [] for row in cursor: row = dict(zip(columns, row)) row['author'] = wiki_to_oneliner(row['author'], self.env) row['body'] = wiki_to_html(row['body'], self.env, req) if int(row['time']) > time: row['new'] = True row['time'] = format_datetime(row['time']) messagemap[row['id']] = row # Add top-level messages to the main list, in order of time if row['replyto'] == -1: messages.append(row) # Second pass, add replies for message in messagemap.values(): if message['replyto'] != -1: parent = messagemap[message['replyto']] if 'replies' in parent: parent['replies'].append(message) else: parent['replies'] = [message] return messages
def export_rss(self, req, query): query.verbose = True db = self.env.get_db_cnx() results = query.execute(req, db) for result in results: result['href'] = req.abs_href.ticket(result['id']) if result['reporter'].find('@') == -1: result['reporter'] = '' if result['description']: # unicode() cancels out the Markup() returned by wiki_to_html descr = wiki_to_html(result['description'], self.env, req, db, absurls=True) result['description'] = unicode(descr) if result['time']: result['time'] = http_date(result['time']) req.hdf['query.results'] = results req.hdf['query.href'] = req.abs_href.query( group=query.group, groupdesc=query.groupdesc and 1 or None, verbose=query.verbose and 1 or None, **query.constraints) return (req.hdf.render('query_rss.cs'), 'application/rss+xml')
def process_request(self, req): req.perm.assert_permission('TICKET_VIEW') action = req.args.get('action', 'view') if not req.args.has_key('id'): req.redirect(self.env.href.wiki()) db = self.env.get_db_cnx() id = int(req.args.get('id')) ticket = Ticket(self.env, id, db=db) reporter_id = util.get_reporter_id(req) if req.method == 'POST': if not req.args.has_key('preview'): self._do_save(req, db, ticket) else: # Use user supplied values ticket.populate(req.args) req.hdf['ticket.action'] = action req.hdf['ticket.ts'] = req.args.get('ts') req.hdf['ticket.reassign_owner'] = req.args.get('reassign_owner') \ or req.authname req.hdf['ticket.resolve_resolution'] = req.args.get('resolve_resolution') reporter_id = req.args.get('author') comment = req.args.get('comment') if comment: req.hdf['ticket.comment'] = comment # Wiki format a preview of comment req.hdf['ticket.comment_preview'] = wiki_to_html(comment, self.env, req, db) else: req.hdf['ticket.reassign_owner'] = req.authname # Store a timestamp in order to detect "mid air collisions" req.hdf['ticket.ts'] = ticket.time_changed self._insert_ticket_data(req, db, ticket, reporter_id) # If the ticket is being shown in the context of a query, add # links to help navigate in the query result set if 'query_tickets' in req.session: tickets = req.session['query_tickets'].split() if str(id) in tickets: idx = tickets.index(str(ticket.id)) if idx > 0: add_link(req, 'first', self.env.href.ticket(tickets[0]), 'Ticket #%s' % tickets[0]) add_link(req, 'prev', self.env.href.ticket(tickets[idx - 1]), 'Ticket #%s' % tickets[idx - 1]) if idx < len(tickets) - 1: add_link(req, 'next', self.env.href.ticket(tickets[idx + 1]), 'Ticket #%s' % tickets[idx + 1]) add_link(req, 'last', self.env.href.ticket(tickets[-1]), 'Ticket #%s' % tickets[-1]) add_link(req, 'up', req.session['query_href']) add_stylesheet(req, 'common/css/ticket.css') return 'ticket.cs', None
def end_process(self, numrows): self.message = 'Scroll to see a preview of the tickets as they will be imported. If the data is correct, select the \'\'\'Execute Import\'\'\' button.\n' + ' * ' + str(numrows) + ' tickets will be imported (' + str(self.added) + ' added, ' + str(self.modifiedcount) + ' modified, ' + str(self.notmodifiedcount) + ' unchanged).\n' + self.message self.req.hdf['report.description'] = Markup(self.styles) + wiki_to_html(self.message, self.env, self.req) + Markup('<br/><form action="importer" method="post"><input type="hidden" name="action" value="import" /><div class="buttons"><input type="submit" name="cancel" value="Cancel" /><input type="submit" value="Execute import" /></div></form>') self.req.hdf['report.numrows'] = numrows self.req.hdf['report.mode'] = 'list' return 'report.cs', None
def get_topics(self, req, cursor, forum_id, order_by = 'time', desc = False): if not order_by in ('replies', 'lastreply',): order_by = 't.' + order_by columns = ('id', 'forum', 'time', 'subject', 'body', 'author', 'replies', 'lastreply') sql = "SELECT t.id, t.forum, t.time, t.subject, t.body, t.author," \ " m.replies, m.lastreply FROM topic t LEFT JOIN (SELECT COUNT(id)" \ " AS replies, MAX(time) AS lastreply, topic FROM message GROUP BY" \ " topic) m ON t.id = m.topic WHERE t.forum = %s ORDER BY " \ + order_by + (" ASC", " DESC")[bool(desc)] self.log.debug(sql % (forum_id,)) cursor.execute(sql, (forum_id,)) topics = [] for row in cursor: row = dict(zip(columns, row)) row['author'] = wiki_to_oneliner(row['author'], self.env) row['body'] = wiki_to_html(row['body'], self.env, req) if row['lastreply']: row['lastreply'] = pretty_timedelta(float(row['lastreply'])) else: row['lastreply'] = 'No replies' if not row['replies']: row['replies'] = 0 row['time'] = format_datetime(row['time']) topics.append(row) return topics
def process_request(self, req): req.perm.assert_permission('TICKET_VIEW') action = req.args.get('action', 'view') if not req.args.has_key('id'): req.redirect(self.env.href.wiki()) db = self.env.get_db_cnx() id = int(req.args.get('id')) ticket = Ticket(self.env, id, db=db) reporter_id = util.get_reporter_id(req) if req.method == 'POST': if not req.args.has_key('preview'): self._do_save(req, db, ticket) else: # Use user supplied values ticket.populate(req.args) req.hdf['ticket.action'] = action req.hdf['ticket.ts'] = req.args.get('ts') req.hdf['ticket.reassign_owner'] = req.args.get('reassign_owner') \ or req.authname req.hdf['ticket.resolve_resolution'] = req.args.get('resolve_resolution') reporter_id = req.args.get('author') comment = req.args.get('comment') if comment: req.hdf['ticket.comment'] = util.escape(comment) # Wiki format a preview of comment req.hdf['ticket.comment_preview'] = wiki_to_html(comment, self.env, req, db) else: req.hdf['ticket.reassign_owner'] = req.authname # Store a timestamp in order to detect "mid air collisions" req.hdf['ticket.ts'] = ticket.time_changed self._insert_ticket_data(req, db, ticket, reporter_id) # If the ticket is being shown in the context of a query, add # links to help navigate in the query result set if 'query_tickets' in req.session: tickets = req.session['query_tickets'].split() if str(id) in tickets: idx = tickets.index(str(ticket.id)) if idx > 0: add_link(req, 'first', self.env.href.ticket(tickets[0]), 'Ticket #%s' % tickets[0]) add_link(req, 'prev', self.env.href.ticket(tickets[idx - 1]), 'Ticket #%s' % tickets[idx - 1]) if idx < len(tickets) - 1: add_link(req, 'next', self.env.href.ticket(tickets[idx + 1]), 'Ticket #%s' % tickets[idx + 1]) add_link(req, 'last', self.env.href.ticket(tickets[-1]), 'Ticket #%s' % tickets[-1]) add_link(req, 'up', req.session['query_href']) add_stylesheet(req, 'common/css/ticket.css') return 'ticket.cs', None
def get_messages(self, req, cursor, topic_id, time, order_by = 'time', desc = False): order_by = 'm.' + order_by columns = ('id', 'replyto', 'time', 'author', 'body') sql = "SELECT m.id, m.replyto, m.time, m.author, m.body FROM message m WHERE" \ " m.topic = %s ORDER BY " + order_by + (" ASC", " DESC")[bool(desc)] self.log.debug(sql % (topic_id,)) cursor.execute(sql, (topic_id,)) messagemap = {} messages = [] for row in cursor: row = dict(zip(columns, row)) row['author'] = wiki_to_oneliner(row['author'], self.env) row['body'] = wiki_to_html(row['body'], self.env, req, None, False, True) if int(row['time']) > time: row['new'] = True row['time'] = format_datetime(row['time']) messagemap[row['id']] = row # Add top-level messages to the main list, in order of time if row['replyto'] == -1: messages.append(row) # Second pass, add replies for message in messagemap.values(): if message['replyto'] != -1: parent = messagemap[message['replyto']] if 'replies' in parent: parent['replies'].append(message) else: parent['replies'] = [message] return messages;
def _display_edit(self, req): req.perm.assert_permission('CODE_REVIEW_EDIT') cs_id = req.args.get('id') cr = CodeReview(self.env, int(cs_id)) if not cr.is_existent_rev(): return pretty_err(req, 'Review ID error', 'No ChangeSet %s, it cannot ' \ 'CodeReview for a Non-existent ChangeSet' % cs_id) item = cr.get_item() if cr.is_existent(): item['reviewers'] = ', '.join(item['reviewers']) #ver, ctime, status, text, priority = record ver = item['version'] status = item['status'] priority = item['priority'] ctime = time.ctime(item['time']) text = item['text'] or '' else: authors = '' ver = 0 status = str_status["UndergoingReview"] text = '' ctime = '' priority = 'normal' sourcelists = [{'i':i, 'v': '[[CodeSegment(%s, 1, 2, %s)]]'%(v, cs_id)} \ for i, v in enumerate(cr.get_all_pathes())] if len(sourcelists) > 0: req.hdf['source_count'] = len(sourcelists) req.hdf['sourcelists'] = sourcelists if req.args.get('action') == 'preview' and req.args.has_key('text'): req.hdf['preview'] = wiki_to_html(req.args.get('text'), self.env, req) req.hdf['text'] = req.args.get('text') else: req.hdf['text'] = text author = util.get_reporter_id(req) if req.args.has_key('req_version'): if ver != int(req.args.get('req_version')): if req.args.has_key('oldtext'): req.hdf['oldtext'] = req.args.get('oldtext') else: req.hdf['oldtext'] = req.args.get('text') req.hdf['version'] = req.args.get('req_version') else: req.hdf['version'] = ver else: req.hdf['version'] = ver self._render_attachment(req, cs_id, True) req.hdf['page_class'] = 'edit' req.hdf['time'] = ctime req.hdf['status'] = status req.hdf['reviewers'] = item['reviewers'] req.hdf['author'] = author req.hdf['id'] = cs_id req.hdf['priority'] = priority req.hdf['cs_href'] = '%s/changeset/%s' % (self.env.href.base, cs_id) req.hdf['save_href'] = '%s/CodeReview/%s' % (self.env.href.base, cs_id) req.hdf['title'] = "Edit CodeReview r%s" % cs_id return 'codereviewpage.cs', None
def get_timeline_events(self, req, start, stop, filters): format = req.args.get('format') status_map = { 'new': ('newticket', u'créé'), 'reopened': ('newticket', u'réouvert'), 'closed': ('closedticket', u'fermé'), 'edit': ('editedticket', u'mis à jour') } href = format == 'rss' and req.abs_href or req.href def produce( (id, t, author, type, summary), status, fields, comment, cid): if status == 'edit': if 'ticket_details' in filters: info = u'' if len(fields) > 0: info = u', '.join([u'<i>%s</i>' % f for f in \ fields.keys()]) + u' modifié<br />' else: return None elif 'ticket' in filters: if status == 'closed' and fields.has_key('resolution'): info = fields['resolution'] if info and comment: info = '%s: ' % info else: info = '' else: return None kind, verb = status_map[status] if format == 'rss': title = u'Ticket #%s (%s %s): %s' % \ (id, translate(self.env, type).lower(), verb, summary) else: title = Markup( u'Ticket <em title="%s">#%s</em> (%s) %s par %s', summary, id, translate(self.env, type), verb, author) ticket_href = href.ticket(id) if cid: ticket_href += '#comment:' + cid if status == 'new': message = unicode(summary) else: message = Markup(info) if comment: if format == 'rss': message += wiki_to_html(comment, self.env, req, db, absurls=True) else: message += wiki_to_oneliner(comment, self.env, db, shorten=True) return kind, ticket_href, title, t, author, message
def parse(hdf, txt, env): req = None txt = txt.lstrip() if (0 == len(txt)): return "" html = "" match = re.search(r"^(from:?\s+?)?(.*)$\s+?^(sent:?\s*)?(.*)$\s+?^\s*to:?\s+?(.*)$\s+?^(\s*cc:?\s+?(.*)$\s+?)?^\s*subject:?\s+(.*)$", txt, re.IGNORECASE | re.MULTILINE) if match: if (-1 == match.start(1)): pre_content = match.string[0:match.start(2)] else: pre_content = match.string[0:match.start(1)] from1 = match.group(2) date = match.group(4) to = match.group(5) if (-1 != match.start(6)) and (-1 != match.start(7)): cc = match.group(7) else: cc = '' subject = match.group(8) content = match.string[match.end(8):] else: return wiki_to_html(txt, env, req, escape_newlines=True) html = '%s<br />'\ '<fieldset style="%s">'\ '<legend style="%s">%s</legend>'\ 'From: %s<br />'\ 'To: %s<br />' % (wiki_to_html(pre_content, env, req, escape_newlines=True), STYLE, STYLE, date, from1.replace("<", "<"), to.replace("<", "<")) if (0 < len(cc)): html += 'Cc: %s<br />' % cc.replace("<", "<") html += 'Subject: %s<br />'\ '</fieldset><br />'\ '%s<br />' % (subject, parse(hdf, content, env)) return html
def execute(hdf, args, env): # Args seperated by commas: # url, formatter # # url is the url to go get. # Formatter is which formatter if any to parse. Default: None _href = env.abs_href or env.href formatter = None action = None id = None parameter = None db = env.get_db_cnx() cursor = db.cursor() cs = db.cursor() buf = StringIO() currentpage = hdf.getValue('wiki.page_name', '') + '/' if args: args = args.replace('\'', '\'\'') args = args.split(',') if args[0] != 'None': action = args[0] try: if args[1] != 'None': id = args[1] except: id = '' try: if args[2] != 'None': parameter = args[2] except: if action == 'begin': parameter = 'inline' if action == 'activator': parameter = 'wiki' try: if args[3] != 'None': content = args[3] except: content = '' if action == 'printscript': output = '<script type=\'text/javascript\'>function switchMenu(obj) { var el = document.getElementById(obj); if ( el.style.display == \'none\' ) { el.style.display =\'inline\'; } else { el.style.display = \'none\'; } } </script>' if action == 'begin': output = '<span id="' + id + '" style="display: ' + parameter + '">' if action == 'end': output = '</span>' if action == 'activator': if parameter == 'wiki': content = wiki_to_html(content, env, hdf, db, 0) output = '<span onClick="javascript: switchMenu(\'' + id + '\');">' + content + '</span>' buf.write(output) return buf.getvalue()
def execute(hdf, args, env): # Args seperated by commas: # url, formatter # # url is the url to go get. # Formatter is which formatter if any to parse. Default: None _href = env.abs_href or env.href formatter = None action = None id = None parameter = None db = env.get_db_cnx() cursor = db.cursor() cs = db.cursor() buf = StringIO() currentpage = hdf.getValue('wiki.page_name', '') + '/' if args: args = args.replace('\'', '\'\'') args = args.split(',') if args[0] != 'None': action = args[0] try: if args[1] != 'None': id = args[1] except: id = ''; try: if args[2] != 'None': parameter = args[2] except: if action == 'begin': parameter = 'inline' if action == 'activator': parameter = 'wiki' try: if args[3] != 'None': content = args[3] except: content = '' if action == 'printscript': output = '<script type=\'text/javascript\'>function switchMenu(obj) { var el = document.getElementById(obj); if ( el.style.display == \'none\' ) { el.style.display =\'inline\'; } else { el.style.display = \'none\'; } } </script>'; if action == 'begin': output = '<span id="'+id+'" style="display: '+parameter+'">'; if action == 'end': output = '</span>'; if action == 'activator': if parameter == 'wiki': content = wiki_to_html(content,env,hdf,db,0) output = '<span onClick="javascript: switchMenu(\''+id+'\');">'+content+'</span>' buf.write(output) return buf.getvalue()
def expand_macro(self, formatter, name, content): db = self.env.get_read_db() cursor = db.cursor() cursor.execute("SELECT text FROM wiki WHERE name=%s ORDER BY version DESC LIMIT 1", ("WikiStart",)) try: text = extract_client_text(cursor.fetchone()[0]) return wiki_to_html(text, self.env, formatter.req) except: return 'B0rken'
def _display_html(self, req): cs_id = int(req.args.get('id')) cr = CodeReview(self.env, int(cs_id)) if req.args.get('version'): try: req_ver = int(req.args.get('version')) except: req_ver = 0 else: req_ver = 0 if req.args.has_key('delete_info'): req.hdf['delete_info'] = req.args.get('delete_info') if not cr.is_existent_rev(): return pretty_err(req, 'Review ID error', 'No ChangeSet %s, it cannot ' \ 'CodeReview for a Non-existent ChangeSet' % cs_id) if req_ver: if cr.is_existent_ver(req_ver): ver = req_ver else: ver = 0 else: ver = cr.get_current_ver() if not ver: req.hdf['page_class'] = "None" if req_ver: req.hdf['title'] = "CodeReview r%s version: %s is non-existent" \ % (cs_id, req_ver) req.hdf['message'] = "CodeReview r%s version: %s is non-existent" \ % (cs_id, req_ver) req.hdf['create_href'] = "%s/%s" % (self.env.href.CodeReview(), \ cs_id) else: req.hdf['title'] = "CodeReview r%s is non-existent" % cs_id req.hdf['message'] = "CodeReview r%s is non-existent, Do you want to create it?" % cs_id req.hdf['create_href'] = "%s/%s" % (self.env.href.CodeReview(), \ cs_id) return 'codereviewpage.cs', None else: req.hdf['page_class'] = "View" req.hdf['title'] = "CodeReview r%s" % cs_id item = cr.get_item() self._render_attachment(req, cs_id) if cr.get_current_ver() == ver: req.hdf['delete_href'] = "%s/%s" % (self.env.href.CodeReview(), cs_id) else: req.hdf['source_text'] = item['text'] or '' req.hdf['status'] = status_str[item['status']] req.hdf['authors'] = ', '.join(item['reviewers']) req.hdf['text'] = item['text'] and wiki_to_html(item['text'], self.env, req) or '' req.hdf['time'] = time.ctime(item['time']) req.hdf['cr_id'] = cs_id req.hdf['version'] = ver req.hdf['priority'] = item['priority'] req.hdf['cs_href'] = "%s/changeset/%s" % (self.env.href.base, cs_id) req.hdf['edit_href'] = "%s/CodeReview/%s" % (self.env.href.base, cs_id) return 'codereviewpage.cs', None
def process_request(self, req): req.perm.assert_permission('TICKET_CREATE') db = self.env.get_db_cnx() if req.method == 'POST' and not req.args.has_key('preview'): self._do_create(req, db) ticket = Ticket(self.env, db=db) ticket.populate(req.args) ticket.values.setdefault('reporter', util.get_reporter_id(req)) if ticket.values.has_key('description'): description = wiki_to_html(ticket['description'], self.env, req, db) req.hdf['newticket.description_preview'] = description req.hdf['title'] = 'New Ticket' req.hdf['newticket'] = dict( zip(ticket.values.keys(), [util.escape(value) for value in ticket.values.values()])) field_names = [ field['name'] for field in ticket.fields if not field.get('custom') ] if 'owner' in field_names: curr_idx = field_names.index('owner') if 'cc' in field_names: insert_idx = field_names.index('cc') else: insert_idx = len(field_names) if curr_idx < insert_idx: ticket.fields.insert(insert_idx, ticket.fields[curr_idx]) del ticket.fields[curr_idx] for field in ticket.fields: name = field['name'] del field['name'] if name in ('summary', 'reporter', 'description', 'type', 'status', 'resolution'): field['skip'] = True elif name == 'owner': field['label'] = 'Assign to' elif name == 'milestone': # Don't make completed milestones available for selection options = field['options'] for option in field['options']: milestone = Milestone(self.env, option, db=db) if milestone.is_completed: options.remove(option) field['options'] = options req.hdf['newticket.fields.' + name] = field add_stylesheet(req, 'common/css/ticket.css') return 'newticket.cs', None
def get_plans(self, req, cursor, suite_id): rows = [] columns = ('id','title','description') sql = "SELECT id, title, description FROM mtp_plans WHERE suite_id = %s" % suite_id self.log.debug(sql) cursor.execute(sql) for row in cursor: row = dict(zip(columns, row)) row['description'] = wiki_to_html(row['description'], self.env, req) rows.append(row) return rows
def get_timeline_events(self, req, start, stop, filters): format = req.args.get('format') status_map = { 'new': ('newticket', u'créé'), 'reopened': ('newticket', u'réouvert'), 'closed': ('closedticket', u'fermé'), 'edit': ('editedticket', u'mis à jour') } href = format == 'rss' and req.abs_href or req.href def produce((id, t, author, type, summary), status, fields, comment, cid): if status == 'edit': if 'ticket_details' in filters: info = u'' if len(fields) > 0: info = u', '.join([u'<i>%s</i>' % f for f in \ fields.keys()]) + u' modifié<br />' else: return None elif 'ticket' in filters: if status == 'closed' and fields.has_key('resolution'): info = fields['resolution'] if info and comment: info = '%s: ' % info else: info = '' else: return None kind, verb = status_map[status] if format == 'rss': title = u'Ticket #%s (%s %s): %s' % \ (id, translate(self.env, type).lower(), verb, summary) else: title = Markup( u'Ticket <em title="%s">#%s</em> (%s) %s par %s', summary, id, translate(self.env, type), verb, author) ticket_href = href.ticket(id) if cid: ticket_href += '#comment:' + cid if status == 'new': message = unicode(summary) else: message = Markup(info) if comment: if format == 'rss': message += wiki_to_html( comment, self.env, req, db, absurls=True) else: message += wiki_to_oneliner( comment, self.env, db, shorten=True) return kind, ticket_href, title, t, author, message
def expand_macro(self, formatter, name, content): db = self.env.get_read_db() cursor = db.cursor() cursor.execute( "SELECT text FROM wiki WHERE name=%s ORDER BY version DESC LIMIT 1", ("WikiStart", )) try: text = extract_client_text(cursor.fetchone()[0]) return wiki_to_html(text, self.env, formatter.req) except: return 'B0rken'
def end_process(self, numrows): notmodifiedcount = numrows - len(self.added) - len(self.modified) self.message = 'Scroll to see a preview of the tickets as they will be imported. If the data is correct, select the \'\'\'Execute Import\'\'\' button.\n' + ' * ' + str( numrows) + ' tickets will be imported (' + str(len( self.added)) + ' added, ' + str(len( self.modified)) + ' modified, ' + str( notmodifiedcount) + ' unchanged).\n' + self.message self.data['message'] = Markup(self.styles) + wiki_to_html( self.message, self.env, self.req) + Markup('<br/>') return 'import_preview.html', self.data, None
def _get_messages(self, req, cursor): cursor.execute("SELECT id, author, time, title, body FROM guestbook" " ORDER BY time") columns = ['id', 'author', 'time', 'title', 'body'] messages = [] for message in cursor: message = dict(zip(columns, message)) message['time'] = format_datetime(message['time']) message['title'] = wiki_to_oneliner(message['title'], self.env) message['body'] = wiki_to_html(message['body'], self.env, req) messages.append(message) return messages
def get_plans(self, req, cursor, suite_id): rows = [] columns = ('id', 'title', 'description') sql = "SELECT id, title, description FROM mtp_plans WHERE suite_id = %s" % suite_id self.log.debug(sql) cursor.execute(sql) for row in cursor: row = dict(zip(columns, row)) row['description'] = wiki_to_html(row['description'], self.env, req) rows.append(row) return rows
def process_request(self, req): req.perm.assert_permission('TICKET_CREATE') db = self.env.get_db_cnx() if req.method == 'POST' and not req.args.has_key('preview'): self._do_create(req, db) ticket = Ticket(self.env, db=db) ticket.populate(req.args) ticket.values.setdefault('reporter', util.get_reporter_id(req)) if ticket.values.has_key('description'): description = wiki_to_html(ticket['description'], self.env, req, db) req.hdf['newticket.description_preview'] = description req.hdf['title'] = 'New Ticket' req.hdf['newticket'] = ticket.values field_names = [field['name'] for field in ticket.fields if not field.get('custom')] if 'owner' in field_names: curr_idx = field_names.index('owner') if 'cc' in field_names: insert_idx = field_names.index('cc') else: insert_idx = len(field_names) if curr_idx < insert_idx: ticket.fields.insert(insert_idx, ticket.fields[curr_idx]) del ticket.fields[curr_idx] for field in ticket.fields: name = field['name'] del field['name'] if name in ('summary', 'reporter', 'description', 'type', 'status', 'resolution'): field['skip'] = True elif name == 'owner': field['label'] = 'Assign to' elif name == 'milestone': # Don't make completed milestones available for selection options = field['options'][:] for option in field['options']: milestone = Milestone(self.env, option, db=db) if milestone.is_completed: options.remove(option) field['options'] = options req.hdf['newticket.fields.' + name] = field add_stylesheet(req, 'common/css/ticket.css') return 'newticket.cs', None
def get_timeline_events(self, req, start, stop, filters): if 'changeset' in filters: format = req.args.get('format') show_files = int( self.config.get('timeline', 'changeset_show_files')) db = self.env.get_db_cnx() repos = self.env.get_repository() authzperm = SubversionAuthorizer(self.env, req.authname) rev = repos.youngest_rev while rev: if not authzperm.has_permission_for_changeset(rev): rev = repos.previous_rev(rev) continue chgset = repos.get_changeset(rev) if chgset.date < start: return if chgset.date < stop: message = chgset.message or '--' if format == 'rss': title = util.Markup('Changeset <em>[%s]</em>: %s', chgset.rev, util.shorten_line(message)) href = self.env.abs_href.changeset(chgset.rev) message = wiki_to_html(message, self.env, req, db, absurls=True) else: title = util.Markup('Changeset <em>[%s]</em> by %s', chgset.rev, chgset.author) href = self.env.href.changeset(chgset.rev) message = wiki_to_oneliner(message, self.env, db, shorten=True) if show_files: files = [] for chg in chgset.get_changes(): if show_files > 0 and len(files) >= show_files: files.append('...') break files.append('<span class="%s">%s</span>' % (chg[2], util.escape(chg[0]))) message = '<span class="changes">' + ', '.join(files) +\ '</span>: ' + message yield 'changeset', href, title, chgset.date, chgset.author,\ util.Markup(message) rev = repos.previous_rev(rev)
def get_changes(env, repos, revs, full=None, req=None, format=None): db = env.get_db_cnx() changes = {} for rev in revs: try: changeset = repos.get_changeset(rev) except NoSuchChangeset: changes[rev] = {} continue wiki_format = env.config['changeset'].getbool('wiki_format_messages') message = changeset.message or '--' absurls = (format == 'rss') if wiki_format: shortlog = wiki_to_oneliner(message, env, db, shorten=True, absurls=absurls) else: shortlog = Markup.escape(shorten_line(message)) if full: if wiki_format: message = wiki_to_html(message, env, req, db, absurls=absurls, escape_newlines=True) else: message = html.PRE(message) else: message = shortlog if format == 'rss': if isinstance(shortlog, Markup): shortlog = shortlog.plaintext(keeplinebreaks=False) message = unicode(message) changes[rev] = { 'date_seconds': changeset.date, 'date': format_datetime(changeset.date), 'age': pretty_timedelta(changeset.date), 'author': changeset.author or 'anonymous', 'message': message, 'shortlog': shortlog, } return changes
def milestone_to_hdf(env, db, req, milestone): hdf = {'name': milestone.name, 'href': req.href.milestone(milestone.name)} if milestone.description: hdf['description_source'] = milestone.description hdf['description'] = wiki_to_html(milestone.description, env, req, db) if milestone.due: hdf['due'] = milestone.due hdf['due_date'] = format_date(milestone.due) hdf['due_delta'] = pretty_timedelta(milestone.due + 86400) hdf['late'] = milestone.is_late if milestone.completed: hdf['completed'] = milestone.completed hdf['completed_date'] = format_datetime(milestone.completed) hdf['completed_delta'] = pretty_timedelta(milestone.completed) return hdf
def display_rss(self, req, query): query.verbose = True db = self.env.get_db_cnx() results = query.execute(db) for result in results: result['href'] = self.env.abs_href.ticket(result['id']) if result['reporter'].find('@') == -1: result['reporter'] = '' if result['description']: result['description'] = escape(wiki_to_html(result['description'] or '', self.env, req, db, absurls=1)) if result['time']: result['time'] = http_date(result['time']) req.hdf['query.results'] = results
def end_process(self, numrows): self.message = 'Scroll to see a preview of the tickets as they will be imported. If the data is correct, select the \'\'\'Execute Import\'\'\' button.\n' + ' * ' + str( numrows ) + ' tickets will be imported (' + str(self.added) + ' added, ' + str( self.modifiedcount) + ' modified, ' + str( self.notmodifiedcount) + ' unchanged).\n' + self.message self.req.hdf['report.description'] = Markup( self.styles ) + wiki_to_html(self.message, self.env, self.req) + Markup( '<br/><form action="importer" method="post"><input type="hidden" name="action" value="import" /><div class="buttons"><input type="submit" name="cancel" value="Cancel" /><input type="submit" value="Execute import" /></div></form>' ) self.req.hdf['report.numrows'] = numrows self.req.hdf['report.mode'] = 'list' return 'report.cs', None
def process_request(self, req): req.perm.assert_permission('DOXYGEN_VIEW') # Get request arguments path = req.args.get('path') action = req.args.get('action') # Get config variables index = self.config.get('doxygen', 'index', 'main.html') wiki_index = self.config.get('doxygen', 'wiki_index', None) # Redirect search requests. if action == 'search': req.redirect('%s?q=%s&doxygen=on' % (self.env.href.search(), req.args.get('query'))) # Retrun apropriate content to type or search request elif action == 'index': if wiki_index: # Get access to database db = self.env.get_db_cnx() cursor = db.cursor() # Get wiki index sql = "SELECT text FROM wiki WHERE name = %s" cursor.execute(sql, (wiki_index,)) text = Markup(system_message('Error', 'Wiki page %s does not' \ ' exists' % (wiki_index))) for row in cursor: text = wiki_to_html(row[0], self.env, req) # Display wiki index page req.hdf['doxygen.text'] = text return 'doxygen.cs', 'text/html' else: add_stylesheet(req, 'doxygen/css/doxygen.css') req.hdf['doxygen.path'] = path + '/' + index return 'doxygen.cs', 'text/html' elif action == 'file': type = mimetypes.guess_type(path)[0] if type == 'text/html': add_stylesheet(req, 'doxygen/css/doxygen.css') req.hdf['doxygen.path'] = path return 'doxygen.cs', 'text/html' else: req.send_file(path, type)
def display_ticket_page(self, req, ticketId): # This method is based on process_request() in TicketModule. # todo: security check should go here # --- For security, only display ticket if it's req.perm.assert_permission('TICKET_VIEW') action = req.args.get('action', 'view') db = self.env.get_db_cnx() ticket = Ticket(self.env, ticketId, db=db) reporter_id = req.args.get('author') req.hdf['ticket.debug'] = self.debug if req.method == 'POST': if not req.args.has_key('preview'): self.save_ticket_form_data(req, db, ticket) else: # Use user supplied values ticket.populate(req.args) req.hdf['ticket.action'] = action req.hdf['ticket.ts'] = req.args.get('ts') req.hdf['ticket.reassign_owner'] = req.args.get('reassign_owner') \ or req.authname req.hdf['ticket.resolve_resolution'] = req.args.get('resolve_resolution') reporter_id = req.args.get('author') comment = req.args.get('comment') if comment: req.hdf['ticket.comment'] = comment # Wiki format a preview of comment req.hdf['ticket.comment_preview'] = wiki_to_html(comment, self.env, req, db) else: req.hdf['ticket.reassign_owner'] = req.authname # Store a timestamp in order to detect "mid air collisions" req.hdf['ticket.ts'] = ticket.time_changed self.insert_ticket_data_to_hdf(req, db, ticket) add_stylesheet(req, 'common/css/ticket.css') return 'autotracticket.cs', None
def get_flat_messages(self, req, cursor, topic, time, order_by = 'ORDER BY time ASC'): columns = ('id', 'replyto', 'time', 'author', 'body') sql = "SELECT id, replyto, time, author, body FROM message WHERE" \ " topic = %s " + order_by self.log.debug(sql % (topic,)) cursor.execute(sql, (topic,)) messages = [] for row in cursor: row = dict(zip(columns, row)) row['author'] = wiki_to_oneliner(row['author'], self.env) row['body'] = wiki_to_html(row['body'], self.env, req) if int(row['time']) > time: row['new'] = True row['time'] = format_datetime(row['time']) messages.append(row) return messages
def _prepare_message_list(self, req, cursor, topic): # Get form values. new_author = req.args.get('author') new_subject = req.args.get('subject') new_body = req.args.get('body') # Get time when topic was visited from session. visited = eval(req.session.get('visited-topics') or '{}') if visited.has_key(topic['id']): visit_time = int(visited[topic['id']]) else: visit_time = 0 # Update this topic visit time and save to session. visited[topic['id']] = int(time.time()) req.session['visited-topics'] = to_unicode(visited) # Mark new topic. if int(topic['time']) > visit_time: topic['new'] = True # Prepare display of topic if new_author: req.hdf['discussion.author'] = wiki_to_oneliner( new_author, self.env) if new_subject: req.hdf['discussion.subject'] = wiki_to_oneliner( new_subject, self.env) if new_body: req.hdf['discussion.body'] = wiki_to_html(new_body, self.env, req) # Prepare display of messages display = req.session.get('message-list-display') or \ self.default_display req.hdf['discussion.display'] = display if display == 'flat-asc': req.hdf['discussion.messages'] = self.get_flat_messages( req, cursor, topic['id'], visit_time) elif display == 'flat-desc' or display == 'flat': req.hdf['discussion.messages'] = self.get_flat_messages( req, cursor, topic['id'], visit_time, 'ORDER BY time DESC') elif display == 'tree' or display == '': req.hdf['discussion.messages'] = self.get_messages( req, cursor, topic['id'], visit_time) else: raise TracError('Unsupported display mode: %s' % (display))
def _prepare_message_list(self, req, cursor, topic): # Get form values. new_author = req.args.get('author') new_subject = req.args.get('subject') new_body = req.args.get('body') # Get time when topic was visited from session. visited = eval(req.session.get('visited-topics') or '{}') if visited.has_key(topic['id']): visit_time = int(visited[topic['id']]) else: visit_time = 0 # Update this topic visit time and save to session. visited[topic['id']] = int(time.time()) req.session['visited-topics'] = to_unicode(visited) # Mark new topic. if int(topic['time']) > visit_time: topic['new'] = True # Prepare display of topic if new_author: req.hdf['discussion.author'] = wiki_to_oneliner(new_author, self.env) if new_subject: req.hdf['discussion.subject'] = wiki_to_oneliner(new_subject, self.env) if new_body: req.hdf['discussion.body'] = wiki_to_html(new_body, self.env, req) # Prepare display of messages display = req.session.get('message-list-display') or \ self.default_display req.hdf['discussion.display'] = display if display == 'flat-asc': req.hdf['discussion.messages'] = self.get_flat_messages(req, cursor, topic['id'], visit_time) elif display == 'flat-desc' or display == 'flat': req.hdf['discussion.messages'] = self.get_flat_messages(req, cursor, topic['id'], visit_time, 'ORDER BY time DESC') elif display == 'tree' or display == '': req.hdf['discussion.messages'] = self.get_messages(req, cursor, topic['id'], visit_time) else: raise TracError('Unsupported display mode: %s' % (display))
def get_timeline_events(self, req, start, stop, filters): if 'changeset' in filters: format = req.args.get('format') show_files = int(self.config.get('timeline', 'changeset_show_files')) db = self.env.get_db_cnx() repos = self.env.get_repository() authzperm = SubversionAuthorizer(self.env, req.authname) rev = repos.youngest_rev while rev: if not authzperm.has_permission_for_changeset(rev): rev = repos.previous_rev(rev) continue chgset = repos.get_changeset(rev) if chgset.date < start: return if chgset.date < stop: message = chgset.message or '--' if format == 'rss': title = util.Markup('Changeset <em>[%s]</em>: %s', chgset.rev, util.shorten_line(message)) href = self.env.abs_href.changeset(chgset.rev) message = wiki_to_html(message, self.env, req, db, absurls=True) else: title = util.Markup('Changeset <em>[%s]</em> by %s', chgset.rev, chgset.author) href = self.env.href.changeset(chgset.rev) message = wiki_to_oneliner(message, self.env, db, shorten=True) if show_files: files = [] for chg in chgset.get_changes(): if show_files > 0 and len(files) >= show_files: files.append('...') break files.append('<span class="%s">%s</span>' % (chg[2], util.escape(chg[0]))) message = '<span class="changes">' + ', '.join(files) +\ '</span>: ' + message yield 'changeset', href, title, chgset.date, chgset.author,\ util.Markup(message) rev = repos.previous_rev(rev)
def render_macro(self, req, name, content): path, start_line, end_line, rev = [arg.strip() for arg in content.split(',')][:4] start_line = int(start_line) end_line = int(end_line) repos = self.env.get_repository() node = repos.get_node(path, rev) text = node.get_content().read() text = re.split(r'\n|\r\n?', text) text = '\n'.join(text[(start_line - 1):(end_line - 1)]) ext = path.split('.')[-1].lower() comment = "%s@%s line %s - line %s by CodeSegment Macro" % (path, rev, start_line, end_line) if ext in langs: comment = langs[ext][1] % comment text = "{{{\n#!%s\n%s\n\n%s\n}}}" % (langs[ext][0], comment, text) else: text = "{{{\n%s\n\n%s\n}}}" % (comment, text) html = wiki_to_html(text, self.env, None) return html
def get_timeline_events(self, req, start, stop, filters): if 'milestone' in filters: format = req.args.get('format') db = self.env.get_db_cnx() cursor = db.cursor() cursor.execute("SELECT completed,name,description FROM milestone " "WHERE completed>=%s AND completed<=%s", (start, stop,)) for completed, name, description in cursor: title = Markup(u'Jalon <em>%s</em> completé', name) if format == 'rss': href = req.abs_href.milestone(name) message = wiki_to_html(description, self.env, req, db, absurls=True) else: href = req.href.milestone(name) message = wiki_to_oneliner(description, self.env, db, shorten=True) yield 'milestone', href, title, completed, None, message or '--'
def _process_log(self, req): """Handle AJAX log requests""" try: rev = int(req.args['logrev']) repos = self.env.get_repository(req.authname) chgset = repos.get_changeset(rev) wikimsg = wiki_to_html(chgset.message, self.env, req, None, True, False) data = { 'chgset': True, 'revision': rev, 'time': format_datetime(chgset.date), 'age': pretty_timedelta(chgset.date, None, 3600), 'author': chgset.author or 'anonymous', 'message': wikimsg, } return 'revtree_log.html', {'log': data}, 'application/xhtml+xml' except Exception, e: raise TracError, "Invalid revision log request: %s" % e
def source( req, argument_text, env, aswiki =False): from trac.versioncontrol.web_ui.util import get_existing_node, get_path_rev_line ## XXX above .util is shaded by trac.util? path,rev,line = get_path_rev_line( argument_text) from trac.mimeview import Mimeview, get_mimetype, content_to_unicode repos = env.get_repository() # req.authname) node = get_existing_node( env, repos, path, rev) content = node.get_content().read() if aswiki: mimetype = 'text/x-trac-wiki' r = wiki_to_html( content_to_unicode( env, content, mimetype), env=env, req=req) else: mimetype = get_mimetype( os.path.basename( path) ) or 'text/plain ' mimeview = Mimeview( env) #charset = mimeview.get_charset( content, mimetype) #node.content_type? #content = util.to_utf8( content, charset ) r = mimeview.render( req, mimetype, content) return r, None