From cf848bdb78f39109237b6bf14c0789392970426f Mon Sep 17 00:00:00 2001 From: Dominik George <nik@naturalnet.de> Date: Wed, 29 Jan 2020 19:18:58 +0100 Subject: [PATCH] Add template tag for better widget inclusion --- aleksis/core/templates/core/index.html | 6 ++---- aleksis/core/templatetags/dashboard.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 aleksis/core/templatetags/dashboard.py diff --git a/aleksis/core/templates/core/index.html b/aleksis/core/templates/core/index.html index 60b0e2ec9..22d0d4013 100644 --- a/aleksis/core/templates/core/index.html +++ b/aleksis/core/templates/core/index.html @@ -1,5 +1,5 @@ {% extends 'core/base.html' %} -{% load i18n static %} +{% load i18n static dashboard %} {% block browser_title %}{% blocktrans %}Home{% endblocktrans %}{% endblock %} @@ -27,9 +27,7 @@ <div class="row" id="live_load"> {% for widget in widgets %} <div class="col s12 m12 l6 xl4"> - {% with widget as d_widget %} - {% include widget.template %} - {% endwith %} + {% include_widget widget %} </div> {% endfor %} </div> diff --git a/aleksis/core/templatetags/dashboard.py b/aleksis/core/templatetags/dashboard.py new file mode 100644 index 000000000..d9615970c --- /dev/null +++ b/aleksis/core/templatetags/dashboard.py @@ -0,0 +1,13 @@ +from django.template import Context, Library, loader + +register = Library() + + +@register.simple_tag +def include_widget(widget) -> dict: + """ Render a template with context from a defined widget """ + + template = loader.get_template(widget.get_template()) + context = Context(widget.get_context()) + + return template.render(context) -- GitLab