Add progress bar for govplans
This commit is contained in:
parent
b0c8aa157f
commit
934ed192ed
4 changed files with 47 additions and 0 deletions
|
|
@ -229,6 +229,7 @@ if CMSPlugin:
|
||||||
|
|
||||||
PLUGIN_TEMPLATES = [
|
PLUGIN_TEMPLATES = [
|
||||||
("froide_govplan/plugins/default.html", _("Normal")),
|
("froide_govplan/plugins/default.html", _("Normal")),
|
||||||
|
("froide_govplan/plugins/progress.html", _("Progress")),
|
||||||
]
|
]
|
||||||
|
|
||||||
class GovernmentPlansCMSPlugin(CMSPlugin):
|
class GovernmentPlansCMSPlugin(CMSPlugin):
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
{% load govplan %}
|
||||||
|
|
||||||
|
{% get_plan_progress object_list as progress %}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div class="progress" style="height: 25px;">
|
||||||
|
{% for section in progress.sections %}
|
||||||
|
<div class="progress-bar bg-{{ section.css_class }}" role="progressbar" style="width: {{ section.css_percentage }}%;" aria-valuenow="{{ section.css_percentage }}" aria-valuemin="0" aria-valuemax="100" title="{{ section.label }}: {{ section.percentage }}%" data-toggle="tooltip" data-placement="top">
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
0
froide_govplan/templatetags/__init__.py
Normal file
0
froide_govplan/templatetags/__init__.py
Normal file
33
froide_govplan/templatetags/govplan.py
Normal file
33
froide_govplan/templatetags/govplan.py
Normal file
|
|
@ -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}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue