__init__.py 984 Bytes
Newer Older
Pierre Dittgen's avatar
Pierre Dittgen committed
1
import json
2
import os
3
from pathlib import Path
4
from urllib.parse import quote_plus
5

6 7
import flask
import jinja2
8

9 10
# Let this import after app initialisation
from . import config
11

Pierre Dittgen's avatar
wip  
Pierre Dittgen committed
12
# TODO: load config.toml
Pierre Dittgen's avatar
Pierre Dittgen committed
13 14 15 16 17 18
ui_config = json.load(config.UI_CONFIG_FILE.open('rt', encoding='utf-8')) if config.UI_CONFIG_FILE else []
schema_info_map = {}
for section in ui_config:
    for val in section['catalog']:
        if 'schema_url' in val:
            schema_info_map[val['schema_url']] = val
19 20

# Flask things
21
app = flask.Flask(__name__)
22 23
app.secret_key = config.SECRET_KEY

24

25 26 27 28
# Jinja2 url_quote_plus custom filter
# https://stackoverflow.com/questions/12288454/how-to-import-custom-jinja2-filters-from-another-file-and-using-flask
blueprint = flask.Blueprint('filters', __name__)

29

30 31 32 33 34 35
@jinja2.contextfilter
@blueprint.app_template_filter()
def urlencode(context, value):
    return quote_plus(value)


36 37
# Keep this import after app initialisation (to avoid cyclic imports)
from . import views  # isort:skip