Skip to content

Commit

Permalink
added filter by allergies and participants with allergy count to event.
Browse files Browse the repository at this point in the history
  • Loading branch information
yazanzarka1 committed Oct 7, 2024
1 parent 1ed7770 commit 149e29d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 91 deletions.
2 changes: 1 addition & 1 deletion app/content/filters/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ def filter_year(self, queryset, name, value):
def filter_has_allergy(self, queryset, name, value):
if value:
return queryset.exclude(user__allergy__isnull=True).exclude(user__allergy__exact='')
return queryset
return queryset.filter(user__allergy__isnull=True) | queryset.filter(user__allergy__exact='')
94 changes: 4 additions & 90 deletions app/content/serializers/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class EventStatisticsSerializer(BaseModelSerializer):
has_attended_count = serializers.SerializerMethodField()
studyyears = serializers.SerializerMethodField()
studies = serializers.SerializerMethodField()
has_allergy_count = serializers.SerializerMethodField()

class Meta:
model = Event
Expand All @@ -272,57 +273,14 @@ class Meta:
"waiting_list_count",
"studyyears",
"studies",
"has_allergy_count",
)

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

def get_studyyears(self, obj, *args, **kwargs):
return filter(
lambda studyyear: studyyear["amount"] > 0,
map(
lambda group: {
"studyyear": group.name,
"amount": obj.registrations.filter(
user__memberships__group=group, is_on_wait=False
).count(),
},
Group.objects.filter(type=GroupType.STUDYYEAR),
),
)

def get_studies(self, obj, *args, **kwargs):
return filter(
lambda study: study["amount"] > 0,
map(
lambda group: {
"study": group.name,
"amount": obj.registrations.filter(
user__memberships__group=group, is_on_wait=False
).count(),
},
Group.objects.filter(type=GroupType.STUDY),
),
)


class EventCategoriesSerializer(BaseModelSerializer):
has_attended_count = serializers.SerializerMethodField()
studyyears = serializers.SerializerMethodField()
studies = serializers.SerializerMethodField()

class Meta:
model = Event
fields = (
"has_attended_count",
"list_count",
"waiting_list_count",
"studyyears",
"studies",
)

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()

def get_studyyears(self, obj, *args, **kwargs):
return filter(
Expand Down Expand Up @@ -352,47 +310,3 @@ def get_studies(self, obj, *args, **kwargs):
),
)

class EventRegistrationSerializer(BaseModelSerializer):
has_attended_count = serializers.SerializerMethodField()
studyyears = serializers.SerializerMethodField()
studies = serializers.SerializerMethodField()

class Meta:
model = Event
fields = (
"list_count",
"waiting_list_count",
"studyyears",
"studies",
)

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

def get_studyyears(self, obj, *args, **kwargs):
return filter(
lambda studyyear: studyyear["amount"] > 0,
map(
lambda group: {
"studyyear": group.name,
"amount": obj.registrations.filter(
user__memberships__group=group, is_on_wait=False
).count(),
},
Group.objects.filter(type=GroupType.STUDYYEAR),
),
)

def get_studies(self, obj, *args, **kwargs):
return filter(
lambda study: study["amount"] > 0,
map(
lambda group: {
"study": group.name,
"amount": obj.registrations.filter(
user__memberships__group=group, is_on_wait=False
).count(),
},
Group.objects.filter(type=GroupType.STUDY),
),
)

0 comments on commit 149e29d

Please sign in to comment.