# -*- coding: utf-8 -*- # # Copyright (C) 2020 mojib wali. # # invenio-theme-tugraz is free software; you can redistribute it and/or # modify it under the terms of the MIT License; see LICENSE file for more # details. """invenio module for TUGRAZ theme.""" from typing import Dict from elasticsearch_dsl.utils import AttrDict from flask import Blueprint, render_template from .search import FrontpageRecordsSearch blueprint = Blueprint( "invenio_theme_tugraz", __name__, template_folder="templates", static_folder="static", ) @blueprint.route("/") def index(): """Render frontpage view.""" return render_template( "invenio_theme_tugraz/index.html", records=FrontpageRecordsSearch()[:5].sort("-created").execute(), ) @blueprint.app_template_filter("make_dict_like") def make_dict_like(value: str, key: str) -> Dict[str, str]: """Convert the value to a dict like structure. in the form of a key -> value pair. """ return {key: value} @blueprint.app_template_filter("cast_to_dict") def cast_to_dict(attr_dict): """Return the dict structure of AttrDict variable.""" return AttrDict.to_dict(attr_dict)