Exemple #1
0
    def __init__(self):
        self._set_env_config()
        self.APP_ROOT = os.path.dirname(__file__)
        self.TOP_WORDS_COUNT = 100
        self.ADMIN_WORDS_PER_PAGE = 100
        self.encryption = Encryption(self)
        self.http_client = AsyncHTTPClient()

        logger.debug('Create DB connection pool')
        self.db = Database(host=self.MYSQL_HOST,
                           port=self.MYSQL_PORT,
                           user=self.MYSQL_USER,
                           password=self.MYSQL_PASSWORD,
                           database=self.MYSQL_DATABASE)

        jinja2_env = jinja2.Environment(loader=jinja2.FileSystemLoader(
            os.path.join(self.APP_ROOT, 'templates')),
                                        autoescape=False)
        jinja2_loader = Jinja2Loader(jinja2_env)

        settings = dict(debug=self.DEBUG,
                        template_loader=jinja2_loader,
                        static_path=os.path.join(self.APP_ROOT, 'static'),
                        static_url_prefix='/static/')

        super().__init__(handlers=self._get_handlers(), **settings)
Exemple #2
0
	def __init__(self, root_dir, db, handlers=None, default_host=None, transforms=None, **settings):
		self.root_dir = root_dir
		self.data_dir = os.path.join(root_dir, 'data')
		if not os.path.exists(self.data_dir):
			os.mkdir(self.data_dir)

		self.db = db
		self.build_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'dist', 'layblr')

		if not handlers:
			handlers = list()

		handlers += [
			(r'/', 									RedirectHandler, dict(url='/index.html')),
			(r'/ajax/browse', 						BrowserHandler),
			(r'/ajax/export', 						ExportHandler),
			(r'/ajax/import', 						ImporterHandler),
			(r'/ajax/analyse/(?P<file>[^\/]+)',		AnalyseHandler),
			(r'/ajax/audio/(.+\.(mp3|wav))', 		StaticFileHandler, dict(path=self.root_dir)),
			# (r'/ajax/audio/(.+\.(mp3|wav))',		AudioFileHandler),

			(r'/api/project',												ProjectHandler),
			(r'/api/project/(?P<project_id>[0-9]+)',						ProjectDetailHandler),
			(r'/api/project/(?P<project_id>[0-9]+)/browse',					ProjectBrowseHandler),
			(r'/api/project/(?P<project_id>[0-9]+)/browse/(?P<path>.*)',	ProjectBrowseHandler),

			(r'/(.*)',								AppHandler, dict(path=self.build_dir)),
		]

		enable_pretty_logging()
		settings['template_path'] = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'template')
		settings['debug'] = True
		settings['autoreload'] = False

		jinja2_env = jinja2.Environment(
			loader=jinja2.FileSystemLoader(settings['template_path']),
			autoescape=True
		)
		jinja2_loader = Jinja2Loader(jinja2_env)
		settings['template_loader'] = jinja2_loader

		settings['default_handler_class'] = AppHandler

		super().__init__(handlers, default_host, transforms, **settings)
Exemple #3
0
    def __init__(self, router, port=80, **kwargs):

        self._initialize(**kwargs)

        self._settings = {
            r'handlers': router,
            r'debug': kwargs.get(r'debug', False),
            r'gzip': kwargs.get(r'gzip', False),
            r'log_function': self._log_request,
        }

        if r'template_path' in kwargs:
            self._settings[r'template_loader'] = Jinja2Loader(
                jinja2.Environment(
                    loader=jinja2.FileSystemLoader(kwargs[r'template_path'])))

        if r'static_path' in kwargs:
            self._settings[r'static_path'] = kwargs[r'static_path']

        if r'cookie_secret' in kwargs:
            self._settings[r'cookie_secret'] = kwargs[r'cookie_secret']

        self._sockets = bind_sockets(port)

        if self._process_num > 1:
            self._process_id = fork_processes(self._process_num)

        options.parse_command_line()

        AsyncIOMainLoop().install()

        self._event_loop = asyncio.get_event_loop()
        self._event_loop.set_debug(self._settings[r'debug'])

        self._server = HTTPServer(Application(**self._settings))

        signal.signal(signal.SIGINT, self.stop)
        signal.signal(signal.SIGTERM, self.stop)

        if self._async_initialize:
            self._event_loop.run_until_complete(self._async_initialize())
