Skip to content

Commit

Permalink
Merge pull request #3699 from webkom/event-serializers-and-views-impr…
Browse files Browse the repository at this point in the history
…ovements
  • Loading branch information
ivarnakken authored Dec 17, 2024
2 parents 4f06f52 + 74b926b commit b8247bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
14 changes: 1 addition & 13 deletions lego/apps/events/serializers/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,8 @@ class Meta:
read_only = True


class EventUserRegSerializer(EventReadSerializer):
user_reg = serializers.SerializerMethodField()

class Meta:
model = Event
fields = EventReadSerializer.Meta.fields + ("user_reg",)
read_only = True

def get_user_reg(self, event):
return RegistrationReadSerializer(event.user_reg[0]).data


class EventReadUserDetailedSerializer(EventReadDetailedSerializer):
"""User specfic event serializer that appends data based on request.user"""
"""User specific event serializer that appends data based on request.user"""

activation_time = ActivationTimeField()
is_admitted = IsAdmittedField()
Expand Down
14 changes: 8 additions & 6 deletions lego/apps/events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
EventReadAuthUserDetailedSerializer,
EventReadSerializer,
EventReadUserDetailedSerializer,
EventUserRegSerializer,
ImageGallerySerializer,
populate_event_registration_users_with_grade,
)
Expand Down Expand Up @@ -137,7 +136,7 @@ def get_queryset(self):
elif self.action == "retrieve":
queryset = Event.objects.select_related(
"company", "responsible_group"
).prefetch_related("pools", "pools__permission_groups", "tags")
).prefetch_related("pools", "pools__permission_groups", "tags", "survey")
if user and user.is_authenticated:
reg_queryset = self.get_registrations(user)
queryset = queryset.prefetch_related(
Expand All @@ -146,13 +145,16 @@ def get_queryset(self):
Prefetch("pools__registrations", queryset=reg_queryset),
Prefetch(
"registrations",
queryset=Registration.objects.filter(pool=None)
.select_related("user")
queryset=Registration.objects.filter(user=user)
.exclude(status=constants.SUCCESS_UNREGISTER)
.select_related("user", "pool")
.prefetch_related("user__abakus_groups"),
to_attr="user_reg",
),
)
else:
queryset = Event.objects.all()

return queryset

def get_registrations(self, user):
Expand Down Expand Up @@ -319,7 +321,7 @@ def payment(self, request, *args, **kwargs):

@decorators.action(
detail=False,
serializer_class=EventUserRegSerializer,
serializer_class=EventReadSerializer,
permission_classes=[permissions.IsAuthenticated],
)
def previous(self, request):
Expand All @@ -333,7 +335,7 @@ def previous(self, request):

@decorators.action(
detail=False,
serializer_class=EventUserRegSerializer,
serializer_class=EventReadSerializer,
permission_classes=[permissions.IsAuthenticated],
)
def upcoming(self, request):
Expand Down

0 comments on commit b8247bb

Please sign in to comment.