本文整理汇总了Python中trac.mimeview.api.Context.req方法的典型用法代码示例。如果您正苦于以下问题:Python Context.req方法的具体用法?Python Context.req怎么用?Python Context.req使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.mimeview.api.Context
的用法示例。
在下文中一共展示了Context.req方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_project_events
# 需要导入模块: from trac.mimeview.api import Context [as 别名]
# 或者: from trac.mimeview.api.Context import req [as 别名]
def get_project_events(self, project, days, minutes):
""" List all events in project that happened in a given time span.
"""
events = []
project_href = Href(conf.url_projects_path + "/" + project.env_name)
req = DummyReq('user', 'password', 'method', 'uri', 'args')
req.permissions = (
'TICKET_VIEW', 'CHANGESET_VIEW', 'WIKI_VIEW', 'ATTACHMENT_VIEW', 'DISCUSSION_VIEW', 'MILESTONE_VIEW')
req.authname = 'authname'
req.abs_href = project_href
project_env = open_environment(conf.getEnvironmentSysPath(project.env_name), use_cache=True)
event_provider = ProjectTimelineEvents(project_env)
last_events = event_provider.get_timeline_events(req,
time_in_days=days,
time_in_minutes=minutes)
for event in last_events:
context = Context(resource=Resource(), href=project_href)
context.req = req
context.perm = req.perm
events.append([project, event, context])
events.sort(lambda x, y: cmp(y[1]['date'], x[1]['date']))
return events
示例2: convert_content
# 需要导入模块: from trac.mimeview.api import Context [as 别名]
# 或者: from trac.mimeview.api.Context import req [as 别名]
def convert_content(self, req, input_type, text, output_type):
page_name = req.args.get('page', 'WikiStart')
wikipage = WikiPage(self.env, page_name)
wikiprint = WikiPrint(self.env)
page = wikiprint.wikipage_to_html(text, page_name, req)
#Get page title from first header in outline
out = StringIO.StringIO()
context = Context(Resource('wiki', page_name), req.abs_href, req.perm)
context.req = req
outline = OutlineFormatter(self.env, context)
outline.format(text, out, 1, 1)
title = wikipage.name
for depth, anchor, text in outline.outline:
if depth == 1:
title = text
break
out = wikiprint.html_to_pdf(req, [page], book = (output_type == 'pdfbook'),
title=title,
subject="%s - %s" % (self.env.project_name, page_name),
version=str(wikipage.version),
date=format_datetime(to_datetime(None)))
return (out, 'application/pdf')
示例3: email_default_context
# 需要导入模块: from trac.mimeview.api import Context [as 别名]
# 或者: from trac.mimeview.api.Context import req [as 别名]
def email_default_context():
class NoEmailViewPerm(MockPerm):
def has_permission(self, action, realm_or_resource=None, id=False, version=False):
return action != "EMAIL_VIEW"
__contains__ = has_permission
context = Context(Resource("wiki", "WikiStart"), href=Href("/"), perm=NoEmailViewPerm())
context.req = None # 0.12 FIXME .req shouldn't be required by formatter
return context
示例4: wikipage_to_html
# 需要导入模块: from trac.mimeview.api import Context [as 别名]
# 或者: from trac.mimeview.api.Context import req [as 别名]
def wikipage_to_html(self, text, page_name, req):
"""
Converts a wiki text to HTML, and makes some replacements in order to fix
internal and external links and references
"""
self.env.log.debug('WikiPrint => Start function wikipage_to_html')
#Remove exclude expressions
for r in EXCLUDE_RES:
text = r.sub('', text)
#Escape [[PageOutline]], to avoid wiki processing
for r in [re.compile(r'\[\[TOC(\(.*\))?\]\]'), re.compile(r'\[\[PageOutline(\(.*\))?\]\]')]:
text = r.sub('![[pdf-toc]]', text)
for macro in self.omit_macros:
r = re.compile(r'\[\[' + macro + r'\(.*?\]\]')
text = r.sub('', text)
r = re.compile(r'^\{\{\{\r?\n#!' + macro + r'\r?\n(^.*\r?\n)*?^\}\}\}', re.MULTILINE)
text = r.sub('', text)
link_format = req.args.get('link_format', None)
if self.omit_links:
r1 = re.compile(r'\[wiki:(.*?) (.*?)\]')
text = r1.sub('[\g<2>]', text)
r2 = re.compile(r'\[wiki:(.*?)\]')
text = r2.sub('[\g<1>]', text)
elif link_format:
#Keep links to the same export format
r = re.compile(r'(?<=\[wiki:)(.*?)(?=(?: .*?)?\])')
text = r.sub('\g<1>?format=%s&link_format=%s' % (link_format, link_format), text)
if self.rebase_links:
r = re.compile(r'\[wiki:(.*?)\]')
text = r.sub('[%s/wiki/\g<1>]' % self.rebase_links, text)
self.env.log.debug('WikiPrint => Wiki input for WikiPrint: %r' % text)
#First create a Context object from the wiki page
context = Context(Resource('wiki', page_name), req.abs_href, req.perm)
context.req = req
#Now convert in that context
page = format_to_html(self.env, context, text)
self.env.log.debug('WikiPrint => Wiki to HTML output: %r' % page)
self.env.log.debug('WikiPrint => HTML output for WikiPrint is: %r' % page)
self.env.log.debug('WikiPrint => Finish function wikipage_to_html')
return page
示例5: refresh_project
# 需要导入模块: from trac.mimeview.api import Context [as 别名]
# 或者: from trac.mimeview.api.Context import req [as 别名]
def refresh_project(self, project_identifier, from_date, to_date=datetime.now(datefmt.localtz),
afilters=None, update=False):
"""
Will refresh a project events in cache in given date range.
.. NOTE::
Dates needs to be given in datefmt.localtz form
"""
# Initialize objects
project = Project.get(env_name=project_identifier)
if not project:
conf.log.warning('Project {0} is already removed from system or it cannot be found'.format(project_identifier))
return
e = open_environment(conf.getEnvironmentSysPath(project.env_name), use_cache=True)
pte = ProjectTimelineEvents(e)
providers = pte.event_providers
project_href = Href(conf.url_projects_path + '/' + project.env_name)
context = Context(resource=Resource(), href=project_href)
req = self._create_dummy_req(project_identifier)
context.req = req
context.perm = req.perm
# Read events from timeline
events = []
for provider in providers:
try:
# Use filters in parameter or check filters from providers
if afilters:
filters = afilters
else:
available_filters = provider.get_timeline_filters(req) or []
filters = [f[0] for f in available_filters]
for event in provider.get_timeline_events(req, from_date, to_date, filters):
event_data = self._event_data(provider, event)
if event_data['author'] != 'trac': # Skip system events
events.append(CachedEvent.from_event_data(project, event_data, context, filters[0]))
except:
conf.log.error("Could not read timeline events for %s from %s" % (project_identifier, str(provider)))
# Write events into sql table
self._write_events_into_cache(events, update)
示例6: trac_wiki
# 需要导入模块: from trac.mimeview.api import Context [as 别名]
# 或者: from trac.mimeview.api.Context import req [as 别名]
def trac_wiki(content):
resource = Resource()
context = Context(resource)
context.req = None
return format_to_html(TRAC_ENV, context, content)