From bdf8f04210aaa695016ffdef4d5cbf03d58f9030 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Sat, 11 Feb 2023 18:07:05 +0000 Subject: [PATCH] Re-add property fields --- core/models.py | 18 +++++++++++++++++- core/templates/partials/assetgroup-list.html | 6 +++++- core/views/assets.py | 3 +++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/core/models.py b/core/models.py index 06103a1..dbff30f 100644 --- a/core/models.py +++ b/core/models.py @@ -418,7 +418,23 @@ class AssetGroup(models.Model): allowed = models.JSONField(null=True, blank=True, default=dict) def __str__(self): - return f"{self.name}" + return f"{self.name} ({self.restrictions})" + + @property + def matches(self): + """ + Get the total number of matches for this group. + """ + if isinstance(self.allowed, dict): + truthy_values = [x for x in self.allowed.values() if x is True] + return f"{len(truthy_values)}/{len(self.allowed)}" + + @property + def restrictions(self): + """ + Get the total number of restrictions for this group. + """ + return self.assetrestriction_set.count() class AssetRestriction(models.Model): diff --git a/core/templates/partials/assetgroup-list.html b/core/templates/partials/assetgroup-list.html index e60eaf0..f037eae 100644 --- a/core/templates/partials/assetgroup-list.html +++ b/core/templates/partials/assetgroup-list.html @@ -1,6 +1,6 @@ {% load cache %} {% load cachalot cache %} -{% get_last_invalidation 'core.AssetGroup' as last %} +{% get_last_invalidation 'core.AssetGroup' 'core.AssetRestriction' as last %} {% include 'mixins/partials/notify.html' %} {% cache 600 objects_assetgroups request.user.id object_list last %} name + + {% for item in object_list %} @@ -25,6 +27,8 @@ + +
description accountstatusrestrictions actions {{ item.name }} {{ item.description }} {{ item.account }}{{ item.matches }}{{ item.restrictions }}