diff options
Diffstat (limited to 'module')
-rw-r--r-- | module/config/ConfigManager.py | 10 | ||||
-rw-r--r-- | module/config/default.py | 1 | ||||
-rw-r--r-- | module/web/pyload_app.py | 16 | ||||
-rw-r--r-- | module/web/templates/default/base.html | 4 | ||||
-rw-r--r-- | module/web/webinterface.py | 11 |
5 files changed, 27 insertions, 15 deletions
diff --git a/module/config/ConfigManager.py b/module/config/ConfigManager.py index 85088020b..3290ed4ec 100644 --- a/module/config/ConfigManager.py +++ b/module/config/ConfigManager.py @@ -4,7 +4,7 @@ from new_collections import OrderedDict from module.Api import InvalidConfigSection -from module.utils import from_string, primary_uid, json +from module.utils import from_string, json from ConfigParser import ConfigParser @@ -60,8 +60,7 @@ class ConfigManager(ConfigParser): # Check if this config exists # Configs without meta data can not be loaded! data = self.config[section].config[option] - self.loadValues(user, section) - return self.values[user, section][option] + return self.loadValues(user, section)[option] except KeyError: pass # Returns default value later @@ -100,7 +99,10 @@ class ConfigManager(ConfigParser): return changed def saveValues(self, user, section): - self.db.saveConfig(section, json.dumps(self.values[user, section]), user) + if section in self.parser and user is None: + self.save() + elif (user, section) in self.values: + self.db.saveConfig(section, json.dumps(self.values[user, section]), user) def delete(self, section, user=None): """ Deletes values saved in db and cached values for given user, NOT meta data diff --git a/module/config/default.py b/module/config/default.py index dfa967284..8a2044281 100644 --- a/module/config/default.py +++ b/module/config/default.py @@ -67,6 +67,7 @@ def make_config(config): ("host", "ip", _("IP"), _("Tooltip"), "0.0.0.0"), ("https", "bool", _("Use HTTPS"), _("Tooltip"), False), ("port", "int", _("Port"), _("Tooltip"), 8001), + ("develop", "str", _("Development mode"), _(""), False), ]) config.addConfigSection("proxy", _("Proxy"), _("Description"), _("Long description"), diff --git a/module/web/pyload_app.py b/module/web/pyload_app.py index 483a47f07..ca2484a00 100644 --- a/module/web/pyload_app.py +++ b/module/web/pyload_app.py @@ -17,12 +17,12 @@ @author: RaNaN """ import time -from os.path import join +from os.path import join, exists from bottle import route, static_file, request, response, redirect, HTTPError, error from jinja2 import TemplateNotFound -from webinterface import PYLOAD, PROJECT_DIR, SETUP, env +from webinterface import PYLOAD, PROJECT_DIR, SETUP, DEVELOP, env from utils import render_to_response, login_required, set_session, get_user_api, is_mobile @@ -31,6 +31,13 @@ from utils import render_to_response, login_required, set_session, get_user_api, # Helper ########## +# Use optimized js when available +if exists(join(PROJECT_DIR, "static", "js-optimized")) and not DEVELOP: + js_path = "js-optimized" +else: + js_path = "js" + + # TODO: useful but needs a rewrite, too def pre_processor(): s = request.environ.get('beaker.session') @@ -45,7 +52,8 @@ def pre_processor(): return {"user": user, 'server': status, 'url': request.url , - 'ws': PYLOAD.getWSAddress()} + 'ws': PYLOAD.getWSAddress(), + 'js': js_path} def base(messages): @@ -61,7 +69,7 @@ def error500(error): return base(["An error occurred while processing the request.", error, error.traceback.replace("\n", "<br>") if error.traceback else "No Traceback"]) -# TODO: not working +# TODO: not working, no i18n strings should be on js files # @route("/static/js/<path:re:.+\.js>") def js_dynamic(path): response.headers['Expires'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", diff --git a/module/web/templates/default/base.html b/module/web/templates/default/base.html index 7785da01b..45d72d104 100644 --- a/module/web/templates/default/base.html +++ b/module/web/templates/default/base.html @@ -14,12 +14,14 @@ <link href="/static/css/select2.css" rel="stylesheet" type="text/css"/>
<link href="/static/css/font.css" rel="stylesheet" type="text/css"/>
<link href="/static/css/fontawesome.css" rel="stylesheet" type="text/css"/>
+
+ {# TODO precompile less, use when not in devel mode #}
<link href="/static/css/default/style.less" rel="stylesheet/less" type="text/css" media="screen"/>
{% block css %}
{% endblock %}
<script src="/static/js/libs/less-1.3.0.min.js" type="text/javascript"></script>
- <script type="text/javascript" data-main="static/js/config" src="/static/js/libs/require-2.1.5.js"></script>
+ <script type="text/javascript" data-main="static/{{ js }}/config" src="/static/{{ js }}/libs/require-2.1.5.js"></script>
<script type="text/javascript">
window.dates = {
weeks: ['week', 'weeks'],
diff --git a/module/web/webinterface.py b/module/web/webinterface.py index 2a9b5660b..c560bbc86 100644 --- a/module/web/webinterface.py +++ b/module/web/webinterface.py @@ -59,8 +59,8 @@ JS = JsEngine() TEMPLATE = config.get('webinterface', 'template')
DL_ROOT = config.get('general', 'download_folder')
-LOG_ROOT = config.get('log', 'log_folder')
PREFIX = config.get('webinterface', 'prefix')
+DEVELOP = config.get('webinterface', 'develop')
if PREFIX:
PREFIX = PREFIX.rstrip("/")
@@ -81,11 +81,10 @@ loader = PrefixLoader({ 'js': FileSystemLoader(join(PROJECT_DIR, 'media', 'js'))
})
-env = Environment(loader=loader, extensions=['jinja2.ext.i18n', 'jinja2.ext.autoescape'], trim_blocks=True, auto_reload=True,
- bytecode_cache=bcc)
+env = Environment(loader=loader, extensions=['jinja2.ext.i18n', 'jinja2.ext.autoescape'],
+ trim_blocks=True, auto_reload=DEVELOP is True, bytecode_cache=bcc)
# Filter
-
env.filters["type"] = lambda x: str(type(x))
env.filters["formatsize"] = format_size
env.filters["getitem"] = lambda x, y: x.__getitem__(y)
@@ -95,10 +94,9 @@ else: env.filters["url"] = lambda x: PREFIX + x if x.startswith("/") else x
# Locale
-
gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None])
translation = gettext.translation("django", join(PYLOAD_DIR, "locale"),
- languages=[config.get("general", "language"), "en"],fallback=True)
+ languages=[config.get("general", "language"), "en"], fallback=True)
translation.install(True)
env.install_gettext_translations(translation)
@@ -129,5 +127,6 @@ import api_app def run_server(host, port, server):
run(app=web, host=host, port=port, quiet=True, server=server)
+
if __name__ == "__main__":
run(app=web, port=8001)
|