Skip to content

Commit

Permalink
Lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yazanzarka1 committed Oct 7, 2024
1 parent 149e29d commit 858da7c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
19 changes: 12 additions & 7 deletions app/content/filters/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,30 @@ class RegistrationFilter(FilterSet):
)

has_allergy = filters.BooleanFilter(
field_name="user__allergy",
method='filter_has_allergy'
field_name="user__allergy", method="filter_has_allergy"
)


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

def filter_study(self, queryset, name, value):
return queryset.filter(
user__memberships__group__name__icontains=value,
user__memberships__group__type=GroupType.STUDY,
)

def filter_year(self, queryset, name, value):
return queryset.filter(user__memberships__group__name__icontains=value, user__memberships__group__type=GroupType.STUDYYEAR)
return queryset.filter(
user__memberships__group__name__icontains=value,
user__memberships__group__type=GroupType.STUDYYEAR,
)

def filter_has_allergy(self, queryset, name, value):
if value:
return queryset.exclude(user__allergy__isnull=True).exclude(user__allergy__exact='')
return queryset.filter(user__allergy__isnull=True) | queryset.filter(user__allergy__exact='')
return queryset.exclude(user__allergy__isnull=True).exclude(
user__allergy__exact=""
)
return queryset.filter(user__allergy__isnull=True) | queryset.filter(
user__allergy__exact=""
)
9 changes: 6 additions & 3 deletions app/content/serializers/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,13 @@ class Meta:

def get_has_attended_count(self, obj, *args, **kwargs):
return obj.registrations.filter(is_on_wait=False, has_attended=True).count()

def get_has_allergy_count(self, obj, *args, **kwargs):
return obj.registrations.exclude(user__allergy__isnull=True).exclude(user__allergy__exact='').count()
return (
obj.registrations.exclude(user__allergy__isnull=True)
.exclude(user__allergy__exact="")
.count()
)

def get_studyyears(self, obj, *args, **kwargs):
return filter(
Expand Down Expand Up @@ -309,4 +313,3 @@ def get_studies(self, obj, *args, **kwargs):
Group.objects.filter(type=GroupType.STUDY),
),
)

0 comments on commit 858da7c

Please sign in to comment.