summaryrefslogtreecommitdiffstats
path: root/module/web
diff options
context:
space:
mode:
Diffstat (limited to 'module/web')
-rw-r--r--module/web/pyload_app.py16
-rw-r--r--module/web/templates/default/base.html4
-rw-r--r--module/web/webinterface.py11
3 files changed, 20 insertions, 11 deletions
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)