nereid-project/application.py

99 lines
2.9 KiB
Python
Raw Permalink Normal View History

2012-08-09 16:41:31 +02:00
# Activate the virutalenv
import os
cwd = os.path.abspath(os.path.dirname(__file__))
2012-10-05 11:38:35 +02:00
app_root_path = os.path.dirname(os.path.join(cwd, ''))
2012-08-09 16:41:31 +02:00
activate_this = '%s/bin/activate_this.py' % app_root_path
execfile(activate_this, dict(__file__=activate_this))
import random
import datetime
2012-08-09 16:41:31 +02:00
from nereid import Nereid
from werkzeug.contrib.sessions import FilesystemSessionStore
from nereid.sessions import Session
from nereid.contrib.locale import Babel
import simplejson as json
from raven import Client
from raven.middleware import Sentry
os.environ['PYTHON_EGG_CACHE'] = '%s/.egg_cache' % app_root_path
print '%s/static/' % cwd
CONFIG = dict(
# The name of database
DATABASE_NAME='openlabs_tryton',
2012-08-09 16:41:31 +02:00
EMAIL_FROM='info@openlabs.co.in',
2012-08-09 16:41:31 +02:00
# Static file root. The root location of the static files. The static/ will
# point to this location. It is recommended to use the web server to serve
# static content
STATIC_FILEROOT='%s/static/' % cwd,
2012-08-09 16:41:31 +02:00
# Tryton Config file path
TRYTON_CONFIG='%s/etc/trytond.conf' % app_root_path,
2012-08-09 16:41:31 +02:00
# Cache backend type
#CACHE_TYPE = 'werkzeug.contrib.cache.MemcachedCache',
# Cache Memcached Servers
# (Only if SESSION_STORE_CLASS or CACHE_TYPE is Memcached)
# eg: ['localhost:11211']
#CACHE_MEMCACHED_SERVERS = ['localhost:11211'],
#CACHE_MEMCACHED_SERVERS = ['mc1:11211', 'mc2:11211'],
# If the application is to be configured in the debug mode
DEBUG=False,
2012-08-09 16:41:31 +02:00
TEMPLATE_LOADER_CLASS='nereid.templating.FileSystemLoader',
TEMPLATE_SEARCH_PATH='%s' % cwd,
TRANSLATIONS_PATH='%s/i18n/' % cwd,
2012-08-09 16:41:31 +02:00
)
app = Nereid()
app.config.update(CONFIG)
app.initialise()
app.jinja_env.globals.update({
'json': json,
'sample': random.sample,
'datetime': datetime,
})
2012-08-09 16:41:31 +02:00
def float_to_time(hours):
"Converts a float of hours into readable hours and mins"
return "%dh %dm" % (hours, (hours * 60) % 60)
app.jinja_env.filters['float_to_time'] = float_to_time
2012-08-09 16:41:31 +02:00
babelized_app = Babel(app)
application = babelized_app.app.wsgi_app
2012-10-05 11:38:35 +02:00
application = Sentry(
application, Client(
'http://2d6a2e5316fb481993b3eeb6123d7203:'
'80855a8b88354bf5acca271f574b79db@sentry.openlabs.co.in/10'
)
2012-10-05 11:38:35 +02:00
)
2012-08-09 16:41:31 +02:00
# If the file is launched from the CLI then launch the app using the debug
# web server built into werkzeug
if __name__ == '__main__':
class NereidTestMiddleware(object):
def __init__(self, app, site):
self.app = app
self.site = site
def __call__(self, environ, start_response):
environ['HTTP_HOST'] = self.site
return self.app(environ, start_response)
2012-10-05 11:38:35 +02:00
site = 'my.openlabs.co.in:5000'
2012-08-09 16:41:31 +02:00
app.wsgi_app = NereidTestMiddleware(app.wsgi_app, site)
2012-10-05 11:38:35 +02:00
app.debug = False
2012-08-09 16:41:31 +02:00
app.static_folder = '%s/static' % (cwd,)
app.session_interface.session_store = \
FilesystemSessionStore('/tmp', session_class=Session)
2012-08-09 16:41:31 +02:00
app.run('0.0.0.0')