本文整理汇总了Python中pyramid.config.Configurator.add_jinja2_extension方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.add_jinja2_extension方法的具体用法?Python Configurator.add_jinja2_extension怎么用?Python Configurator.add_jinja2_extension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.add_jinja2_extension方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_jinja2_extension [as 别名]
def main(global_config, **settings):
""" This function returns a WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
get_root = appmaker(engine)
config = Configurator(settings=settings, root_factory=get_root)
# allow jinja2 templates! requires pyramid_jinja2 package.
config.include('pyramid_jinja2')
jinja2_extensions=[
# Allow arbitrary expressions:
'jinja2.ext.do',
# Add a trans block tag:
'jinja2.ext.i18n',
# Adds break, continue to for loops:
'jinja2.ext.loopcontrols',
# Add a with statement for explicit variable scopes:
'jinja2.ext.with_',
# Allow autoescaping to be disabled:
'jinja2.ext.autoescape',
]
for ext in jinja2_extensions:
config.add_jinja2_extension(ext)
config.add_jinja2_search_path("counterpoint:templates")
# add static files folder
config.add_static_view('static', 'counterpoint:static', cache_max_age=3600)
# add views
config.add_view('counterpoint.views.view_exercise',
context='counterpoint.models.MyRoot',
renderer="exercise.jinja2")
return config.make_wsgi_app()
示例2: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_jinja2_extension [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
set_cache_regions_from_settings(settings)
config = Configurator(settings=settings)
add_directives(config)
authn_policy = BasicAuthAuthenticationPolicy(check=auth_check_func)
authz_policy = ACLAuthorizationPolicy()
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('browse', '/browse')
config.add_route('simple', '/simple*traverse', factory=repository_root_factory)
config.add_notfound_view(notfound, append_slash=True)
config.add_jinja2_extension('webassets.ext.jinja2.AssetsExtension')
assets_env = config.get_webassets_env()
config.commit()
jinja2_env = config.get_jinja2_environment()
jinja2_env.assets_environment = assets_env
# config.add_webasset('test', jst)
config.add_webasset('papaye_js', papaye_js)
config.add_webasset('papaye_css', papaye_css)
config.add_webasset('papaye_font', papaye_font)
config.check_database_config()
config.scan()
config.start_scheduler()
return config.make_wsgi_app()
示例3: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_jinja2_extension [as 别名]
def main(global_config, **settings):
""" Return a Pyramid WSGI application. """
settings['config_uri'] = global_config['__file__']
# here we create the engine and bind it to the (not really a) session
# factory
configure_engine(settings)
from views import root_factory
config = Configurator(settings=settings, root_factory=root_factory)
config.add_translation_dirs('assembl:locale/')
config.set_locale_negotiator(my_locale_negotiator)
config.add_tween(
'assembl.tweens.virtuoso_deadlock.transient_deadlock_tween_factory',
under="pyramid_tm.tm_tween_factory")
config.include('.lib.zmqlib')
session_factory = session_factory_from_settings(settings)
config.set_session_factory(session_factory)
if not settings.get('nosecurity', False):
# import after session to delay loading of BaseOps
from auth import authentication_callback
auth_policy = SessionAuthenticationPolicy(
callback=authentication_callback)
config.set_authentication_policy(auth_policy)
config.set_authorization_policy(ACLAuthorizationPolicy())
# ensure default roles and permissions at startup
from models import get_session_maker
from auth.models import (
populate_default_roles, populate_default_permissions)
with transaction.manager:
session = get_session_maker()
populate_default_roles(session)
populate_default_permissions(session)
config.add_static_view('static', 'static', cache_max_age=3600)
config.include('cornice') # REST services library.
# config.include('.lib.alembic')
# config.include('.lib.email')
config.include('.views')
# config.scan('.lib')
config.scan('.views')
# jinja2
config.include('pyramid_jinja2')
config.add_jinja2_extension('jinja2.ext.i18n')
# Mailer
config.include('pyramid_mailer')
# Tasks
config.include('.tasks')
config.include('.view_def')
return config.make_wsgi_app()
示例4: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_jinja2_extension [as 别名]
def main(global_config, **settings):
""" This function returns a WSGI application.
It is usually called by the PasteDeploy framework during
``paster serve``.
"""
settings = dict(settings)
settings.setdefault('jinja2.i18n.domain', 'ziggurat_form_demo')
config = Configurator(settings=settings)
config.add_translation_dirs('locale/')
config.include('pyramid_jinja2')
config.add_jinja2_extension('jinja2.ext.do')
config.add_jinja2_search_path('ziggurat_form_demo:templates/')
config.add_route('/', '/')
config.add_route('forms', '/form/{view}')
config.scan()
config.add_static_view('static', 'static')
return config.make_wsgi_app()
示例5: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_jinja2_extension [as 别名]
def main(global_config, **settings):
""" Return a Pyramid WSGI application. """
settings['config_uri'] = global_config['__file__']
# here we create the engine and bind it to the (not really a) session
# factory
configure_engine(settings)
from views.traversal import root_factory
config = Configurator(registry=getGlobalSiteManager())
config.setup_registry(settings=settings, root_factory=root_factory)
config.add_translation_dirs('assembl:locale/')
def my_locale_negotiator(request):
locale = default_locale_negotiator(request)
available = settings['available_languages'].split()
locale = locale if locale in available else None
if not locale:
locale = request.accept_language.best_match(
available, settings.get('pyramid.default_locale_name', 'en'))
request._LOCALE_ = locale
return locale
config.set_locale_negotiator(my_locale_negotiator)
config.add_tween(
'assembl.tweens.virtuoso_deadlock.transient_deadlock_tween_factory',
under="pyramid_tm.tm_tween_factory")
# Tasks first, because it includes ZCA registration (for now)
config.include('.tasks')
config.include('pyramid_dogpile_cache')
config.include('.lib.zmqlib')
session_factory = session_factory_from_settings(settings)
config.set_session_factory(session_factory)
if not settings.get('nosecurity', False):
# import after session to delay loading of BaseOps
from auth.util import authentication_callback
auth_policy = SessionAuthenticationPolicy(
callback=authentication_callback)
config.set_authentication_policy(auth_policy)
config.set_authorization_policy(ACLAuthorizationPolicy())
# ensure default roles and permissions at startup
from models import get_session_maker
from .models.auth import (
populate_default_roles, populate_default_permissions)
with transaction.manager:
session = get_session_maker()
populate_default_roles(session)
populate_default_permissions(session)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_static_view('widget', 'widget', cache_max_age=3600)
config.include('cornice') # REST services library.
# config.include('.lib.alembic')
# config.include('.lib.email')
config.include('.views')
# config.scan('.lib')
config.scan('.views')
# jinja2
config.include('pyramid_jinja2')
config.add_jinja2_extension('jinja2.ext.i18n')
# Mailer
config.include('pyramid_mailer')
config.include('.view_def')
return config.make_wsgi_app()
示例6: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_jinja2_extension [as 别名]
def main(global_config, **settings):
""" Return a Pyramid WSGI application. """
settings['config_uri'] = global_config['__file__']
# here we create the engine and bind it to the (not really a) session
# factory
set_config(settings)
if not session_maker_is_initialized():
configure_engine(settings)
if settings.get('assembl_debug_signal', False):
from assembl.lib import signals
signals.listen()
from views.traversal import root_factory
config = Configurator(registry=getGlobalSiteManager())
config.setup_registry(settings=settings, root_factory=root_factory)
config.add_translation_dirs('assembl:locale/')
global locale_negotiator
locale_negotiator = my_locale_negotiator
config.set_locale_negotiator(my_locale_negotiator)
config.add_tween(
'assembl.tweens.virtuoso_deadlock.transient_deadlock_tween_factory',
under="pyramid_tm.tm_tween_factory")
# Tasks first, because it includes ZCA registration (for now)
config.include('.tasks')
config.include('pyramid_dogpile_cache')
config.include('.lib.zmqlib')
session_factory = session_factory_from_settings(settings)
config.set_session_factory(session_factory)
if not settings.get('nosecurity', False):
# import after session to delay loading of BaseOps
from auth.util import authentication_callback
auth_policy = SessionAuthenticationPolicy(
callback=authentication_callback)
config.set_authentication_policy(auth_policy)
config.set_authorization_policy(ACLAuthorizationPolicy())
# ensure default roles and permissions at startup
from models import get_session_maker
from .models.auth import (
populate_default_roles, populate_default_permissions)
with transaction.manager:
session = get_session_maker()
populate_default_roles(session)
populate_default_permissions(session)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_static_view('widget', 'widget', cache_max_age=3600)
config.include('cornice') # REST services library.
# config.include('.lib.alembic')
# config.include('.lib.email')
config.include('.views')
# config.scan('.lib')
config.scan('.views')
# jinja2
config.include('pyramid_jinja2')
config.add_jinja2_extension('jinja2.ext.i18n')
# Mailer
config.include('pyramid_mailer')
config.include('.view_def')
wsgi_app = config.make_wsgi_app()
if asbool(settings.get('sqltap', False)):
wsgi_app = sqltap.wsgi.SQLTapMiddleware(wsgi_app)
return wsgi_app
示例7: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_jinja2_extension [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
# Session factory (CSRF)
my_session_factory = SignedCookieSessionFactory(settings["session.secret"])
# SqlAlchemy:
engine = engine_from_config(settings, "sqlalchemy.default.")
DBSession.configure(bind=engine)
Base.metadata.bind = engine
try:
engine2 = engine_from_config(
settings,
"sqlalchemy.ea.",
pool_size=settings.get("sqla_ea_pool_size", 5),
max_overflow=settings.get("sqla_ea_max_overflow", 20),
pool_recycle=settings.get("sqla_ea_pool_recycle", 3600),
)
# For testing with SqlLite we need to have different engine setup
except TypeError:
engine2 = engine_from_config(settings, "sqlalchemy.ea.")
DBSession_EA.configure(bind=engine2)
Base_EA.metadata.bind = engine2
# Security
# authn_policy = RemoteUserAuthenticationPolicy(environ_key='REMOTE_USER', callback=groupfinder)
# authn_policy = AuthTktAuthenticationPolicy('sosecret', callback=groupfinder, hashalg='sha512')
authz_policy = ACLAuthorizationPolicy()
# Pyramid_multiauth seperate module for REMOTE_USER fallback
policies = [
RemoteUserAuthenticationPolicy(environ_key="HTTP_PROXY_AD_USER", callback=groupfinder),
AuthTktAuthenticationPolicy(settings["auth.secret"], callback=groupfinder, hashalg="sha512"),
]
authn_policy = MultiAuthenticationPolicy(policies)
config = Configurator(settings=settings, root_factory=RootFactory, session_factory=my_session_factory)
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
# Jinja:
# config.add_translation_dirs('locale/')
config.include("pyramid_jinja2")
# Cornice
config.include("cornice")
# Template locations
config.add_jinja2_search_path("arhea:templates")
# Supports updating objects in Jinja. Used in querysorter_m.jinja2
config.add_jinja2_extension("jinja2.ext.do")
# Register custom filter in Jinja
config.commit()
config.get_jinja2_environment().filters["dateformat"] = dateformat
config.get_jinja2_environment().filters["datetimeformat"] = datetimeformat
# Static
config.add_static_view(name="static", path="static", cache_max_age=3600)
# Admin Gateway url
config.add_route("admin_gtwy", settings["admin_gtwy"])
# Routes
config.add_route("home", "/")
# Security package sec include
config.include(".app_sec.include")
# Applications package apps include
config.include(".app_apps.include")
# HR package apps include
config.include(".app_hr.include")
# SD package apps include
config.include(".app_sd.include")
config.scan()
return config.make_wsgi_app()
示例8: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_jinja2_extension [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
session_factory = session_factory_from_settings(settings)
authn_policy = AuthTktAuthenticationPolicy('pyvor3',
callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()
config = Configurator(
settings=settings,
session_factory=session_factory,
authorization_policy=authz_policy,
authentication_policy=authn_policy
)
config.add_subscriber(handle_request, PasswordResetEvent)
config.add_subscriber(handle_request, NewRegistrationEvent)
config.add_subscriber(handle_request, RegistrationActivatedEvent)
config.add_subscriber(handle_request, ProfileUpdatedEvent)
config.registry.registerUtility(DBSession, ISession)
jst = Bundle('templates/*.html',
filters='jst',
output='jst.js', debug=False)
config.add_webasset('jst', jst)
# jinja2 configuration
config.add_jinja2_extension('jinja2.ext.i18n')
config.add_jinja2_extension('webassets.ext.jinja2.AssetsExtension')
config.add_jinja2_search_path(os.path.join(here, 'templates'))
config.add_jinja2_search_path("pyvore:templates")
jinja2_env = config.get_jinja2_environment()
assets_env = config.get_webassets_env()
jinja2_env.assets_environment = assets_env
renderer = jinja2_renderer_factory(
search_paths=(
'pyvore:templates/',
),
default_templates='deform_jinja2:bootstrap_templates',
translator=PyramidTranslator()
)
deform.Form.set_default_renderer(renderer)
# The are from pyramid_signup, we are overriding them to use CouchForm
# for rendering
override_forms = [
ISULoginForm, ISURegisterForm, ISUForgotPasswordForm,
ISUResetPasswordForm, ISUProfileForm
]
for form in override_forms:
config.registry.registerUtility(PyvoreForm, form)
config.registry.registerUtility(DBSession, ISUSession)
config.include('pyvore.routes')
config.scan()
return config.make_wsgi_app()
示例9: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_jinja2_extension [as 别名]
def main(global_config, **settings):
""" Return a Pyramid WSGI application. """
settings['config_uri'] = global_config['__file__']
# here we create the engine and bind it to the (not really a) session
# factory
settings = set_config(settings)
if not session_maker_is_initialized():
configure_engine(settings)
if settings.get('assembl_debug_signal', False):
from assembl.lib import signals
signals.listen()
import os
if 'UWSGI_ORIGINAL_PROC_NAME' in os.environ:
# uwsgi does not load logging properly
from pyramid.paster import setup_logging
setup_logging(global_config['__file__'])
# Sentry
import sentry_sdk
from sentry_sdk.integrations.pyramid import PyramidIntegration
if settings.get('sentry_dsn', ''):
sentry_sdk.init(
dsn=settings['sentry_dsn'],
integrations=[PyramidIntegration()]
)
from views.traversal import root_factory
config = Configurator(registry=getGlobalSiteManager())
config.setup_registry(settings=settings, root_factory=root_factory)
config.add_translation_dirs('assembl:locale/')
config.set_locale_negotiator(my_locale_negotiator)
config.add_tween(
'assembl.tweens.logging.logging_tween_factory',
over="pyramid_tm.tm_tween_factory")
config.include('.auth')
config.include('.models')
config.include('.indexing')
config.include('.lib.logging')
# Tasks first, because it includes ZCA registration (for now)
config.include('.tasks')
config.include('.lib.zmqlib')
session_factory = session_factory_from_settings(settings)
config.set_session_factory(session_factory)
if not settings.get('nosecurity', False):
# import after session to delay loading of BaseOps
from auth.util import authentication_callback
auth_policy_name = settings.get(
"auth_policy_class", "assembl.auth.util.UpgradingSessionAuthenticationPolicy")
auth_policy = resolver.resolve(auth_policy_name)(
callback=authentication_callback)
config.set_authentication_policy(auth_policy)
config.set_authorization_policy(ACLAuthorizationPolicy())
# ensure default roles and permissions at startup
from models import get_session_maker
if not settings.get('in_migration', False):
with transaction.manager:
session = get_session_maker()
from .lib.migration import bootstrap_db_data
bootstrap_db_data(session, settings['config_uri'] != "testing.ini")
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_static_view('static2', 'static2', cache_max_age=3600)
config.include('.graphql') # This MUST be above views import
config.include('cornice') # REST services library.
# config.include('.lib.alembic')
# config.include('.lib.email')
config.include('.lib')
config.include('.views')
# jinja2
config.include('pyramid_jinja2')
config.add_jinja2_extension('jinja2.ext.i18n')
# Mailer
config.include('pyramid_mailer')
config.include('.view_def')
wsgi_app = config.make_wsgi_app()
if asbool(settings.get('sqltap', False)):
import sqltap.wsgi
wsgi_app = sqltap.wsgi.SQLTapMiddleware(wsgi_app)
return wsgi_app
示例10: configure_application
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_jinja2_extension [as 别名]
def configure_application(settings, config=None):
# Provide deployment-independent settings
settings.update({
# Webassets
'webassets.base_dir': os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'static'
),
'webassets.base_url': '/static/',
# Jinja2
'jinja2.i18n.domain': 'sngconnect',
})
# Configure the database connection.
database_engine = sqlalchemy.engine_from_config(settings, 'database.')
DBSession.configure(bind=database_engine)
# Configure Cassandra connection.
cassandra_connection_pool.initialize_connection_pool(settings)
# Create application configurator.
if config is None:
config = Configurator(settings=settings)
else:
config.add_settings(settings)
config.registry['settings'] = settings
config.registry['database_engine'] = database_engine
# Configure ACL.
config.set_root_factory(RootFactory)
# Configure security.
authorization_policy = ACLAuthorizationPolicy()
config.set_authorization_policy(authorization_policy)
authentication_policy = AuthTktAuthenticationPolicy(
settings['session.secret'],
callback=User.authentication_callback
)
config.set_authentication_policy(authentication_policy)
# Configure session.
session_factory = UnencryptedCookieSessionFactoryConfig(
settings['session.secret']
)
config.set_session_factory(session_factory)
# Add translation directories.
config.add_translation_dirs(os.path.join(
os.path.dirname(__file__),
'locale'
))
# Set default timezone.
config.registry['default_timezone'] = pytz.timezone(
settings['sngconnect.default_timezone']
)
# Configure scheduler.
config.registry['scheduler'] = Scheduler()
register_jobs(config.registry, config.registry['scheduler'])
# Include add-ons.
config.include('pyramid_tm')
config.include('pyramid_jinja2')
config.include('pyramid_webassets')
config.include('pyramid_mailer')
# Configure asset bundles
for name, bundle in ASSET_BUNDLES.iteritems():
config.add_webasset(name, bundle)
# Add Jinja2 extensions.
config.add_jinja2_extension('jinja2.ext.with_')
config.add_jinja2_extension('webassets.ext.jinja2.AssetsExtension')
jinja2_environment = config.get_jinja2_environment()
config.registry['jinja2_environment'] = jinja2_environment
jinja2_environment.filters.update({
'tojson': template_filters.tojson,
'format_datetime': template_filters.format_datetime,
'format_date': template_filters.format_date,
'format_time': template_filters.format_time,
'format_number': template_filters.format_number,
'format_decimal': template_filters.format_decimal,
'format_currency': template_filters.format_currency,
})
jinja2_environment.assets_environment = config.get_webassets_env()
# Configure routes.
for name, pattern in ROUTES:
config.add_route(name, pattern)
# Add static views.
config.add_static_view(
name='static',
path='sngconnect:static',
cache_max_age=0
)
config.add_static_view(
name='device-images',
path=settings['sngconnect.device_image_upload_path'],
cache_max_age=0
)
config.add_static_view(
name='appearance-assets',
path=settings['sngconnect.appearance_assets_upload_path'],
cache_max_age=0
)
return config
示例11: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_jinja2_extension [as 别名]
def main(global_config, **settings):
# Provide deployment-independent settings
settings.update({
# Webassets
'webassets.base_dir': os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'static'
),
'webassets.base_url': settings.get('route.prefix', '') + '/static/',
# Jinja2
'jinja2.i18n.domain': 'alpaca',
})
# Configure database session.
database_engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=database_engine)
# Create configurator.
config = Configurator(settings=settings)
config.registry['settings'] = settings
# Configure ACL.
config.set_root_factory(RootFactory)
# Configure security.
authentication_policy = AuthTktAuthenticationPolicy(
settings['session.secret'],
callback=User.authentication_callback
)
config.set_authentication_policy(authentication_policy)
authorization_policy = ACLAuthorizationPolicy()
config.set_authorization_policy(authorization_policy)
# Configure session.
session_factory = UnencryptedCookieSessionFactoryConfig(
settings['session.secret']
)
config.set_session_factory(session_factory)
# Add translation directories.
config.add_translation_dirs(os.path.join(
os.path.dirname(__file__),
'locale'
))
# Include packages.
config.include('pyramid_tm')
config.include('pyramid_jinja2')
config.include('pyramid_webassets')
# Configure asset bundles.
for name, bundle in ASSET_BUNDLES.iteritems():
config.add_webasset(name, bundle)
# Add Jinja2 extensions.
config.add_jinja2_extension('jinja2.ext.with_')
config.get_jinja2_environment().filters['tojson'] = json.dumps
config.registry['jinja2_environment'] = config.get_jinja2_environment()
# Add webassets extension to Jinja2.
config.add_jinja2_extension('webassets.ext.jinja2.AssetsExtension')
webassets_environment = config.get_webassets_env()
config.get_jinja2_environment().assets_environment = webassets_environment
# Configure routes.
for name, pattern in ROUTES.iteritems():
config.add_route(name, pattern)
# Add static view.
config.add_static_view('static', 'static', cache_max_age=3600)
# Scan for view configuration.
config.scan()
return config.make_wsgi_app()