From cb057e7ee7f4b0e3c1ffce607d0a3b7a1c5251e9 Mon Sep 17 00:00:00 2001 From: Stefan Wehrmeyer Date: Wed, 23 Nov 2022 13:23:18 +0100 Subject: [PATCH] Add time progress template --- froide_govplan/models.py | 27 +++++++++++++++++++ .../froide_govplan/plugins/progress_row.html | 18 +++++++++++++ .../froide_govplan/plugins/time_used.html | 15 +++++++++++ 3 files changed, 60 insertions(+) create mode 100644 froide_govplan/templates/froide_govplan/plugins/progress_row.html create mode 100644 froide_govplan/templates/froide_govplan/plugins/time_used.html diff --git a/froide_govplan/models.py b/froide_govplan/models.py index 095b7b2..29b0611 100644 --- a/froide_govplan/models.py +++ b/froide_govplan/models.py @@ -80,6 +80,31 @@ class Government(models.Model): def __str__(self): return self.name + @property + def days_available(self): + if self.start_date is None: + return 0 + if self.end_date is None: + return 0 + return (self.end_date - self.start_date).days + + @property + def days_left(self): + if not self.end_date: + return 0 + now = timezone.now().date() + if now > self.end_date: + return 0 + return (self.end_date - now).days + + def days_used_percentage(self) -> int: + total_days = self.days_available + if not total_days: + return 0 + now = timezone.now().date() + days_used = (now - self.start_date).days + return int(days_used / total_days * 100) + class CategorizedGovernmentPlan(TaggedItemBase): tag = models.ForeignKey( @@ -442,6 +467,8 @@ if CMSPlugin: PLUGIN_TEMPLATES = [ ("froide_govplan/plugins/default.html", _("Normal")), ("froide_govplan/plugins/progress.html", _("Progress")), + ("froide_govplan/plugins/progress_row.html", _("Progress Row")), + ("froide_govplan/plugins/time_used.html", _("Time used")), ("froide_govplan/plugins/card_cols.html", _("Card columns")), ("froide_govplan/plugins/search.html", _("Search")), ] diff --git a/froide_govplan/templates/froide_govplan/plugins/progress_row.html b/froide_govplan/templates/froide_govplan/plugins/progress_row.html new file mode 100644 index 0000000..52210ac --- /dev/null +++ b/froide_govplan/templates/froide_govplan/plugins/progress_row.html @@ -0,0 +1,18 @@ +{% load govplan %} + +{% get_plan_progress object_list as progress %} + +
+
+ {{ progress.count }} Vorhaben +
+
+
+ {% for section in progress.sections %} +
+
+ {% endfor %} +
+
+
+ diff --git a/froide_govplan/templates/froide_govplan/plugins/time_used.html b/froide_govplan/templates/froide_govplan/plugins/time_used.html new file mode 100644 index 0000000..1e8ef3f --- /dev/null +++ b/froide_govplan/templates/froide_govplan/plugins/time_used.html @@ -0,0 +1,15 @@ +{% load govplan %} + +
+ {% with gov=instance.government %} +
+ {{ gov.days_left }} Tage übrig +
+
+
+
+
+
+
+ {% endwith %} +