From 29ac21c98b9733ab9cb967cc5ae51aa9b23bed19 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Fri, 24 May 2013 21:44:02 +0200 Subject: added production / devel mode to webui --- .gitignore | 1 + module/config/ConfigManager.py | 10 ++++++---- module/config/default.py | 1 + module/web/pyload_app.py | 16 ++++++++++++---- module/web/templates/default/base.html | 4 +++- module/web/webinterface.py | 11 +++++------ pavement.py | 6 ++++++ tests/helper/Stubs.py | 2 +- tests/manager/test_configManager.py | 5 +++++ 9 files changed, 40 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index c4a4deff0..e95306990 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,4 @@ pyload/* dist/* build/* env/* +js-optimized/ 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", "
") if error.traceback else "No Traceback"]) -# TODO: not working +# TODO: not working, no i18n strings should be on js files # @route("/static/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 @@ + + {# TODO precompile less, use when not in devel mode #} {% block css %} {% endblock %} - +