Skip to content
Snippets Groups Projects
Verified Commit 05377dc3 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Add template tag for better widget inclusion

parent 75a060c3
Branches 616-docs-document-dashboard-and-dashboard-widgets
No related tags found
1 merge request!142Implement core functionality for dashboard widgets
......@@ -262,6 +262,9 @@ class DashboardWidget(PolymorphicModel):
def get_context(self):
raise NotImplementedError("A widget subclass needs to implement the get_context method.")
def get_template(self):
return self.template
def __str__(self):
return self.title
......
{% 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>
......
from django.template import 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 = widget.get_context()
return template.render(context)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment