diff --git a/froide_govplan/models.py b/froide_govplan/models.py index 2a6b78b..aa85f99 100644 --- a/froide_govplan/models.py +++ b/froide_govplan/models.py @@ -229,6 +229,7 @@ if CMSPlugin: PLUGIN_TEMPLATES = [ ("froide_govplan/plugins/default.html", _("Normal")), + ("froide_govplan/plugins/progress.html", _("Progress")), ] class GovernmentPlansCMSPlugin(CMSPlugin): diff --git a/froide_govplan/templates/froide_govplan/plugins/progress.html b/froide_govplan/templates/froide_govplan/plugins/progress.html new file mode 100644 index 0000000..c4ce7d5 --- /dev/null +++ b/froide_govplan/templates/froide_govplan/plugins/progress.html @@ -0,0 +1,13 @@ +{% load govplan %} + +{% get_plan_progress object_list as progress %} + +
+
+ {% for section in progress.sections %} +
+
+ {% endfor %} +
+
+ diff --git a/froide_govplan/templatetags/__init__.py b/froide_govplan/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/froide_govplan/templatetags/govplan.py b/froide_govplan/templatetags/govplan.py new file mode 100644 index 0000000..4f1ae87 --- /dev/null +++ b/froide_govplan/templatetags/govplan.py @@ -0,0 +1,33 @@ +from django import template + +from froide_govplan.models import PlanStatus + +register = template.Library() + +STATUS_CSS = { + PlanStatus.NOT_STARTED: "secondary", + PlanStatus.STARTED: "primary", + PlanStatus.PARTIALLY_IMPLEMENTED: "warning", + PlanStatus.IMPLEMENTED: "success", + PlanStatus.DEFERRED: "danger", +} + + +@register.simple_tag +def get_plan_progress(object_list): + sections = [] + for value, label in PlanStatus.choices: + status_count = len([x for x in object_list if x.status == value]) + percentage = status_count / len(object_list) * 100 + sections.append( + { + "count": status_count, + "label": label, + "css_class": STATUS_CSS[value], + "percentage": round(percentage), + "css_percentage": str(percentage), + } + ) + + value, label + return {"count": len(object_list), "sections": sections}