本文整理汇总了Python中pyramid.config.Configurator.get_jinja2_environment方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.get_jinja2_environment方法的具体用法?Python Configurator.get_jinja2_environment怎么用?Python Configurator.get_jinja2_environment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.get_jinja2_environment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_jinja2_environment [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
# authn_policy = AuthTktAuthenticationPolicy(
# 'gabbleblotchits')
# authz_policy = SNMAuthorizationPolicy()
config = Configurator(
# authentication_policy=authn_policy,
# authorization_policy=authz_policy,
settings=settings
)
config.include("pyramid_jinja2")
config.commit()
config.get_jinja2_environment().filters['epoch2readable'] = epoch2readable
config.get_jinja2_environment().filters['duration'] = duration
def addSettings(event):
event["sci_platform"] = settings["sci_platform"]
event["google_tracking_code"] = settings["google_tracking_code"]
config.add_subscriber(addSettings, BeforeRender)
# Configuring static assets
config.add_static_view(name="static", path="static")
config.add_settings({"sci_platform": settings["sci_platform"],
"google_tracking_code": settings["google_tracking_code"]})
config.add_route("home", "/")
config.add_route("dsm", "/dsm")
config.add_route("app_used_with", "/application/{name}/used_with")
config.add_route("app_usage", "/application/{name}/usage")
config.add_route("app_users", "/application/{name}/users")
config.add_route("app_dashboard", "/application/{name}/dashboard")
config.add_route("application", "/application/{name}")
config.add_route("app_pubs", "/application/{name}/publications")
config.add_route("app_gitprojects", "/application/{name}/gitprojects")
config.add_route("compare", "/compare")
config.add_route("about", "/about")
config.add_route("data_source", "/data_source")
config.add_route("browse", "/browse")
config.add_route("overview", "/overview")
config.add_route("login", "/login")
config.add_route("notebook", "/notebook")
config.add_route("status", "/status")
config.add_route("sys_usage", "/status/usage")
config.add_route("accept_login", "/accept_login")
config.add_route("api_home", "/api")
config.add_route("api_home.category", "/api/{category}")
config.add_route("api_home.category.id", "/api/{category}/{id}")
connect(settings['db_name'])
register_connection('raw-records', settings['raw_db_name'])
config.scan()
return config.make_wsgi_app()
示例2: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_jinja2_environment [as 别名]
def main(global_config, **settings):
"""
`PasteDeploy app factory <http://pythonpaste.org/deploy/#paste-app-factory>`_
for the JASMIN cloud portal.
"""
config = Configurator(settings=settings)
# Use Beaker sessions
config.include("pyramid_beaker")
# We want to use Jinja2 templates
config.include("pyramid_jinja2")
# Force the creation of the environment
config.commit()
# Add our custom filters
config.get_jinja2_environment().filters.update({"markdown": jinja2_ext.markdown_filter})
# Set up the integration for the portal services
config.include("jasmin_cloud.auth")
config.include("jasmin_cloud.membership")
config.include("jasmin_cloud.cloud")
############################################################################
## Define routes
############################################################################
# Define a pass-through route for static content with caching
config.add_static_view(name="static", path="static", cache_max_age=3600)
config.add_route("home", "/")
# Route for FAQs
config.add_route("faqs", "/faqs")
# Route for XMLHttpRequest calls to get markdown preview
config.add_route("markdown_preview", "/markdown_preview")
# Single login and logout for all orgs
config.add_route("login", "/login")
config.add_route("logout", "/logout")
# User-specific routes
config.add_route("dashboard", "/dashboard")
# Org-specific routes
config.add_route("org_home", "/{org}")
config.add_route("users", "/{org}/users")
config.add_route("catalogue", "/{org}/catalogue")
config.add_route("catalogue_new", "/{org}/catalogue/new/{id}")
config.add_route("catalogue_delete", "/{org}/catalogue/delete/{id}")
config.add_route("machines", "/{org}/machines")
config.add_route("new_machine", "/{org}/machine/new/{id}")
config.add_route("machine_reconfigure", "/{org}/machine/{id}/reconfigure")
config.add_route("machine_add_disk", "/{org}/machine/{id}/add_disk")
config.add_route("machine_action", "/{org}/machine/{id}/action")
config.scan(ignore=[".test"])
return config.make_wsgi_app()
示例3: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_jinja2_environment [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
authn_policy = AuthTktAuthenticationPolicy('seekrit')
authz_policy = ACLAuthorizationPolicy()
my_session_factory = UnencryptedCookieSessionFactoryConfig('itsaseekreet')
config = Configurator(
settings=settings,
root_factory='scribeui_pyramid.modules.app.resources.RootFactory',
authentication_policy=authn_policy,
authorization_policy=authz_policy,
session_factory=my_session_factory
)
config.include('pyramid_jinja2')
config.include('.modules')
config.add_jinja2_search_path("scribeui_pyramid:templates")
environment = config.get_jinja2_environment()
environment.globals['time'] = get_rid()
environment.globals['getattr'] = jinja_getattr
config.add_static_view(
'static',
'scribeui_pyramid:static',
cache_max_age=3600
)
return config.make_wsgi_app()
示例4: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_jinja2_environment [as 别名]
def main(global_config, **settings): # pragma: no cover
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
session_factory = session_factory_from_settings(settings)
config = Configurator(settings=settings)
config.set_session_factory(session_factory)
config.set_root_factory(RootFactory)
config.set_request_property(remote_addr)
config.add_request_method(tagged_static_path)
config.include(pyramid_jinja2)
# Redis setup.
redis_conn = redis.StrictRedis.from_url(settings['redis.url'])
config.registry.settings['redis_conn'] = redis_conn
def _add_redis(event):
settings = event.request.registry.settings
event.request.redis = settings['redis_conn']
config.add_subscriber(_add_redis, NewRequest)
jinja2_env = config.get_jinja2_environment()
jinja2_env.filters['datetime'] = format_datetime
jinja2_env.filters['formatpost'] = format_post
jinja2_env.filters['isotime'] = format_isotime
jinja2_env.filters['markdown'] = format_markdown
jinja2_env.filters['markup'] = format_text
config.add_static_view('static', path='static', cache_max_age=3600)
config.scan()
return config.make_wsgi_app()
示例5: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_jinja2_environment [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()
示例6: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_jinja2_environment [as 别名]
def main(*args, **settings):
"""Initialize, and return a WSGI application."""
logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.WARNING)
engine = engine_from_config(settings, "sqlalchemy.")
DBSession.configure(bind=engine, expire_on_commit=False)
settings = dict(settings)
settings.setdefault("jinja2.i18n.domain", "arachcurator")
authn_policy = AuthTktAuthenticationPolicy("sosecret", callback=groupfinder, hashalg="sha512")
authz_policy = ACLAuthorizationPolicy()
config = Configurator(settings=settings, root_factory=ROOTFACTORYSPEC)
# config.add_translation_dirs('locale/')
config.include("pyramid_jinja2")
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.include(".models")
config.include(".routes")
config.scan()
config.commit()
jinja2_env = config.get_jinja2_environment()
jinja2_env.filters["curie"] = field_curie
return config.make_wsgi_app()
示例7: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_jinja2_environment [as 别名]
def main(global_config, **settings):
config = Configurator(settings=settings)
# Includes
config.include('pyramid_jinja2')
config.commit()
config.include('pyramid_scss')
# Database
db_url = urlparse(settings['mongo_uri'])
config.registry.db = MongoClient(host=db_url.hostname,
port=db_url.port)
def add_db(request):
db = config.registry.db[db_url.path[1:]]
if db_url.username and db_url.password:
db.authenticate(db_url.username, db_url.password)
return db
config.add_request_method(add_db, 'db', reify=True)
# Jinja Filters
jinja2_env = config.get_jinja2_environment()
# and Stripe and Paypal
jinja2_env.globals['stripe_pk'] = settings['stripe_pk']
jinja2_env.globals['paypal_id'] = settings['paypal_id']
jinja2_env.globals['btc_address'] = settings['btc_address']
jf = JinjaFilters(db=config.registry.db)
jf.set_filters(jinja2_env)
# Routing
add_auto_route(config, 'home', '/')
add_auto_route(config, 'stripe_charge', '/charge')
add_auto_route(config, 'about', '/about')
add_auto_route(config, 'region_switch', '{region:(us|eu)}')
add_auto_route(config, 'realm', '{region:(us|eu)}/{realm_slug}')
add_auto_route(config, 'item',
'{region:(us|eu)}/{realm_slug}/item/{item:\d+}')
add_auto_route(config, 'seller',
'{region:(us|eu)}/{realm_slug}/seller/{seller}')
# Static Files
config.add_route('favicon', '/favicon.ico')
config.add_route('robots', '/robots.txt')
config.add_route('sitemap', '/sitemap.xml')
config.add_view(view='etherealpost.favicon_view', route_name='favicon')
config.add_view(view='etherealpost.robots_view', route_name='robots')
config.add_view(view='etherealpost.sitemap_view', route_name='sitemap')
config.add_route('css', '/assets/css/{css_path:.*}.css')
config.add_view(route_name='css', view='pyramid_scss.controller.get_scss',
renderer='scss', request_method='GET')
config.add_static_view(name='assets', path='etherealpost:assets')
# Scan things
config.scan('.views')
# Here we gooooo!
return config.make_wsgi_app()
示例8: test_jinja2
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_jinja2_environment [as 别名]
def test_jinja2(self):
""" Auto-configure jinja2 if it's present """
settings = {}
config = Configurator(settings=settings)
config.include('pyramid_jinja2')
config.include('pike')
jinja_env = config.get_jinja2_environment()
self.assertTrue(hasattr(jinja_env, 'pike'))
示例9: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_jinja2_environment [as 别名]
def main(global_config, **settings):
""" This function returns a WSGI application.
"""
settings = dict(settings)
config = Configurator(root_factory=RootFactory, settings=settings)
# Set Unicode as default encoding
reload(sys)
sys.setdefaultencoding('utf-8')
database_config(config)
userdb_config(config)
auth_config(config)
celery_config(config)
locale_config(config)
check_server_list(config)
config.add_translation_dirs('gecoscc:locale/')
jinja2_config(config)
config.include('pyramid_jinja2')
config.include('pyramid_beaker')
config.include('pyramid_celery')
config.include('cornice')
jinja2_env = config.get_jinja2_environment()
jinja2_env.globals["include_file"] = include_file
jinja2_env.filters['env_override'] = env_override
def add_renderer_globals(event):
current_settings = get_current_registry().settings
event['help_manual_url'] = current_settings['help_manual_url']
config.add_subscriber(add_renderer_globals, 'pyramid.events.BeforeRender')
config.add_subscriber('gecoscc.i18n.setAcceptedLanguagesLocale',
'pyramid.events.NewRequest')
config.add_subscriber('gecoscc.i18n.add_localizer',
'pyramid.events.NewRequest')
config.add_subscriber('gecoscc.context_processors.set_version',
'pyramid.events.NewRequest')
route_config(config)
sockjs_config(config, global_config)
config.set_request_property(is_logged, 'is_logged', reify=True)
config.set_request_property(get_jobstorage, 'jobs', reify=True)
config.scan('gecoscc.views')
config.scan('gecoscc.api')
return config.make_wsgi_app()
示例10: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_jinja2_environment [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
config = Configurator(settings=settings)
config.registry.settings['jinja2'] = {
'block_start_string': '[%',
'block_end_string': '%]',
'variable_start_string': '[[',
'variable_end_string': ']]'
}
config.include('pyramid_jinja2')
print config.get_jinja2_environment()
config.include('myproject.fainit')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('todo', '/todo')
config.scan()
return config.make_wsgi_app()
示例11: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_jinja2_environment [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
authn_policy = AuthTktAuthenticationPolicy('rklain', callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()
config = Configurator(settings=settings, root_factory='myblog.models.RootFactory')
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.set_request_property(get_user, 'user', reify=True)
# routes/views
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_static_view('files', 'files', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
#User
#config.add_route('user_add', 'user/add')
config.add_route('user_edit', 'user/{id}/edit')
#config.add_route('user_delete', 'user/{id}/delete')
# Page
config.add_route('page_add', '/page/add')
config.add_route('page_view', '/page/{route}')
config.add_route('page_edit', '/page/{route}/edit')
config.add_route('page_delete', '/page/{route}/delete')
# Blog
config.add_route('post_add', '/blog/add')
config.add_route('post_view_y', '/blog/{year}')
config.add_route('post_view_ym', '/blog/{year}/{month}')
config.add_route('post_view_ymd', '/blog/{year}/{month}/{day}')
config.add_route('post_view', '/blog/{year}/{month}/{day}/{route}')
config.add_route('post_edit', '/blog/{year}/{month}/{day}/{route}/edit')
config.add_route('post_delete', '/blog/{year}/{month}/{day}/{route}/delete')
config.add_route('post_comment_delete', '/blog/{year}/{month}/{day}/{route}/comment/{id}/delete')
# Image
config.add_route('image_add', '/image/add')
config.add_route('image_view', '/image/{id}')
# config.add_route('image_edit', '/image/{route}/edit')
# config.add_route('image_delete', '/image/{route}/delete')
config.scan()
#jinja2
config.include('pyramid_jinja2')
#config.get_jinja2_environment().filters['rst2htmlbody'] = rst2htmlbody
config.get_jinja2_environment().filters['markdown'] = markup
return config.make_wsgi_app()
示例12: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_jinja2_environment [as 别名]
def main(global_config, **settings):
engine = engine_from_config(settings, 'sqlalchemy.')
db.configure(bind=engine)
Base.metadata.bind = engine
authn_policy = AuthTktAuthenticationPolicy('D24AD44D67115C79B2848FE932556', cookie_name='hd', domain='hostdown.co')
authz_policy = ACLAuthorizationPolicy()
my_session_factory = SignedCookieSessionFactory('2B156E211E49488AB4CD5B28BB763')
config = Configurator(settings=settings, session_factory=my_session_factory, root_factory=RootFactory)
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.include('pyramid_jinja2')
config.add_jinja2_search_path("pingrealm:templates")
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('index', '/')
config.add_route('terms', '/i/terms')
config.add_route('contact', '/i/contact')
config.add_route('rpc', '/api/xmlrpc')
# assert config.registry.settings['mongodb.database']
# connect(config.registry.settings['mongodb.database'])
config.scan()
config.commit()
config.get_jinja2_environment().filters['timeago'] = filters.time_ago_in_words
config.get_jinja2_environment().filters['format_number'] = filters.format_number
config.get_jinja2_environment().filters['markdown_file'] = filters.markdown_file
config.get_jinja2_environment().filters['urlshort'] = filters.urlshort
config.get_jinja2_environment().trim_blocks = True
config.get_jinja2_environment().lstrip_blocks = True
return config.make_wsgi_app()
示例13: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_jinja2_environment [as 别名]
def main(global_config, **settings):
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
config = Configurator(settings=settings)
config.add_jinja2_search_path("pastebunker:templates")
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('index', '/')
config.add_route('recent', '/recent')
config.add_route('about', '/about')
config.add_route('terms', '/terms')
config.add_route('public', '/public/{id}')
config.add_route('private', '/private/{id}')
config.scan()
config.commit()
config.get_jinja2_environment().filters['timeago'] = time_ago_in_words
config.get_jinja2_environment().filters['markdown'] = markdown_text
config.get_jinja2_environment().trim_blocks = True
config.get_jinja2_environment().lstrip_blocks = True
return config.make_wsgi_app()
示例14: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_jinja2_environment [as 别名]
def main(global_config, **settings):
""" This function returns the Pyramid WSGI application.
"""
config = Configurator(settings=settings)
# http://docs.pylonsproject.org/projects/pyramid_exclog/dev/api.html#pyramid_exclog.includeme
config.include('pyramid_exclog')
# https://docs.pylonsproject.org/projects/pyramid_jinja2/dev/api.html#pyramid_jinja2.includeme
config.include('pyramid_jinja2')
config.get_jinja2_environment().filters.update({
'date_format' : import_string('tumblrproxy.lib.template_filter.date_format'),
'tumblr_video' : import_string('tumblrproxy.lib.tumblr_filter.video_embed')
})
# view handler
config.include('tumblrproxy.controllers.blog')
# jinja2 configuration
config.add_jinja2_search_path("tumblrproxy:templates")
# static content route
config.add_static_view('static', 'static', cache_max_age=3600)
return config.make_wsgi_app()
示例15: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import get_jinja2_environment [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.include('pyramid_jinja2')
config.include('.models')
config.include('.routes')
config.scan()
config.commit()
config.add_request_method(
lambda x: config.get_jinja2_environment(),
'jinja2_env',
reify=True
)
return config.make_wsgi_app()