Skip to content

Commit

Permalink
added optional username argument
Browse files Browse the repository at this point in the history
  • Loading branch information
olehkorkh-planeks committed Feb 16, 2024
1 parent 5db8c6f commit 9a3ca4d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions mcserver/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class Meta:
class SessionFilteringSerializer(serializers.Serializer):
status = serializers.CharField(max_length=64, required=True)
date_range = serializers.ListField(child=serializers.DateField(), required=False)
username = serializers.CharField(max_length=64, required=False)


class SubjectSerializer(serializers.ModelSerializer):
Expand Down
3 changes: 3 additions & 0 deletions mcserver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,9 @@ def get_session_statuses(self, request):
filter_kwargs['status_changed__lte'] = date_range[1]
if not IsAdmin().has_permission(request, self) and not IsBackend().has_permission(request, self):
filter_kwargs['user'] = request.user
else:
if 'username' in filtering_serializer.validated_data:
filter_kwargs['user__username'] = filtering_serializer.validated_data.get('username')

sessions = Session.objects.filter(**filter_kwargs)
serializer = SessionIdSerializer(sessions, many=True)
Expand Down

0 comments on commit 9a3ca4d

Please sign in to comment.