From 7bbabe41a6969cc0a1bc27495644f1227f3cafac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Schl=C3=B6gl?= Date: Fri, 10 Nov 2023 08:43:47 +0100 Subject: [PATCH] fix: fixes a bug where time contraints were not applied fixes #171 --- paas_theme/forms.py | 2 +- paas_theme/models.py | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/paas_theme/forms.py b/paas_theme/forms.py index a8edfff..54f37ef 100644 --- a/paas_theme/forms.py +++ b/paas_theme/forms.py @@ -453,7 +453,7 @@ def search(self): if ( self.cleaned_data["mtgld_mitgliedschaft"] or self.cleaned_data["mtgld_klasse"] - ) and not self.cleaned_data["start_date_form"]: + ) and not (self.cleaned_data["start_date_form"] or self.cleaned_data["end_date_form"]): mtgld_dic = SQ() for mitgliedschaft in self.cleaned_data["mtgld_mitgliedschaft"]: mtgld_dic.add( diff --git a/paas_theme/models.py b/paas_theme/models.py index 6adbcff..76db9aa 100644 --- a/paas_theme/models.py +++ b/paas_theme/models.py @@ -354,17 +354,21 @@ def get_memberships( ) ) - if start and end and start > end: - raise ValueError( - f"End date needs to be before start date: {start} > {end}" - ) + if start and end: + if convert_date(start, boundary="start") > convert_date(end, boundary="end"): + raise ValueError( + f"End date needs to be before start date: {start} > {end}" + ) - if start: + if start and not end: - q_obj &= models.Q(end_date__isnull=True) | models.Q( + q_obj &= models.q(models.Q(end_date__isnull=True) | models.Q( + end_date__gte=convert_date(start, boundary="start")) + ) + elif start: + q_obj &= models.Q( end_date__gte=convert_date(start, boundary="start") ) - if start and start_exclusive: q_obj &= models.Q(start_date__gte=convert_date(start, boundary="start")) @@ -372,7 +376,7 @@ def get_memberships( q_obj &= models.Q(start_date__lte=convert_date(end, boundary="end")) if end and end_exclusive: - q_obj = models.Q(end_date__lte=convert_date(end, boundary="end")) + q_obj &= models.Q(end_date__lte=convert_date(end, boundary="end")) return self.filter(q_obj)