Skip to content

Commit

Permalink
fix: fixes a bug where time contraints were not applied
Browse files Browse the repository at this point in the history
fixes #171
  • Loading branch information
sennierer committed Nov 10, 2023
1 parent aebabd3 commit 7bbabe4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion paas_theme/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
20 changes: 12 additions & 8 deletions paas_theme/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,25 +354,29 @@ 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"))

if end:
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)

Expand Down

0 comments on commit 7bbabe4

Please sign in to comment.