-
Notifications
You must be signed in to change notification settings - Fork 20
/
application.py
68 lines (51 loc) · 1.79 KB
/
application.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
import os
import datetime
import mimetypes
from nereid import Nereid
from werkzeug.contrib.sessions import FilesystemSessionStore
from werkzeug.wsgi import SharedDataMiddleware
from nereid.contrib.locale import Babel
from nereid.sessions import Session
from raven.contrib.flask import Sentry
CWD = os.path.abspath(os.path.dirname(__file__))
DATABASE_NAME = os.environ.get('TRYTOND_DB_NAME', 'nereid_project')
SECRET_PATH = os.environ.get('SECRET_PATH', '.secret')
from trytond.config import config
config.update_etc()
APP_CONFIG = dict(
# The name of database
DATABASE_NAME=DATABASE_NAME,
# If the application is to be configured in the debug mode
DEBUG=False,
# The location where the translations of this template are stored
TRANSLATIONS_PATH='i18n',
SECRET_KEY=open(SECRET_PATH).read(),
WTF_CSRF_ENABLED=False,
)
# Create a new application
app = Nereid(static_folder='%s/static/' % CWD, static_url_path='/static')
# Update the configuration with the above config values
app.config.update(APP_CONFIG)
# Initialise the app, connect to cache and backend
app.initialise()
app.jinja_env.filters[
'float_to_time'] = lambda hours: "%dh %dm" % (hours, (hours * 60) % 60)
app.jinja_env.globals.update({
'datetime': datetime,
'guess_mimetype': mimetypes.guess_type,
})
# Setup the filesystem cache for session store.
# This wont work if you scale on more than one servers.
# Use something like redissessionstore or memcached store
app.session_interface.session_store = FilesystemSessionStore(
'/tmp', session_class=Session
)
Babel(app)
sentry = Sentry(app)
app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {
'/app': os.path.join(os.path.dirname(__file__), 'ng-app/app')
})
if __name__ == '__main__':
app.debug = True
app.run('0.0.0.0')