本文整理匯總了Python中jinja2.ChoiceLoader方法的典型用法代碼示例。如果您正苦於以下問題:Python jinja2.ChoiceLoader方法的具體用法?Python jinja2.ChoiceLoader怎麽用?Python jinja2.ChoiceLoader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jinja2
的用法示例。
在下文中一共展示了jinja2.ChoiceLoader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import jinja2 [as 別名]
# 或者: from jinja2 import ChoiceLoader [as 別名]
def __init__(self, template_file=None, flag_dep=False):
"""Constructor
The `Diagram` class constructor simply initializes object lists. It
does not create objects or relationships.
"""
self._flag_dep = flag_dep
self.clear()
loader_list = []
if template_file is not None:
loader_list.append(jinja2.FileSystemLoader(
os.path.abspath(os.path.dirname(template_file))))
self._template_file = os.path.basename(template_file)
else:
self._template_file = 'default.puml'
loader_list.append(jinja2.PackageLoader('hpp2plantuml', 'templates'))
self._env = jinja2.Environment(loader=jinja2.ChoiceLoader(
loader_list), keep_trailing_newline=True)
示例2: app_with_mail
# 需要導入模塊: import jinja2 [as 別名]
# 或者: from jinja2 import ChoiceLoader [as 別名]
def app_with_mail(app):
"""App with email test templates."""
app.register_blueprint(
Blueprint(
"invenio_app_ils_tests", __name__,
template_folder="templates"
)
)
# add extra test templates to the search app blueprint, to fake the
# existence of `invenio-theme` base templates.
test_templates_path = os.path.join(os.path.dirname(__file__), "templates")
enhanced_jinja_loader = jinja2.ChoiceLoader([
app.jinja_loader,
jinja2.FileSystemLoader(test_templates_path),
])
# override default app jinja_loader to add the new path
app.jinja_loader = enhanced_jinja_loader
yield app
示例3: register_loaders
# 需要導入模塊: import jinja2 [as 別名]
# 或者: from jinja2 import ChoiceLoader [as 別名]
def register_loaders(self, application=None):
user_path_loaders = [jinja2.FileSystemLoader(path)
for path in self.config.get('paths')]
user_package_loaders = [jinja2.PackageLoader(*package)
for package in self.config.get('packages')]
user_loaders = user_package_loaders + user_path_loaders
system_loaders = [jinja2.PackageLoader(*package)
for package in self.config.get('framework_packages')]
if self._debug_mode:
loaders = system_loaders + user_loaders
else:
loaders = user_loaders + system_loaders
kwargs = self.config.get('environment', {})
loader = jinja2.ChoiceLoader(loaders)
kwargs['loader'] = loader
self._choice_loader = loader
self._env = jinja2.Environment(**kwargs)
self._env.application = application
示例4: init_blueprint
# 需要導入模塊: import jinja2 [as 別名]
# 或者: from jinja2 import ChoiceLoader [as 別名]
def init_blueprint(self, blueprint, path='templates.yaml'):
"""Initialize a Flask Blueprint, similar to init_app, but without the access
to the application config.
Keyword Arguments:
blueprint {Flask Blueprint} -- Flask Blueprint instance to initialize (Default: {None})
path {str} -- path to templates yaml file, relative to Blueprint (Default: {'templates.yaml'})
"""
if self._route is not None:
raise TypeError("route cannot be set when using blueprints!")
# we need to tuck our reference to this Ask instance into the blueprint object and find it later!
blueprint.ask = self
# BlueprintSetupState.add_url_rule gets called underneath the covers and
# concats the rule string, so we should set to an empty string to allow
# Blueprint('blueprint_api', __name__, url_prefix="/ask") to result in
# exposing the rule at "/ask" and not "/ask/".
blueprint.add_url_rule("", view_func=self._flask_view_func, methods=['POST'])
blueprint.jinja_loader = ChoiceLoader([YamlLoader(blueprint, path)])
示例5: make_html_report
# 需要導入模塊: import jinja2 [as 別名]
# 或者: from jinja2 import ChoiceLoader [as 別名]
def make_html_report(self, html_filename=None, json_filename=None):
"""Generate html report from pychef stats."""
data = {"dose_plots": self.stats.to_dict()}
if html_filename:
logger.info("Writing html report to: %s", html_filename)
loader = ChoiceLoader(
[
PackageLoader("dials", "templates"),
PackageLoader("dials", "static", encoding="utf-8"),
]
)
env = Environment(loader=loader)
template = env.get_template("damage_analysis_report.html")
html = template.render(
page_title="Damage analysis report", dose_plots=data["dose_plots"]
)
with open(html_filename, "wb") as f:
f.write(html.encode("utf-8", "xmlcharrefreplace"))
if json_filename:
logger.info("Writing html report data to: %s", json_filename)
with open(json_filename, "w") as outfile:
json.dump(data, outfile)
示例6: make_html
# 需要導入模塊: import jinja2 [as 別名]
# 或者: from jinja2 import ChoiceLoader [as 別名]
def make_html(self, cosym_script):
"""Collect data from the individual observers and write the html."""
filename = cosym_script.params.output.html
if not filename:
return
self.data.update(CosymClusterAnalysisObserver().make_plots())
self.data.update(UnitCellAnalysisObserver().make_plots())
self.data.update(SymmetryAnalysisObserver().make_tables())
print("Writing html report to: %s" % filename)
loader = ChoiceLoader(
[
PackageLoader("dials", "templates"),
PackageLoader("dials", "static", encoding="utf-8"),
]
)
env = Environment(loader=loader)
template = env.get_template("cosym_report.html")
html = template.render(
page_title="DIALS cosym report",
cosym_graphs=self.data["cosym_graphs"],
unit_cell_graphs=self.data["unit_cell_graphs"],
symmetry_analysis=self.data["symmetry_analysis"],
)
with open(filename, "wb") as f:
f.write(html.encode("utf-8", "xmlcharrefreplace"))
示例7: generate_html_report
# 需要導入模塊: import jinja2 [as 別名]
# 或者: from jinja2 import ChoiceLoader [as 別名]
def generate_html_report(self, filename):
"""Generate a html report using the data."""
screw_axes_graphs = plot_screw_axes(self.data)
self.data["screw_axes"] = screw_axes_graphs
loader = ChoiceLoader(
[
PackageLoader("dials", "templates"),
PackageLoader("dials", "static", encoding="utf-8"),
]
)
env = Environment(loader=loader)
template = env.get_template("systematic_absences_report.html")
html = template.render(
page_title="DIALS systematic absences report",
screw_axes_graphs=self.data["screw_axes"],
)
with open(filename, "wb") as f:
f.write(html.encode("utf-8", "xmlcharrefreplace"))
示例8: init_app
# 需要導入模塊: import jinja2 [as 別名]
# 或者: from jinja2 import ChoiceLoader [as 別名]
def init_app(self, app):
"""Initializes the App.
Args:
app (TYPE): Description
Returns:
TYPE: Description
"""
config = app.config.copy()
self.debug = config.get('PONYWHOOSH_DEBUG', self.debug)
self.indexes_path = config.get('PONYWHOOSH_INDEXES_PATH', self.indexes_path)
self.search_string_min_len = config.get('PONYWHOOSH_MIN_STRING_LEN', self.search_string_min_len)
self.template_path = config.get('PONYWHOOSH_TEMPLATE_PATH', self.template_path)
self.url_route = config.get('PONYWHOOSH_URL_ROUTE', self.url_route)
self.writer_timeout = config.get('PONYWHOOSH_WRITER_TIMEOUT', self.writer_timeout)
if self.debug:
print('PONYWHOOSH_DEBUG: ', self.debug)
print('PONYWHOOSH_INDEXES_PATH : ', self.indexes_path)
print('PONYWHOOSH_MIN_STRING_LEN : ', self.search_string_min_len)
print('PONYWHOOSH_TEMPLATE_PATH: ', self.template_path)
print('PONYWHOOSH_URL_ROUTE: ', self.url_route)
print('PONYWHOOSH_WRITER_TIMEOUT: ', self.writer_timeout)
loader = jinja2.ChoiceLoader([
app.jinja_loader
, jinja2.FileSystemLoader(self.template_path)
])
app.jinja_loader = loader
app.add_url_rule(
self.url_route
, view_func=IndexView.as_view(self.url_route
, pw=self
, action_url_form=self.url_route
)
)
示例9: _init_environment
# 需要導入模塊: import jinja2 [as 別名]
# 或者: from jinja2 import ChoiceLoader [as 別名]
def _init_environment(self, extra_loaders=None):
"""
Create the Jinja templating environment.
"""
here = os.path.dirname(os.path.realpath(__file__))
loaders = []
if extra_loaders:
loaders.extend(extra_loaders)
paths = self.template_path
paths.extend([os.path.join(here, self.default_template_path),
os.path.join(here, self.template_skeleton_path)])
loaders.append(FileSystemLoader(paths))
self.environment = Environment(
loader= ChoiceLoader(loaders),
extensions=JINJA_EXTENSIONS
)
#Set special Jinja2 syntax that will not conflict with latex.
if self.jinja_logic_block_start:
self.environment.block_start_string = self.jinja_logic_block_start
if self.jinja_logic_block_end:
self.environment.block_end_string = self.jinja_logic_block_end
if self.jinja_variable_block_start:
self.environment.variable_start_string = self.jinja_variable_block_start
if self.jinja_variable_block_end:
self.environment.variable_end_string = self.jinja_variable_block_end
if self.jinja_comment_block_start:
self.environment.comment_start_string = self.jinja_comment_block_start
if self.jinja_comment_block_end:
self.environment.comment_end_string = self.jinja_comment_block_end
示例10: experiment_dashboard
# 需要導入模塊: import jinja2 [as 別名]
# 或者: from jinja2 import ChoiceLoader [as 別名]
def experiment_dashboard(exp_uid, app_id):
"""
Endpoint that renders the experiment dashboard.
Inputs: ::\n
(string) exp_uid, exp_uid for a current experiment.
"""
simple_flag = int(request.args.get('simple',0))
force_recompute = int(request.args.get('force_recompute',1))
if rm.get_experiment(exp_uid) is None:
return render_template('exp_404.html', exp_uid=exp_uid), 404
# Not a particularly good way to do this.
alg_label_list = rm.get_algs_for_exp_uid(exp_uid)
alg_list = [{'alg_label':alg['alg_label'],
'alg_label_clean':'_'.join(alg['alg_label'].split())}
for alg in alg_label_list]
# -- Directly use Jinja2 to load and render the app-specific dashboard template.
env = Environment(loader=ChoiceLoader([PackageLoader('apps.{}'.format(app_id),
'dashboard'),
PackageLoader('next.dashboard',
'templates')]))
template = env.get_template('myAppDashboard.html'.format(app_id)) # looks for /next/apps/{{ app_id }}/dashboard/{{ app_id }}.html
# The context we pass to the dashboard template.
ctx = dict(app_id=app_id,
exp_uid=exp_uid,
alg_list=alg_list,
exceptions_present=False,#exceptions_present(exp_uid),
url_for=url_for,
simple_flag=int(simple_flag),
force_recompute=int(force_recompute))
# Inject standard Flask context + context processors
current_app.update_template_context(ctx)
# Render the template
return template.render(**ctx)
示例11: render_to_string
# 需要導入模塊: import jinja2 [as 別名]
# 或者: from jinja2 import ChoiceLoader [as 別名]
def render_to_string(backend, filename, context):
# type: (str, str, Dict) -> str
"""
Render a template using the specified context
:param backend: The backend for which the template is rendered
:param filename: The template name
:param context: The data to use when rendering the template
:return: The rendered template as a string
"""
template_directory = "./swagger_django_generator/templates/{}".format(backend)
loaders = [jinja2.FileSystemLoader(template_directory)]
try:
import swagger_django_generator
loaders.append(jinja2.PackageLoader("swagger_django_generator", "templates/{}".format(backend)))
except ImportError:
pass
environment = jinja2.Environment(
loader=jinja2.ChoiceLoader(loaders),
trim_blocks=True,
lstrip_blocks=True,
)
environment.filters["clean_schema"] = clean_schema
environment.filters["parse_array"] = parse_array
return environment.get_template(filename).render(context)
示例12: _register_template_path
# 需要導入模塊: import jinja2 [as 別名]
# 或者: from jinja2 import ChoiceLoader [as 別名]
def _register_template_path(self):
if self._loaded:
return
self.log.debug('Adding %s to template path', TEMPLATE_DIR)
loader = FileSystemLoader([TEMPLATE_DIR])
env = self.settings['jinja2_env']
previous_loader = env.loader
env.loader = ChoiceLoader([previous_loader, loader])
self._loaded = True
示例13: _create_loader
# 需要導入模塊: import jinja2 [as 別名]
# 或者: from jinja2 import ChoiceLoader [as 別名]
def _create_loader(loaders=None):
if loaders is None:
loaders = [
jinja2.FileSystemLoader('.'),
]
return jinja2.ChoiceLoader(loaders)
示例14: loader
# 需要導入模塊: import jinja2 [as 別名]
# 或者: from jinja2 import ChoiceLoader [as 別名]
def loader(self):
if not self._choice_loader:
self._choice_loader = jinja2.ChoiceLoader()
return self._choice_loader
示例15: _get_j2env
# 需要導入模塊: import jinja2 [as 別名]
# 或者: from jinja2 import ChoiceLoader [as 別名]
def _get_j2env(self):
if self._j2env is None:
templates_dirs = [user_templates_dir]
for app_name, app_config in apps.app_configs.items():
app_events_template_dir = getattr(app_config, 'events_templates_dir', None)
if app_events_template_dir:
templates_dirs.append(app_events_template_dir)
templates_dirs.extend(self.extra_lookup_dirs)
self._j2env = Environment(loader=ChoiceLoader([FileSystemLoader(d) for d in templates_dirs]),
trim_blocks=True)
logger.debug('Jinja2 env loaded')
return self._j2env