make sure static subdir 404s correctly

before each request, we put the current service on the flask session,
except for with the static folder, cos it's not needed.... except, if
we 404, then we return the 404 template, which checks if you're logged
in or not to display different nav bar items. This was crashing when
current_service wasn't set, so we now set it.

also cleaned up some imports and stuff in test files
This commit is contained in:
Leo Hemsted
2017-05-04 11:28:45 +01:00
parent 50e4a8a50c
commit d6de5508ca
6 changed files with 14 additions and 21 deletions

View File

@@ -21,7 +21,7 @@ from flask import (
g,
url_for)
from flask._compat import string_types
from flask.globals import _lookup_req_object
from flask.globals import _lookup_req_object, _request_ctx_stack
from flask_login import LoginManager
from flask_wtf import CsrfProtect
from functools import partial
@@ -380,10 +380,10 @@ def load_user(user_id):
def load_service_before_request():
if '/static/' in request.url:
_request_ctx_stack.top.service = None
return
service_id = request.view_args.get('service_id', session.get('service_id')) if request.view_args \
else session.get('service_id')
from flask.globals import _request_ctx_stack
if _request_ctx_stack.top is not None:
_request_ctx_stack.top.service = service_api_client.get_service(service_id)['data'] if service_id else None