More updates and getting things working

This commit is contained in:
Tim Bentley 2016-07-03 08:26:09 +01:00
parent a81cc8292b
commit 28a5f5c3fd
17 changed files with 26 additions and 45 deletions

View File

@ -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):

View File

@ -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)

View File

@ -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('')

View File

@ -100,7 +100,7 @@ window.OpenLP = {
}
text = text.replace(/\n/g, '<br />');
if (slide["img"]) {
text += "<img src='" + slide["img"].replace("/thumbnails/", "/thumbnails88x88/") + "'>";
text += "<img src='" + slide["img"].replace("/thumbnails/", "/thumbnails/88x88/") + "'>";
}
var li = $("<li data-icon=\"false\">").append($("<a href=\"#\">").html(text));
if (slide["selected"]) {

View File

@ -104,7 +104,7 @@ window.OpenLP = {
}
// use thumbnail if available
if (slide["img"]) {
text += "<br /><img src='" + slide["img"].replace("/thumbnails/", "/thumbnails320x240/") + "'><br />";
text += "<br /><img src='" + slide["img"].replace("/thumbnails/", "/thumbnails/320x240/") + "'><br />";
}
// use notes if available
if (slide["slide_notes"]) {

View File

@ -24,12 +24,12 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1" />
<title>${app_title}</title>
<link rel="stylesheet" href="/static/assets/jquery.mobile.min.css" />
<link rel="stylesheet" href="/static/css/openlp.css" />
<link rel="stylesheet" href="${assets_url}/jquery.mobile.min.css" />
<link rel="stylesheet" href="${static_url}/css/openlp.css" />
<link rel="shortcut icon" type="image/x-icon" href="/static/images/favicon.ico">
<script type="text/javascript" src="/static/assets/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/openlp.js"></script>
<script type="text/javascript" src="/static/assets/jquery.mobile.min.js"></script>
<script type="text/javascript" src="${assets_url}/jquery.min.js"></script>
<script type="text/javascript" src="${static_url}/js/openlp.js"></script>
<script type="text/javascript" src="${assets_url}/jquery.mobile.min.js"></script>
<script type="text/javascript">
translationStrings = {
"go_live": "${go_live}",

View File

@ -23,10 +23,10 @@
<head>
<meta charset="utf-8" />
<title>${live_title}</title>
<link rel="stylesheet" href="/static/css/main.css" />
<link rel="stylesheet" href="${static_url}/css/main.css" />
<link rel="shortcut icon" type="image/x-icon" href="/static/images/favicon.ico">
<script type="text/javascript" src="/static/assets/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/main.js"></script>
<script type="text/javascript" src="${assets_url}/jquery.min.js"></script>
<script type="text/javascript" src="${static_url}/js/main.js"></script>
</head>
<body>
<img id="image" class="size"/>

View File

@ -23,10 +23,10 @@
<head>
<meta charset="utf-8" />
<title>${stage_title}</title>
<link rel="stylesheet" href="/static/css/stage.css" />
<link rel="stylesheet" href="${static_url}/css/stage.css" />
<link rel="shortcut icon" type="image/x-icon" href="/static/images/favicon.ico">
<script type="text/javascript" src="/static/assets/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/stage.js"></script>
<script type="text/javascript" src="${assets_url}/jquery.min.js"></script>
<script type="text/javascript" src="${static_url}/js/stage.js"></script>
</head>
<body>
<input type="hidden" id="next-text" value="${next}" />

View File

@ -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 "/<plugin>/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)