Refactor user uploads template to enhance selection functionality and update count display

This commit is contained in:
Ross
2026-03-02 11:32:19 +00:00
parent a5a4084994
commit 7cac5aa60f
2 changed files with 72 additions and 18 deletions
+10 -5
View File
@@ -450,7 +450,7 @@ class NormalCaseFilter(django_filters.FilterSet):
("months", "Months"),
("years", "Years"),
)
age_unit = django_filters.ChoiceFilter(label="Unit", choices=AGE_UNIT_CHOICES)
age_unit = django_filters.ChoiceFilter(label="Unit", choices=AGE_UNIT_CHOICES, method="filter_age_unit")
class Meta:
model = NormalCase
@@ -554,9 +554,9 @@ class NormalCaseFilter(django_filters.FilterSet):
def filter_min_value(self, queryset, name, value):
try:
unit = getattr(self.form, "cleaned_data", {}).get("age_unit", "years")
unit = getattr(self.form, "cleaned_data", {}).get("age_unit", "days")
except Exception:
unit = "years"
unit = "days"
try:
days = self._convert_to_days(value, unit)
except Exception:
@@ -565,15 +565,20 @@ class NormalCaseFilter(django_filters.FilterSet):
def filter_max_value(self, queryset, name, value):
try:
unit = getattr(self.form, "cleaned_data", {}).get("age_unit", "years")
unit = getattr(self.form, "cleaned_data", {}).get("age_unit", "days")
except Exception:
unit = "years"
unit = "days"
try:
days = self._convert_to_days(value, unit)
except Exception:
return queryset
return queryset.filter(age_days__lte=days)
def filter_age_unit(self, queryset, name, value):
# `age_unit` is a helper input used by min/max conversion and does not
# map to a database field on NormalCase.
return queryset
class ResourceFilter(django_filters.FilterSet):
name = django_filters.CharFilter(field_name='name', lookup_expr='icontains')