Exemple #4
0
    def __init__(self, port):
        root = os.path.dirname(__file__)

        static_dir = os.path.join(root, 'static')

        templates_dir = os.path.join(root, 'templates')
        jinja2_loader = Jinja2Loader(templates_dir)

        settings = {
            'static_path': static_dir,
            'template_loader': jinja2_loader,
        }

        handlers = [(r'/static/(.*)', web.StaticFileHandler, {
            'path': static_dir,
            'default_filename': 'index.html'
        }), (r'/(.*)', IndexHandler)]

        super(LinscheidServer, self).__init__(port=port,
                                              handlers=handlers,
                                              **settings)

        self.loop = IOLoop.instance()
        self.listen(port)
Exemple #5
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
应用描述
"""
import os

import jinja2
import tornado.web
from tornado_jinja2 import Jinja2Loader

from url import url

jinja2_env = jinja2.Environment(loader=jinja2.FileSystemLoader('template/'), autoescape=False)
jinja2_loader = Jinja2Loader(jinja2_env)

setting = {
    "login_url": "/login",
    # "cookie_secret": "vickwww",
    "template_path": os.path.join(os.path.dirname(__file__), "template"),
    "static_path": os.path.join(os.path.dirname(__file__), "static"),
    'xsrf_cookies': False,
    'template_loader': jinja2_loader
    # 'task_config_path': 'task/'
}

application = tornado.web.Application(
    handlers=url,
    debug=True,
    **setting
)
Exemple #6
0

jinja2env = Environment(
    loader=FileSystemLoader(os.path.join(BASE_DIR, 'common', 'templates')))
jinja2env.filters.update({
    'backend_name': filters.backend_name,
    'backend_class': filters.backend_class,
    'icon_name': filters.icon_name,
    'social_backends': filters.social_backends,
    'legacy_backends': filters.legacy_backends,
    'oauth_backends': filters.oauth_backends,
    'filter_backends': filters.filter_backends,
    'slice_by': filters.slice_by
})
jinja2env.globals.update({'url': url_for})
jinja2loader = Jinja2Loader(jinja2env)

tornado.options.parse_command_line()
tornado_settings = dict(
    (k, getattr(settings, k)) for k in dir(settings) if not k.startswith('__'))
tornado_settings['template_loader'] = jinja2loader
application = tornado.web.Application(
    SOCIAL_AUTH_ROUTES + [
        (r'/', MainHandler),
        (r'/done/', DoneHandler),
        (r'/email', EmailRequiredHandler),
        (r'/logout/', LogoutHandler),
    ],
    cookie_secret='adb528da-20bb-4386-8eaf-09f041b569e0',
    **tornado_settings)
Exemple #7
0
 def setUp(self):
     self.loader = Jinja2Loader(self.templates_path)
     self.template_obj = self.loader.load('page.html')
Exemple #8
0
 def setUp(self):
     self.jinja2_env = jinja2.Environment(
         loader=jinja2.FileSystemLoader(self.templates_path))
     self.loader = Jinja2Loader(self.jinja2_env)
     self.template_obj = self.loader.load('page.html')
Exemple #9
0
from edgebox import event
from jinja2 import Environment, PackageLoader
from tornado.options import define, options
from tornado_jinja2 import Jinja2Loader

__BASE_PACKAGE__ = "email_sender"
__BASE_DIR__ = os.path.dirname(os.path.abspath(__file__))

# TODO:read the local config
event.setup(host="192.168.6.200", type_mq=event.type_redis)

define("port", default=9995, help="run on the given port", type=int)
define("config", default=None, help="tornado config file")
define("conf", default=None, help="email_sender config path")

jinja2loader = Jinja2Loader('templates')

settings = {
    "host_ip": "10.201.0.1",
    "email": {
        "smtp_host": "smtp.exmail.qq.com",
        "smtp_port": 25,
        "mail_user": "******",
        "mail_pwd": "xxxxxxxxxxx",
    },
    "topic": "email",
    "log_dir": "/var/log",
    "template_loader": jinja2loader
}

Exemple #10
0
# -*- coding: utf-8 -*-

from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals

import jinja2

from tornado_jinja2 import Jinja2Loader


def field_errors(field):
    """给静态文件添加修改时间"""

    template = jinja2.Template("""
        {% if field.errors %}
            <ul class="errors">
                {% for error in field.errors %}
                    <li>{{ error }}</li>
                {% endfor %}
            </ul>
        {% endif %}
        """)
    return template.render(field=field)

enviroment = jinja2.Environment(loader=jinja2.FileSystemLoader('redisadmin/templates/'))
enviroment.filters['field_errors'] = field_errors
loader = Jinja2Loader(enviroment)