From a3397070093fe3f39f8f625f29047a20993bd7c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Or=C5=82owski?= Date: Thu, 4 May 2017 13:39:08 +0200 Subject: [PATCH] Dynamic grapelli dashboard size based on columns from Dashboard class default:2 --- .../grappelli/dashboard/dashboard.html | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/grappelli/dashboard/templates/grappelli/dashboard/dashboard.html b/grappelli/dashboard/templates/grappelli/dashboard/dashboard.html index d6c3a909f..ff70c2280 100644 --- a/grappelli/dashboard/templates/grappelli/dashboard/dashboard.html +++ b/grappelli/dashboard/templates/grappelli/dashboard/dashboard.html @@ -1,27 +1,32 @@ {% load i18n grp_dashboard_tags %} {{ dashboard.media }} - +{% comment %} + Tested on Django1.8 and branch 2.7.4 + dashboard.parentloop.counter returns counter of inner loop if inner loop exists + instead of correct number else works + use 23 as size instead of 24 as its rounded better for 4 columns + widthratio used for multiplication and division. +{% endcomment %}
-
- {% for module in dashboard.children %} - {% if module.column == 1 %} - {% grp_render_dashboard_module module forloop.counter %} - {% endif %} - {% endfor %} -
-
- {% for module in dashboard.children %} - {% if module.column == 2 %} - {% grp_render_dashboard_module module forloop.counter %} - {% endif %} - {% endfor %} -
-
- {% for module in dashboard.children %} - {% if module.column == 3 %} - {% grp_render_dashboard_module module forloop.counter %} - {% endif %} + {% with ''|ljust:dashboard.columns as range %} + {% with '0' as outer_counter %} + {% for _ in range %} + {% with outer_counter|add:'1' as outer_counter %} +
+ {% for module in dashboard.children %} + {% if module.column == outer_counter %} + {% grp_render_dashboard_module module forloop.counter %} + {% endif %} + {% endfor %} + +
+ {% endwith %} {% endfor %} -
+ {% endwith %} + {% endwith %}