From 5363f4206e2f357dc02252e9aca59f87eca0e65d Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 12 Aug 2019 12:19:02 +0200 Subject: [PATCH] Lazy-load dashboard widgets --- .../control/templates/pretixcontrol/base.html | 1 + .../templates/pretixcontrol/event/index.html | 20 ++- src/pretix/control/urls.py | 1 + src/pretix/control/views/dashboards.py | 161 +++++++++++------- .../static/pretixcontrol/js/ui/dashboard.js | 13 ++ .../static/pretixcontrol/scss/_dashboard.scss | 10 ++ 6 files changed, 139 insertions(+), 67 deletions(-) create mode 100644 src/pretix/static/pretixcontrol/js/ui/dashboard.js diff --git a/src/pretix/control/templates/pretixcontrol/base.html b/src/pretix/control/templates/pretixcontrol/base.html index ff9bf22771..774c00862a 100644 --- a/src/pretix/control/templates/pretixcontrol/base.html +++ b/src/pretix/control/templates/pretixcontrol/base.html @@ -47,6 +47,7 @@ + diff --git a/src/pretix/control/templates/pretixcontrol/event/index.html b/src/pretix/control/templates/pretixcontrol/event/index.html index bb84603c22..a9101b066d 100644 --- a/src/pretix/control/templates/pretixcontrol/event/index.html +++ b/src/pretix/control/templates/pretixcontrol/event/index.html @@ -95,18 +95,30 @@ {% endif %}
{% for w in widgets %} -
+
{% if w.url %}{# backwards compatibility #} - {{ w.content|safe }} + {% if w.lazy %} + + {% else %} + {{ w.content|safe }} + {% endif %} {% elif w.link %} - {{ w.content|safe }} + {% if w.lazy %} + + {% else %} + {{ w.content|safe }} + {% endif %} {% else %}
- {{ w.content|safe }} + {% if w.lazy %} + + {% else %} + {{ w.content|safe }} + {% endif %}
{% endif %}
diff --git a/src/pretix/control/urls.py b/src/pretix/control/urls.py index fed78398f9..10b3c4981d 100644 --- a/src/pretix/control/urls.py +++ b/src/pretix/control/urls.py @@ -106,6 +106,7 @@ urlpatterns = [ url(r'^search/orders/$', search.OrderSearch.as_view(), name='search.orders'), url(r'^event/(?P[^/]+)/(?P[^/]+)/', include([ url(r'^$', dashboards.event_index, name='event.index'), + url(r'^widgets.json$', dashboards.event_index_widgets_lazy, name='event.index.widgets'), url(r'^live/$', event.EventLive.as_view(), name='event.live'), url(r'^logs/$', event.EventLog.as_view(), name='event.log'), url(r'^delete/$', event.EventDelete.as_view(), name='event.delete'), diff --git a/src/pretix/control/views/dashboards.py b/src/pretix/control/views/dashboards.py index d1a19ac34c..079c8b1312 100644 --- a/src/pretix/control/views/dashboards.py +++ b/src/pretix/control/views/dashboards.py @@ -8,6 +8,7 @@ from django.db.models import ( ) from django.db.models.functions import Coalesce, Greatest from django.dispatch import receiver +from django.http import JsonResponse from django.shortcuts import render from django.template.loader import get_template from django.urls import reverse @@ -36,44 +37,46 @@ NUM_WIDGET = '
{num}