本文整理汇总了Python中trac.wiki.wiki_to_html函数的典型用法代码示例。如果您正苦于以下问题:Python wiki_to_html函数的具体用法?Python wiki_to_html怎么用?Python wiki_to_html使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wiki_to_html函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: export_rss
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')
示例2: wiki
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
示例3: notify
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'])
示例4: render_discussion
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
示例5: get_timeline_events
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
示例6: end_process
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
示例7: process_request
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
示例8: get_topics
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
示例9: get_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;
示例10: get_timeline_events
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
示例11: process_request
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
示例12: parse
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
示例13: _display_edit
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
示例14: execute
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()
示例15: expand_macro
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'