def environment(**options): """ Setup Jinja2 environment: """ # Init environment env = Environment(**options) # Use template with some common context env.template_class = ContextTemplate # Add our custom filters env.filters.update( { "addcss": addcss, "total_time": total_time, "convert_speed": convert_speed, "convert_speed_kmh": convert_speed_kmh, "total_distance": total_distance, } ) # Add constants from settings keys = [ "DEBUG", "PIWIK_HOST", "PIWIK_ID", "FACEBOOK_ID", "LANGUAGES", "PAYMILL_PUBLIC", "HELP_URL", "PAYMENTS_ENABLED", "VERSION", ] env.globals.update(dict([(k, getattr(settings, k, None)) for k in keys])) # Setup translations translation = import_module("django.utils.translation") env.install_gettext_translations(translation, newstyle=False) # In Prod, skip auto_reload # and setup bytecode cache if not settings.DEBUG: env.auto_reload = False cache_dir = os.path.join(settings.HOME, "templates_cached") if not os.path.exists(cache_dir): os.mkdir(cache_dir) env.bytecode_cache = FileSystemBytecodeCache(cache_dir, "rr.%s.cache") return env
def environment(**options): ''' Setup Jinja2 environment: ''' # Init environment env = Environment(**options) # Use template with some common context env.template_class = ContextTemplate # Add our custom filters env.filters.update({ 'addcss': addcss, 'total_time': total_time, 'convert_speed': convert_speed, 'convert_speed_kmh': convert_speed_kmh, 'total_distance': total_distance, }) # Add constants from settings keys = [ 'DEBUG', 'PIWIK_HOST', 'PIWIK_ID', 'FACEBOOK_ID', 'LANGUAGES', 'PAYMILL_PUBLIC', 'HELP_URL', 'PAYMENTS_ENABLED', 'VERSION', ] env.globals.update(dict([(k, getattr(settings, k, None)) for k in keys])) # Setup translations translation = import_module('django.utils.translation') env.install_gettext_translations(translation, newstyle=False) # In Prod, skip auto_reload # and setup bytecode cache if not settings.DEBUG: env.auto_reload = False cache_dir = os.path.join(settings.HOME, 'templates_cached') if not os.path.exists(cache_dir): os.mkdir(cache_dir) env.bytecode_cache = FileSystemBytecodeCache(cache_dir, 'rr.%s.cache') return env
#!/usr/bin/env python #-*- coding:utf-8 -*- #-*- hack2me.com website -*- #-*- author:younger.shen -*- #Licensed under the Apache License, Version 2.0 (the "License"); #you may not use this file except in compliance with the License. #You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # utils.tools methods import web from jinja2 import Environment, PackageLoader _templates_dir = '../templates' _jinja_env = Environment(loader = PackageLoader('app', _templates_dir)) _jinja_env.auto_reload = True jinja = _jinja_env host_addr = web.ctx.protocol + '://' + web.ctx.host