forked from openlp/openlp
More updates and getting things working
This commit is contained in:
parent
a81cc8292b
commit
28a5f5c3fd
@ -57,6 +57,9 @@ def register_endpoint(end_point):
|
|||||||
static_route = _route_from_url(end_point.url_prefix, 'static')
|
static_route = _route_from_url(end_point.url_prefix, 'static')
|
||||||
static_route += '(.*)'
|
static_route += '(.*)'
|
||||||
application.add_static_route(static_route, end_point.static_dir)
|
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):
|
def check_auth(auth):
|
||||||
|
@ -32,13 +32,17 @@ class Endpoint(object):
|
|||||||
"""
|
"""
|
||||||
This is an endpoint for the HTTP API
|
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
|
Create an endpoint with a URL prefix
|
||||||
"""
|
"""
|
||||||
self.url_prefix = url_prefix
|
self.url_prefix = url_prefix
|
||||||
self.static_dir = static_dir
|
self.static_dir = static_dir
|
||||||
self.template_dir = template_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 = []
|
self.routes = []
|
||||||
|
|
||||||
def add_url_route(self, url, view_func, method):
|
def add_url_route(self, url, view_func, method):
|
||||||
@ -66,11 +70,9 @@ class Endpoint(object):
|
|||||||
if not self.template_dir:
|
if not self.template_dir:
|
||||||
raise Exception('No template directory specified')
|
raise Exception('No template directory specified')
|
||||||
path = os.path.abspath(os.path.join(self.template_dir, filename))
|
path = os.path.abspath(os.path.join(self.template_dir, filename))
|
||||||
print(path)
|
if self.static_dir:
|
||||||
print(self.static_dir)
|
kwargs['static_url'] = '/{prefix}/static'.format(prefix=self.url_prefix)
|
||||||
print('/{prefix}/static'.format(prefix=self.url_prefix))
|
kwargs['assets_url'] = '/assets'
|
||||||
# if self.static_dir:
|
|
||||||
# kwargs['static_url'] = '/{prefix}/static'.format(prefix=self.url_prefix)
|
|
||||||
return Template(filename=path, input_encoding='utf-8').render(**kwargs)
|
return Template(filename=path, input_encoding='utf-8').render(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,19 +65,7 @@ def stage_index(request):
|
|||||||
"""
|
"""
|
||||||
Deliver the page for the /stage url
|
Deliver the page for the /stage url
|
||||||
"""
|
"""
|
||||||
#file_name = request.path
|
return stage_endpoint.render_template('stage.mako', **TRANSLATED_STRINGS)
|
||||||
#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)
|
|
||||||
|
|
||||||
|
|
||||||
@main_endpoint.route('')
|
@main_endpoint.route('')
|
||||||
@ -85,7 +73,7 @@ def main_index(request):
|
|||||||
"""
|
"""
|
||||||
Deliver the page for the /main url
|
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('')
|
@blank_endpoint.route('')
|
||||||
|
@ -100,7 +100,7 @@ window.OpenLP = {
|
|||||||
}
|
}
|
||||||
text = text.replace(/\n/g, '<br />');
|
text = text.replace(/\n/g, '<br />');
|
||||||
if (slide["img"]) {
|
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));
|
var li = $("<li data-icon=\"false\">").append($("<a href=\"#\">").html(text));
|
||||||
if (slide["selected"]) {
|
if (slide["selected"]) {
|
||||||
|
@ -104,7 +104,7 @@ window.OpenLP = {
|
|||||||
}
|
}
|
||||||
// use thumbnail if available
|
// use thumbnail if available
|
||||||
if (slide["img"]) {
|
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
|
// use notes if available
|
||||||
if (slide["slide_notes"]) {
|
if (slide["slide_notes"]) {
|
@ -24,12 +24,12 @@
|
|||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1" />
|
<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1" />
|
||||||
<title>${app_title}</title>
|
<title>${app_title}</title>
|
||||||
<link rel="stylesheet" href="/static/assets/jquery.mobile.min.css" />
|
<link rel="stylesheet" href="${assets_url}/jquery.mobile.min.css" />
|
||||||
<link rel="stylesheet" href="/static/css/openlp.css" />
|
<link rel="stylesheet" href="${static_url}/css/openlp.css" />
|
||||||
<link rel="shortcut icon" type="image/x-icon" href="/static/images/favicon.ico">
|
<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="${assets_url}/jquery.min.js"></script>
|
||||||
<script type="text/javascript" src="/static/js/openlp.js"></script>
|
<script type="text/javascript" src="${static_url}/js/openlp.js"></script>
|
||||||
<script type="text/javascript" src="/static/assets/jquery.mobile.min.js"></script>
|
<script type="text/javascript" src="${assets_url}/jquery.mobile.min.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
translationStrings = {
|
translationStrings = {
|
||||||
"go_live": "${go_live}",
|
"go_live": "${go_live}",
|
||||||
|
@ -23,10 +23,10 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>${live_title}</title>
|
<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">
|
<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="${assets_url}/jquery.min.js"></script>
|
||||||
<script type="text/javascript" src="/static/js/main.js"></script>
|
<script type="text/javascript" src="${static_url}/js/main.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<img id="image" class="size"/>
|
<img id="image" class="size"/>
|
||||||
|
@ -23,10 +23,10 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>${stage_title}</title>
|
<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">
|
<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="${assets_url}/jquery.min.js"></script>
|
||||||
<script type="text/javascript" src="/static/js/stage.js"></script>
|
<script type="text/javascript" src="${static_url}/js/stage.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<input type="hidden" id="next-text" value="${next}" />
|
<input type="hidden" id="next-text" value="${next}" />
|
||||||
|
@ -79,9 +79,6 @@ def _make_response(view_result):
|
|||||||
body = json.dumps(body)
|
body = json.dumps(body)
|
||||||
response = Response(body=body, status=view_result[1],
|
response = Response(body=body, status=view_result[1],
|
||||||
content_type=content_type, charset='utf8')
|
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:
|
if len(view_result) >= 3:
|
||||||
response.headers.update(view_result[2])
|
response.headers.update(view_result[2])
|
||||||
return response
|
return response
|
||||||
@ -136,15 +133,9 @@ class WSGIApplication(object):
|
|||||||
"""
|
"""
|
||||||
Find the appropriate URL and run the view function
|
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
|
# First look to see if this is a static file request
|
||||||
for route, static_app in self.static_routes.items():
|
for route, static_app in self.static_routes.items():
|
||||||
if re.match(route, request.path):
|
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)
|
return request.get_response(static_app)
|
||||||
# If not a static route, try the views
|
# If not a static route, try the views
|
||||||
for route, views in self.route_map.items():
|
for route, views in self.route_map.items():
|
||||||
@ -176,7 +167,4 @@ class WSGIApplication(object):
|
|||||||
"""
|
"""
|
||||||
Shortcut for wsgi_app.
|
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)
|
return self.wsgi_app(environ, start_response)
|
||||||
|
Loading…
Reference in New Issue
Block a user