Skip to content

Commit

Permalink
Added filter for expired and upcoming events
Browse files Browse the repository at this point in the history
  • Loading branch information
Ester2109 committed Oct 9, 2023
1 parent 99c9cd0 commit aaaefd3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/content/filters/registration.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from django_filters.rest_framework import FilterSet

from django_filters import filters
from app.content.models.registration import Registration


class RegistrationFilter(FilterSet):
event_has_ended = filters.BooleanFilter(method="filter_event_has_ended")

class Meta:
model = Registration
fields = ["has_attended", "is_on_wait"]

def filter_event_has_ended(self, queryset, name, value):
return queryset.filter(
event_has_ended=value
)
4 changes: 4 additions & 0 deletions app/content/models/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ def check_registration_has_started(self):
def check_registration_has_ended(self):
if self.event.end_registration_at < now():
raise ValidationError("Påmeldingsfristen har passert")

@property
def event_has_ended(self):
return self.event.event_has_ended

def get_submissions(self, type=None):
from app.forms.models import EventForm, Submission
Expand Down

0 comments on commit aaaefd3

Please sign in to comment.