#!/usr/bin/python
import ConfigParser as configparser
+import StringIO
import accounts
import ads
from . import zeiterfassung
+DEFAULT_CONFIG = StringIO.StringIO("""
+[global]
+debug = false
+
+data_dir =
+static_dir = %(data_dir)s/static
+templates_dir = %(data_dir)s/templates
+""")
+
class Backend(object):
def __init__(self, configfile, debug=False):
# Read configuration file.
self.config = self.read_config(configfile)
- self.debug = debug
+
+ # Enable debug logging if configured
+ self.debug = debug or self.config.getboolean("global", "debug")
# Setup database.
self.setup_database()
def read_config(self, configfile):
cp = configparser.ConfigParser()
+
+ # Initialize configuration with some sensible defaults
+ cp.readfp(DEFAULT_CONFIG)
+
+ # Parse file
cp.read(configfile)
return cp
# Initialize backend
self.backend = ipfire.Backend(config)
- settings = dict(
- debug = tornado.options.options.debug,
- login_url = "/login",
- template_path = os.path.join(BASEDIR, "templates"),
- ui_methods = {
+ settings = {
+ # Do not compress responses
+ "gzip" : False,
+
+ # Enable XSRF cookies
+ "xsrf_cookies" : True,
+
+ # Login
+ "login_url" : "/login",
+
+ # Setup directory structure
+ "static_path" : self.backend.config.get("global", "static_dir"),
+ "template_path" : self.backend.config.get("global", "templates_dir"),
+
+ # UI Modules
+ "ui_methods" : {
"format_month_name" : self.format_month_name,
},
- ui_modules = {
+ "ui_modules" : {
"Advertisement" : AdvertisementModule,
"DonationBox" : DonationBoxModule,
"DonationButton" : DonationButtonModule,
"TalkLines" : TalkLinesModule,
"TalkOngoingCalls" : TalkOngoingCallsModule,
},
- xsrf_cookies = True,
- )
+ }
settings.update(kwargs)
tornado.web.Application.__init__(self, **settings)