Convert ui methods into Flask globals
This commit is contained in:
parent
6a5d3d57cf
commit
29c68151de
31
atst/app.py
31
atst/app.py
@ -1,7 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
|
import re
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from redis import StrictRedis
|
from redis import StrictRedis
|
||||||
from flask import Flask
|
from flask import Flask, request, g
|
||||||
from unipath import Path
|
from unipath import Path
|
||||||
|
|
||||||
from atst.api_client import ApiClient
|
from atst.api_client import ApiClient
|
||||||
@ -24,6 +25,8 @@ def make_app(config):
|
|||||||
)
|
)
|
||||||
app.config.update(config)
|
app.config.update(config)
|
||||||
|
|
||||||
|
make_flask_callbacks(app)
|
||||||
|
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
assets.init_app(app)
|
assets.init_app(app)
|
||||||
|
|
||||||
@ -32,6 +35,21 @@ def make_app(config):
|
|||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
def make_flask_callbacks(app):
|
||||||
|
@app.before_request
|
||||||
|
def set_globals():
|
||||||
|
g.navigationContext = 'workspace' if re.match('\/workspaces\/[A-Za-z0-9]*', request.url) else 'global'
|
||||||
|
g.dev = os.getenv("TORNADO_ENV", "dev") == "dev"
|
||||||
|
g.matchesPath = lambda href: re.match('^'+href, request.url)
|
||||||
|
g.modalOpen = request.args.get("modal", False)
|
||||||
|
|
||||||
|
# TODO: Make me a macro
|
||||||
|
def modal(self, body):
|
||||||
|
return self.render_string(
|
||||||
|
"components/modal.html.to",
|
||||||
|
body=body)
|
||||||
|
|
||||||
|
|
||||||
# def make_app(config, deps, **kwargs):
|
# def make_app(config, deps, **kwargs):
|
||||||
# routes = [
|
# routes = [
|
||||||
# url(r"/", Root, {"page": "root"}, name="root"),
|
# url(r"/", Root, {"page": "root"}, name="root"),
|
||||||
@ -180,6 +198,15 @@ def make_deps(config):
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def map_config(config):
|
||||||
|
return {
|
||||||
|
"ENV": config["default"]["ENVIRONMENT"],
|
||||||
|
"DEBUG": config["default"]["DEBUG"],
|
||||||
|
"PORT": int(config["default"]["PORT"]),
|
||||||
|
"SQLALCHEMY_DATABASE_URI": config["default"]["DATABASE_URI"],
|
||||||
|
"SQLALCHEMY_TRACK_MODIFICATIONS": False,
|
||||||
|
**config["default"]
|
||||||
|
}
|
||||||
|
|
||||||
def make_config():
|
def make_config():
|
||||||
BASE_CONFIG_FILENAME = os.path.join(os.path.dirname(__file__), "../config/base.ini")
|
BASE_CONFIG_FILENAME = os.path.join(os.path.dirname(__file__), "../config/base.ini")
|
||||||
@ -212,4 +239,4 @@ def make_config():
|
|||||||
)
|
)
|
||||||
config.set("default", "DATABASE_URI", database_uri)
|
config.set("default", "DATABASE_URI", database_uri)
|
||||||
|
|
||||||
return config["default"]
|
return map_config(config)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from flask import Blueprint, render_template
|
from flask import Blueprint, render_template, g
|
||||||
|
|
||||||
bp = Blueprint("atst", __name__)
|
bp = Blueprint("atst", __name__)
|
||||||
|
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
{# TODO: set this context elsewhere #}
|
{# TODO: set this context elsewhere #}
|
||||||
{# set context='workspace' #}
|
{# set context='workspace' #}
|
||||||
{% set context=navigationContext() %}
|
{% set context=g.navigationContext %}
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<title>{% block title %}JEDI{% end %}</title>
|
<title>{% block title %}JEDI{% endblock %}</title>
|
||||||
{% for url in assets['css'].urls() %}
|
{% assets "css" %}
|
||||||
<link rel="stylesheet" href="{{ url }}" type="text/css">
|
<link rel="stylesheet" href="{{ ASSET_URL }}" type="text/css">
|
||||||
{% end %}
|
{% endassets %}
|
||||||
<link rel="icon" type="image/x-icon" href="/static/img/favicon.ico">
|
<link rel="icon" type="image/x-icon" href="/static/img/favicon.ico">
|
||||||
</head>
|
</head>
|
||||||
<body class="{% if modalOpen() %} modalOpen{% end %}">
|
<body class="{% if g.modalOpen %} modalOpen{% endif %}">
|
||||||
|
|
||||||
{% block template_vars %}{% end %}
|
{% block template_vars %}{% endblock %}
|
||||||
|
|
||||||
{% include 'navigation/topbar.html.to' %}
|
{% include 'navigation/topbar.html.to' %}
|
||||||
|
|
||||||
@ -23,18 +23,16 @@
|
|||||||
{% include 'navigation/global_navigation.html.to' %}
|
{% include 'navigation/global_navigation.html.to' %}
|
||||||
|
|
||||||
<div class='global-panel-container'>
|
<div class='global-panel-container'>
|
||||||
{% block sidenav %}{% end %}
|
{% block sidenav %}{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
these are not the droids you are looking for
|
these are not the droids you are looking for
|
||||||
{% end %}
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% include 'footer.html.to' %}
|
{% include 'footer.html.to' %}
|
||||||
|
|
||||||
{% block modal %}{% end %}
|
{% block modal %}{% endblock %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
{% extends "base.html.to" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
{% end %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user