mirror of
https://github.com/Cian-H/invenio-theme-iform.git
synced 2025-12-22 20:51:58 +00:00
Switched blueprint creation to newer flask style
Noticed and cherry picked from tugraz theme during debugging of plugin
build issues. See:
62c572e483
This commit is contained in:
@@ -106,7 +106,9 @@ DEPOSITS_HEADER_TEMPLATE = "invenio_theme_iform/header.html"
|
|||||||
# SEARCH_UI_SEARCH_TEMPLATE = "invenio_theme_iform/search.html"
|
# SEARCH_UI_SEARCH_TEMPLATE = "invenio_theme_iform/search.html"
|
||||||
# """override the default search page"""
|
# """override the default search page"""
|
||||||
|
|
||||||
IFORM_ROUTES = {
|
THEME_IFORM_ROUTES = {
|
||||||
"index": "/",
|
"index": "/",
|
||||||
"comingsoon": "/comingsoon",
|
"comingsoon": "/comingsoon",
|
||||||
|
"records-search": "/records/search",
|
||||||
|
"overview": "/me/overview",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from flask import Blueprint, current_app, g, redirect, render_template, url_for
|
from flask import Blueprint, Flask, current_app, g, redirect, render_template, url_for
|
||||||
from flask_login import current_user, login_required
|
from flask_login import current_user, login_required
|
||||||
from invenio_rdm_records.proxies import current_rdm_records
|
from invenio_rdm_records.proxies import current_rdm_records
|
||||||
from invenio_records_global_search.resources.serializers import (
|
from invenio_records_global_search.resources.serializers import (
|
||||||
@@ -22,15 +22,30 @@ from opensearch_dsl.utils import AttrDict
|
|||||||
|
|
||||||
from .search import FrontpageRecordsSearch
|
from .search import FrontpageRecordsSearch
|
||||||
|
|
||||||
blueprint = Blueprint(
|
|
||||||
|
def create_blueprint(app: Flask) -> Blueprint:
|
||||||
|
"""Create blueprint."""
|
||||||
|
blueprint = Blueprint(
|
||||||
"invenio_theme_iform",
|
"invenio_theme_iform",
|
||||||
__name__,
|
__name__,
|
||||||
template_folder="templates",
|
template_folder="templates",
|
||||||
static_folder="static",
|
static_folder="static",
|
||||||
)
|
)
|
||||||
|
routes = app.config.get("THEME_IFORM_ROUTES")
|
||||||
|
|
||||||
|
blueprint.add_url_rule(routes["records-search"], view_func=records_search)
|
||||||
|
blueprint.add_url_rule(routes["index"], view_func=index)
|
||||||
|
blueprint.add_url_rule(routes["overview"], view_func=overview)
|
||||||
|
|
||||||
|
# base case for any otherwise unhandled exception
|
||||||
|
app.register_error_handler(Exception, default_error_handler)
|
||||||
|
|
||||||
|
blueprint.add_app_template_filter(make_dict_like)
|
||||||
|
blueprint.add_app_template_filter(cast_to_dict)
|
||||||
|
|
||||||
|
return blueprint
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route("/records/search")
|
|
||||||
def records_search():
|
def records_search():
|
||||||
"""Search page ui.
|
"""Search page ui.
|
||||||
|
|
||||||
@@ -70,7 +85,6 @@ def require_iform_authenticated(view_func):
|
|||||||
return decorated_view
|
return decorated_view
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route("/me/overview")
|
|
||||||
@login_required
|
@login_required
|
||||||
def overview():
|
def overview():
|
||||||
"""Overview."""
|
"""Overview."""
|
||||||
@@ -85,7 +99,6 @@ def overview():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@blueprint.app_template_filter("make_dict_like")
|
|
||||||
def make_dict_like(value: str, key: str) -> Dict[str, str]:
|
def make_dict_like(value: str, key: str) -> Dict[str, str]:
|
||||||
"""Convert the value to a dict like structure.
|
"""Convert the value to a dict like structure.
|
||||||
|
|
||||||
@@ -94,7 +107,6 @@ def make_dict_like(value: str, key: str) -> Dict[str, str]:
|
|||||||
return {key: value}
|
return {key: value}
|
||||||
|
|
||||||
|
|
||||||
@blueprint.app_template_filter("cast_to_dict")
|
|
||||||
def cast_to_dict(attr_dict):
|
def cast_to_dict(attr_dict):
|
||||||
"""Return the dict structure of AttrDict variable."""
|
"""Return the dict structure of AttrDict variable."""
|
||||||
return AttrDict.to_dict(attr_dict)
|
return AttrDict.to_dict(attr_dict)
|
||||||
@@ -112,18 +124,6 @@ def default_error_handler(e: Exception):
|
|||||||
return render_template(current_app.config["THEME_500_TEMPLATE"]), 500
|
return render_template(current_app.config["THEME_500_TEMPLATE"]), 500
|
||||||
|
|
||||||
|
|
||||||
def ui_blueprint(app):
|
|
||||||
"""Blueprint for the routes and resources provided by invenio-theme-iform."""
|
|
||||||
routes = app.config.get("IFORM_ROUTES")
|
|
||||||
|
|
||||||
blueprint.add_url_rule(routes["index"], view_func=index)
|
|
||||||
|
|
||||||
# base case for any otherwise unhandled exception
|
|
||||||
app.register_error_handler(Exception, default_error_handler)
|
|
||||||
|
|
||||||
return blueprint
|
|
||||||
|
|
||||||
|
|
||||||
def records_serializer(records=None):
|
def records_serializer(records=None):
|
||||||
"""Serialize list of records."""
|
"""Serialize list of records."""
|
||||||
serializer = GlobalSearchJSONSerializer()
|
serializer = GlobalSearchJSONSerializer()
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ test = "scripts.test:main"
|
|||||||
invenio_theme_iform = "invenio_theme_iform:InvenioThemeIform"
|
invenio_theme_iform = "invenio_theme_iform:InvenioThemeIform"
|
||||||
|
|
||||||
[project.entry-points."invenio_base.blueprints"]
|
[project.entry-points."invenio_base.blueprints"]
|
||||||
invenio_theme_iform = "invenio_theme_iform.views:ui_blueprint"
|
invenio_theme_iform = "invenio_theme_iform.views:create_blueprint"
|
||||||
|
|
||||||
[project.entry-points."invenio_i18n.translations"]
|
[project.entry-points."invenio_i18n.translations"]
|
||||||
messages = "invenio_theme_iform"
|
messages = "invenio_theme_iform"
|
||||||
|
|||||||
Reference in New Issue
Block a user