本文整理汇总了Python中trac.web.chrome.Chrome.load_template方法的典型用法代码示例。如果您正苦于以下问题:Python Chrome.load_template方法的具体用法?Python Chrome.load_template怎么用?Python Chrome.load_template使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.web.chrome.Chrome
的用法示例。
在下文中一共展示了Chrome.load_template方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: filter_stream
# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import load_template [as 别名]
def filter_stream(self, req, method, filename, stream, data):
"""Return a filtered Genshi event stream, or the original unfiltered
stream if no match.
`req` is the current request object, `method` is the Genshi render
method (xml, xhtml or text), `filename` is the filename of the template
to be rendered, `stream` is the event stream and `data` is the data for
the current template.
See the Genshi documentation for more information.
"""
if filename == "query.html" and self.inject_query:
self.geoticket() # sanity check
chrome = Chrome(self.env)
variables = ("center_location", "radius")
_data = dict([(i, data.get(i)) for i in variables])
# georegions
_data["geo_column_label"] = None
_data["regions"] = None
if self.env.is_component_enabled(GeoRegions):
georegions = GeoRegions(self.env)
if georegions.enabled():
regions = georegions.regions()
if regions:
column, regions = regions
_data["geo_column_label"] = column
_data["regions"] = regions
_data["region"] = req.args.get("region")
template = chrome.load_template("geoquery.html")
stream |= Transformer("//fieldset[@id='columns']").after(template.generate(**_data))
return stream
示例2: render_ticket_action_control
# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import load_template [as 别名]
def render_ticket_action_control(self, req, ticket, action):
config = self.parse_config()
assert action in config
control = []
hints = []
data = config[action]
action_name = action # @@TODO: config'able label/name
chrome = Chrome(self.env)
from trac.ticket.web_ui import TicketModule
prepared_fields = TicketModule(self.env)._prepare_fields(req, ticket)
for field in data.get('fields', []):
id = "action_%s_%s" % (action, field)
operation = data.get('operations', {}).get(field, "change")
assert operation in ["change", "unset"]
if operation == "unset":
hints.append("%s will be unset" % field) # @@TODO: i18n
continue
assert operation == "change"
current_value = ticket._old.get(field, ticket[field]) or ""
rendered_control = ''
prepared_field = [pfield for pfield in prepared_fields
if pfield['name'] == field]
if len(prepared_field):
prepared_field = prepared_field[0]
# we can't use chrome.render_template here, or it will blow away
# key scripts like jquery.js and trac.js in the eventual 'primary' template
# that's rendered by process_request
template = chrome.load_template("ticket_fields.html", method="xhtml")
rendered_control = template.generate(ticket=ticket, field=prepared_field)
if rendered_control:
rendered_control = Markup(rendered_control)
control.append(tag.label(field,
rendered_control or tag.input(
name=id, id=id,
type='text', value=current_value)))
current_status = ticket._old.get('status', ticket['status'])
new_status = data['status'].get(current_status) or \
data['status']['*']
if new_status != '*':
hints.append("Next status will be %s" % new_status) # @@TODO: i18n
add_script(req, "workflow_ticketfields/workflow_ticketfields.js")
return (action_name, tag.div(*[tag.div(element, style=("display: inline-block; "
"margin-right: 1em"))
for element in control],
class_="workflow_ticket_fields",
style="margin-left: 2em; display: none"),
'. '.join(hints) + '.' if hints else '')
示例3: content
# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import load_template [as 别名]
def content(self, req, ticket):
tm = TicketMover(self.env)
projects = tm.projects(req.authname)
chrome = Chrome(self.env)
template = chrome.load_template('ticketmover-sidebar.html')
data = {'projects': projects,
'req': req,
'ticket': ticket}
return template.generate(**data)
示例4: feature_content
# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import load_template [as 别名]
def feature_content(self, req, ticket):
"""
returns content of a feature popup window
"""
if self.feature_popup:
chrome = Chrome(self.env)
_data = dict(req=req, ticket=ticket)
template = chrome.load_template(self.feature_popup)
return template.generate(**_data).render()
else:
return '<a href="%s">%s</a>' % (req.href("ticket", ticket.id), ticket["summary"])
示例5: get_stream
# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import load_template [as 别名]
def get_stream(self, req, method, filename, stream, original_data):
chrome = Chrome(self.env)
data = original_data
data['components'] = [component.name for component in trac.ticket.model.Component.select(self.env)]
data['logs'] = WorkLogTable.getByTicketId(self.env, data['ticket'].id)
template = chrome.load_template('work_log.html')
content_stream = template.generate(**(chrome.populate_data(req, data)))
chrome.add_jquery_ui(req)
add_stylesheet(req, 'trac/css/work-log.css')
return Transformer('//div[@id="ticket"]').after(content_stream)
示例6: filter_stream
# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import load_template [as 别名]
def filter_stream(self, req, method, filename, stream, data):
"""Return a filtered Genshi event stream, or the original unfiltered
stream if no match.
`req` is the current request object, `method` is the Genshi render
method (xml, xhtml or text), `filename` is the filename of the template
to be rendered, `stream` is the event stream and `data` is the data for
the current template.
See the Genshi documentation for more information.
"""
# only show CAPTCHAs for anonymous users
if req.authname != 'anonymous':
return stream
# only put CAPTCHAs in the realms specified
realm = self.realm(req)
if realm not in self.realms:
return stream
# add the CAPTCHA to the stream
if filename in self.xpath:
# store CAPTCHA in DB and session
word = random_word(self.dict_file)
insert_update(self.env, 'captcha', 'id', req.session.sid, dict(word=word))
req.session['captcha'] = word
req.session.save()
# render the template
chrome = Chrome(self.env)
template = chrome.load_template('captcha.html')
_data = {}
# CAPTCHA type
if self.captcha_type == 'png':
captcha = tag.img(None, src=req.href('captcha.png'))
else:
captcha = Markup(skimpyAPI.Pre(word).data())
_data['captcha'] = captcha
_data['email'] = req.session.get('email', '')
_data['name'] = req.session.get('name', '')
_data['captchaid'] = req.session.sid
xpath = self.xpath[filename]
stream |= Transformer(xpath).before(template.generate(**_data))
if filename in self.delete:
stream |= Transformer(self.delete[filename]).remove()
return stream
示例7: _format_plaintext
# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import load_template [as 别名]
def _format_plaintext(self, event):
data = dict(
event = event,
project_name = self.env.project_name,
project_desc = self.env.project_description,
project_link = self.env.project_url or self.env.abs_href(),
)
chrome = Chrome(self.env)
template = chrome.load_template(self.text_template_name,
method='text')
if template:
stream = template.generate(**data)
output = stream.render('text')
return output
示例8: get_stream
# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import load_template [as 别名]
def get_stream(self,req, method, filename, stream, original_data):
chrome = Chrome(self.env)
ticket_id = original_data['ticket'].id
data = original_data
data['objectlinks'] = self.get_links_for('ticket', ticket_id)
data['link_types'] = get_link_types()
data['components'] = [component.name for component in trac.ticket.model.Component.select(self.env)]
data['return_url'] = req.href.ticket(ticket_id)
template = chrome.load_template('ticket-links.html')
content_stream = template.generate(**(chrome.populate_data(req, data)))
chrome.add_jquery_ui(req)
add_script(req,'objectlinking/jquery-ui-autocomplete.js')
add_script(req,'objectlinking/search-links.js')
add_stylesheet(req, 'objectlinking/style.css')
add_stylesheet(req, 'objectlinking/jquery-ui-custom.css')
return Transformer('//div[@id="ticket"]').after(content_stream)
示例9: filter_stream
# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import load_template [as 别名]
def filter_stream(self, req, method, filename, stream, data):
"""Return a filtered Genshi event stream, or the original unfiltered
stream if no match.
`req` is the current request object, `method` is the Genshi render
method (xml, xhtml or text), `filename` is the filename of the template
to be rendered, `stream` is the event stream and `data` is the data for
the current template.
See the Genshi documentation for more information.
"""
if filename == 'ticket.html':
chrome = Chrome(self.env)
template = chrome.load_template('image-upload.html')
stream |= Transformer("//fieldset[@id='%s']" % self.fieldset_id).after(template.generate())
stream |= Transformer("//form[@id='propertyform']").attr('enctype', "multipart/form-data")
return stream
示例10: filter_stream
# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import load_template [as 别名]
def filter_stream(self, req, method, filename, stream, data):
if req.authname == 'anonymous':
return stream
if not self.c_name or not self.c_version:
return stream
user_dis_obj = UserDisclaimerModel(self.env)
valid = user_dis_obj.validate(req.authname, self.c_name, self.c_version)
if valid:
return stream
obj = DisclaimerModel(self.env)
disclaimer = obj.get_by_name_version(self.c_name,self.c_version)
if not disclaimer:
return stream
(id, author, body) = disclaimer
add_stylesheet(req, 'disclaimer/css/disclaimer.css')
add_javascript(req, 'disclaimer/js/disclaimer.js')
chrome = Chrome(self.env)
template = chrome.load_template("disclaimer.html")
data = dict(name=self.c_name, version=self.c_version, body=body)
data = chrome.populate_data(req, data)
stream |= Transformer('//div[@id="footer"]').append(template.generate(**data))
return stream
示例11: filter_stream
# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import load_template [as 别名]
def filter_stream(self, req, method, filename, stream, data):
"""Return a filtered Genshi event stream, or the original unfiltered
stream if no match.
`req` is the current request object, `method` is the Genshi render
method (xml, xhtml or text), `filename` is the filename of the template
to be rendered, `stream` is the event stream and `data` is the data for
the current template.
See the Genshi documentation for more information.
"""
if filename in [
"ticket.html",
"query.html",
"report_view.html",
"mapdashboard.html",
"regions_admin.html",
"wiki_view.html",
]:
# XXX random E fix for minimum lattitude that somehow
# works and I have no idea why
min_lat = max(-89.999999999, self.min_lat)
chrome = Chrome(self.env)
_data = dict(
req=req,
wms_url=self.wms_url,
min_lat=min_lat,
max_lat=self.max_lat,
min_lon=self.min_lon,
max_lon=self.max_lon,
)
template = chrome.load_template("layers.html")
stream |= Transformer("//script[@src='%s']" % self.openlayers_url).after(template.generate(**_data))
return stream
示例12: content
# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import load_template [as 别名]
def content(self, req, ticket):
chrome = Chrome(self.env)
template = chrome.load_template('image-sidebar.html')
imagetrac = ImageTrac(self.env)
if imagetrac:
images = imagetrac.images(ticket, req.href)
display = 'default'
else:
image = self.image(ticket)
link = req.href('attachment', 'ticket', ticket.id, image, format='raw')
images = dict(image=dict(original=link))
display = 'original'
# default ticket image
default = None
if self.env.is_component_enabled(DefaultTicketImage):
default = DefaultTicketImage(self.env).default_image(ticket.id)
# generate the template
return template.generate(display=display,
images=images,
req=req,
default=default,
ticket=ticket)
示例13: repr
# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import load_template [as 别名]
self.log.error("Failed to render %s", repr(text))
self.log.error(exception_to_unicode(e, traceback=True))
htmlmessage = text
else:
htmlmessage = "No message supplied."
data = {'sendername': sender[0],
'senderaddress': sender[1],
'comment': htmlmessage,
'links' : links,
'mode': mode,
'attachments': attachments,
'project_name': self.env.project_name,
'project_desc': self.env.project_description,
'project_link': self.env.project_url or self.env.abs_href()}
chrome = Chrome(self.env)
template = chrome.load_template(self.html_template_name)
if template:
stream = template.generate(**data)
output = stream.render()
return output
def _make_charset(self):
charset = Charset()
charset.input_charset = 'utf-8'
pref = self.mime_encoding.lower()
if pref == 'base64':
charset.header_encoding = BASE64
charset.body_encoding = BASE64
charset.output_charset = 'utf-8'
charset.input_codec = 'utf-8'
charset.output_codec = 'utf-8'
示例14: expand_macro
# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import load_template [as 别名]
def expand_macro(self, formatter, name, content, args=[]):
try:
cols = [] # Sentinel
group = '' # Sentinel
groups = {}
lines = content.split('\r\n')
for line in lines:
if line.startswith('||= href =||= '):
cols = line[14:].split(' =||= ')
elif line.startswith('|| group: '):
group = line[10:]
if group in [u'', u'None']:
group = None
groups[group] = [] # initialize for the group
elif line.startswith('|| '):
values = iter(line[3:].split(' || '))
ticket = {'href': values.next()}
for col in cols:
ticket[col] = values.next()
groups[group].append(ticket)
else:
pass
ticketsystem = TicketSystem(self.env)
#
labels = ticketsystem.get_ticket_field_labels()
headers = [{'name': col, 'label': labels.get(col, _('Ticket'))} for col in cols]
#
fields = {}
ticket_fields = ticketsystem.get_ticket_fields()
for field in ticket_fields:
fields[field['name']] = {'label': field['label']} # transform list to expected dict
# fail safe
fields[None] = 'NONE'
for group in groups.keys():
if not 'group' in fields:
fields[group] = group
#
group_name = 'group' in args and args['group'] or None
if group_name not in fields:
group_name = None
query = {'group': group_name}
#
groups = [(name, groups[name]) for name in groups] # transform dict to expected tuple
#
data = {
'paginator': None,
'headers': headers,
'query': query,
'fields': fields,
'groups': groups,
}
add_stylesheet(formatter.req, 'common/css/report.css')
chrome = Chrome(self.env)
data = chrome.populate_data(formatter.req, data)
template = chrome.load_template('query_results.html')
content = template.generate(**data)
# ticket id list as static
tickets = ''
if 'id' in cols:
ticket_id_list = [ticket.get('id') for group in groups for ticket in group[1]]
if len(ticket_id_list) > 0:
tickets = '([ticket:' + ','.join(ticket_id_list) + ' query by ticket id])'
return tag.div(content, format_to_html(self.env, formatter.context, tickets))
except StopIteration:
errorinfo = _('Not Enough fields in ticket: %s') % line
except Exception:
errorinfo = sys.exc_info()
return tag.div(tag.div(errorinfo, class_='message'), class_='error', id='content')