From 28a5f5c3fd656271f35febd91b12589655714b85 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 3 Jul 2016 08:26:09 +0100 Subject: [PATCH] More updates and getting things working --- openlp/core/api/http/__init__.py | 3 +++ openlp/core/api/http/endpoint/__init__.py | 14 ++++++++------ .../http/endpoint/{static => }/assets/jquery.js | 0 .../endpoint/{static => }/assets/jquery.min.js | 0 .../{static => }/assets/jquery.mobile.js | 0 .../{static => }/assets/jquery.mobile.min.css | 0 .../{static => }/assets/jquery.mobile.min.js | 0 openlp/core/api/http/endpoint/core.py | 16 ++-------------- .../core/api/http/endpoint/static/js/openlp.js | 2 +- .../static/{ => main/static}/css/main.css | 0 .../endpoint/static/{ => main/static}/js/main.js | 0 .../static/{ => stage/static}/css/stage.css | 0 .../static/{ => stage/static}/js/stage.js | 2 +- .../core/api/http/endpoint/templates/index.mako | 10 +++++----- .../core/api/http/endpoint/templates/main.mako | 6 +++--- .../core/api/http/endpoint/templates/stage.mako | 6 +++--- openlp/core/api/http/wsgiapp.py | 12 ------------ 17 files changed, 26 insertions(+), 45 deletions(-) rename openlp/core/api/http/endpoint/{static => }/assets/jquery.js (100%) rename openlp/core/api/http/endpoint/{static => }/assets/jquery.min.js (100%) rename openlp/core/api/http/endpoint/{static => }/assets/jquery.mobile.js (100%) rename openlp/core/api/http/endpoint/{static => }/assets/jquery.mobile.min.css (100%) rename openlp/core/api/http/endpoint/{static => }/assets/jquery.mobile.min.js (100%) rename openlp/core/api/http/endpoint/static/{ => main/static}/css/main.css (100%) rename openlp/core/api/http/endpoint/static/{ => main/static}/js/main.js (100%) rename openlp/core/api/http/endpoint/static/{ => stage/static}/css/stage.css (100%) rename openlp/core/api/http/endpoint/static/{ => stage/static}/js/stage.js (99%) diff --git a/openlp/core/api/http/__init__.py b/openlp/core/api/http/__init__.py index d98322015..983929625 100644 --- a/openlp/core/api/http/__init__.py +++ b/openlp/core/api/http/__init__.py @@ -57,6 +57,9 @@ def register_endpoint(end_point): static_route = _route_from_url(end_point.url_prefix, 'static') static_route += '(.*)' application.add_static_route(static_route, end_point.static_dir) + assets_route = _route_from_url('', 'assets') + assets_route += '(.*)' + application.add_static_route(assets_route, end_point.assets_dir) def check_auth(auth): diff --git a/openlp/core/api/http/endpoint/__init__.py b/openlp/core/api/http/endpoint/__init__.py index d7a09ab08..1acaca872 100644 --- a/openlp/core/api/http/endpoint/__init__.py +++ b/openlp/core/api/http/endpoint/__init__.py @@ -32,13 +32,17 @@ class Endpoint(object): """ This is an endpoint for the HTTP API """ - def __init__(self, url_prefix, template_dir=None, static_dir=None): + def __init__(self, url_prefix, template_dir=None, static_dir=None, assets_dir=None): """ Create an endpoint with a URL prefix """ self.url_prefix = url_prefix self.static_dir = static_dir self.template_dir = template_dir + if assets_dir: + self.assets_dir = assets_dir + else: + self.assets_dir = os.path.dirname(os.path.realpath(__file__)) self.routes = [] def add_url_route(self, url, view_func, method): @@ -66,11 +70,9 @@ class Endpoint(object): if not self.template_dir: raise Exception('No template directory specified') path = os.path.abspath(os.path.join(self.template_dir, filename)) - print(path) - print(self.static_dir) - print('/{prefix}/static'.format(prefix=self.url_prefix)) - # if self.static_dir: - # kwargs['static_url'] = '/{prefix}/static'.format(prefix=self.url_prefix) + if self.static_dir: + kwargs['static_url'] = '/{prefix}/static'.format(prefix=self.url_prefix) + kwargs['assets_url'] = '/assets' return Template(filename=path, input_encoding='utf-8').render(**kwargs) diff --git a/openlp/core/api/http/endpoint/static/assets/jquery.js b/openlp/core/api/http/endpoint/assets/jquery.js similarity index 100% rename from openlp/core/api/http/endpoint/static/assets/jquery.js rename to openlp/core/api/http/endpoint/assets/jquery.js diff --git a/openlp/core/api/http/endpoint/static/assets/jquery.min.js b/openlp/core/api/http/endpoint/assets/jquery.min.js similarity index 100% rename from openlp/core/api/http/endpoint/static/assets/jquery.min.js rename to openlp/core/api/http/endpoint/assets/jquery.min.js diff --git a/openlp/core/api/http/endpoint/static/assets/jquery.mobile.js b/openlp/core/api/http/endpoint/assets/jquery.mobile.js similarity index 100% rename from openlp/core/api/http/endpoint/static/assets/jquery.mobile.js rename to openlp/core/api/http/endpoint/assets/jquery.mobile.js diff --git a/openlp/core/api/http/endpoint/static/assets/jquery.mobile.min.css b/openlp/core/api/http/endpoint/assets/jquery.mobile.min.css similarity index 100% rename from openlp/core/api/http/endpoint/static/assets/jquery.mobile.min.css rename to openlp/core/api/http/endpoint/assets/jquery.mobile.min.css diff --git a/openlp/core/api/http/endpoint/static/assets/jquery.mobile.min.js b/openlp/core/api/http/endpoint/assets/jquery.mobile.min.js similarity index 100% rename from openlp/core/api/http/endpoint/static/assets/jquery.mobile.min.js rename to openlp/core/api/http/endpoint/assets/jquery.mobile.min.js diff --git a/openlp/core/api/http/endpoint/core.py b/openlp/core/api/http/endpoint/core.py index 1776ec42a..955f9d3dc 100644 --- a/openlp/core/api/http/endpoint/core.py +++ b/openlp/core/api/http/endpoint/core.py @@ -65,19 +65,7 @@ def stage_index(request): """ Deliver the page for the /stage url """ - #file_name = request.path - #html_dir = os.path.join(AppLocation.get_directory(AppLocation.AppDir), 'core', 'api', 'html') - #log.debug('serve file request {name}'.format(name=file_name)) - #if file_name.startswith('/'): - # file_name = file_name[1:] - #if not file_name: - # file_name = 'index.mako' - #if '.' not in file_name: - # file_name += '.html' - #if file_name.startswith('/'): - # file_name = file_name[1:] - #path = os.path.normpath(os.path.join(html_dir, file_name)) - return stage_endpoint.render_template('stage.mako', **TRANSLATED_STRINGS, static_url=static_dir) + return stage_endpoint.render_template('stage.mako', **TRANSLATED_STRINGS) @main_endpoint.route('') @@ -85,7 +73,7 @@ def main_index(request): """ Deliver the page for the /main url """ - return stage_endpoint.render_template('main.mako', **TRANSLATED_STRINGS) + return main_endpoint.render_template('main.mako', **TRANSLATED_STRINGS) @blank_endpoint.route('') diff --git a/openlp/core/api/http/endpoint/static/js/openlp.js b/openlp/core/api/http/endpoint/static/js/openlp.js index 929209b52..27193007c 100644 --- a/openlp/core/api/http/endpoint/static/js/openlp.js +++ b/openlp/core/api/http/endpoint/static/js/openlp.js @@ -100,7 +100,7 @@ window.OpenLP = { } text = text.replace(/\n/g, '
'); if (slide["img"]) { - text += ""; + text += ""; } var li = $("
  • ").append($("").html(text)); if (slide["selected"]) { diff --git a/openlp/core/api/http/endpoint/static/css/main.css b/openlp/core/api/http/endpoint/static/main/static/css/main.css similarity index 100% rename from openlp/core/api/http/endpoint/static/css/main.css rename to openlp/core/api/http/endpoint/static/main/static/css/main.css diff --git a/openlp/core/api/http/endpoint/static/js/main.js b/openlp/core/api/http/endpoint/static/main/static/js/main.js similarity index 100% rename from openlp/core/api/http/endpoint/static/js/main.js rename to openlp/core/api/http/endpoint/static/main/static/js/main.js diff --git a/openlp/core/api/http/endpoint/static/css/stage.css b/openlp/core/api/http/endpoint/static/stage/static/css/stage.css similarity index 100% rename from openlp/core/api/http/endpoint/static/css/stage.css rename to openlp/core/api/http/endpoint/static/stage/static/css/stage.css diff --git a/openlp/core/api/http/endpoint/static/js/stage.js b/openlp/core/api/http/endpoint/static/stage/static/js/stage.js similarity index 99% rename from openlp/core/api/http/endpoint/static/js/stage.js rename to openlp/core/api/http/endpoint/static/stage/static/js/stage.js index 48b1ebdc2..479181da8 100644 --- a/openlp/core/api/http/endpoint/static/js/stage.js +++ b/openlp/core/api/http/endpoint/static/stage/static/js/stage.js @@ -104,7 +104,7 @@ window.OpenLP = { } // use thumbnail if available if (slide["img"]) { - text += "

    "; + text += "

    "; } // use notes if available if (slide["slide_notes"]) { diff --git a/openlp/core/api/http/endpoint/templates/index.mako b/openlp/core/api/http/endpoint/templates/index.mako index 15fc96882..950fc29bc 100644 --- a/openlp/core/api/http/endpoint/templates/index.mako +++ b/openlp/core/api/http/endpoint/templates/index.mako @@ -24,12 +24,12 @@ ${app_title} - - + + - - - + + + - + + diff --git a/openlp/core/api/http/endpoint/templates/stage.mako b/openlp/core/api/http/endpoint/templates/stage.mako index f98e7e8c2..db4d81033 100644 --- a/openlp/core/api/http/endpoint/templates/stage.mako +++ b/openlp/core/api/http/endpoint/templates/stage.mako @@ -23,10 +23,10 @@ ${stage_title} - + - - + + diff --git a/openlp/core/api/http/wsgiapp.py b/openlp/core/api/http/wsgiapp.py index 1406e1035..00b2bfd66 100644 --- a/openlp/core/api/http/wsgiapp.py +++ b/openlp/core/api/http/wsgiapp.py @@ -79,9 +79,6 @@ def _make_response(view_result): body = json.dumps(body) response = Response(body=body, status=view_result[1], content_type=content_type, charset='utf8') - response.headers.add("Cache-Control", "no-cache, no-store, must-revalidate") - response.headers.add("Pragma", "no-cache") - response.headers.add("Expires", "0") if len(view_result) >= 3: response.headers.update(view_result[2]) return response @@ -136,15 +133,9 @@ class WSGIApplication(object): """ Find the appropriate URL and run the view function """ - # We are not interested in this so discard - if 'favicon' in request.path: - return # First look to see if this is a static file request for route, static_app in self.static_routes.items(): if re.match(route, request.path): - # Pop the path info twice in order to get rid of the "//static" - # request.path_info_pop() - request.path_info_pop() return request.get_response(static_app) # If not a static route, try the views for route, views in self.route_map.items(): @@ -176,7 +167,4 @@ class WSGIApplication(object): """ Shortcut for wsgi_app. """ - # We are not interested in this so discard - if 'favicon' in environ["PATH_INFO"]: - return return self.wsgi_app(environ, start_response)