1
Fork 0
mirror of https://github.com/Steffo99/sophon.git synced 2024-12-22 06:44:21 +00:00

🔧 Order and "distinct" all querysets

This commit is contained in:
Steffo 2021-10-20 22:13:32 +02:00
parent d1977fa6c5
commit fae22ac62c
3 changed files with 10 additions and 10 deletions

View file

@ -175,7 +175,7 @@ class UserViewSet(ReadSophonViewSet):
A viewset to list registered users.
"""
def get_queryset(self):
return User.objects.all()
return User.objects.order_by("username").all()
def get_serializer_class(self):
return serializers.UserSerializer
@ -199,7 +199,7 @@ class ResearchGroupViewSet(WriteSophonViewSet):
def get_queryset(self):
# All research groups are public, so it's fine to do this
return models.ResearchGroup.objects.all()
return models.ResearchGroup.objects.order_by("slug").all()
def hook_create(self, serializer) -> dict[str, t.Any]:
# Add the owner field to the serializer

View file

@ -97,7 +97,7 @@ class NotebooksByProjectViewSet(NotebooksViewSet):
return Notebook.objects.filter(
Q(project__slug=self.kwargs["project_slug"]) &
Q(project__visibility="PUBLIC")
)
).distinct().order_by("slug").all()
else:
return Notebook.objects.filter(
Q(project__slug=self.kwargs["project_slug"]) & (
@ -106,7 +106,7 @@ class NotebooksByProjectViewSet(NotebooksViewSet):
Q(project__visibility="PRIVATE", project__group__members__in=[self.request.user]) |
Q(project__visibility="PRIVATE", project__group__owner=self.request.user)
)
)
).distinct().order_by("slug").all()
def get_serializer_class(self):
# Get the base serializer
@ -145,11 +145,11 @@ class NotebooksBySlugViewSet(NotebooksViewSet):
if self.request.user.is_anonymous:
return Notebook.objects.filter(
Q(project__visibility="PUBLIC")
)
).distinct().order_by("slug").all()
else:
return Notebook.objects.filter(
Q(project__visibility="PUBLIC") |
Q(project__visibility="INTERNAL") |
Q(project__visibility="PRIVATE", project__group__members__in=[self.request.user]) |
Q(project__visibility="PRIVATE", project__group__owner=self.request.user)
)
).distinct().order_by("slug").all()

View file

@ -18,7 +18,7 @@ class ResearchProjectsByGroupViewSet(ResearchProjectViewSet):
return models.ResearchProject.objects.filter(
Q(group__slug=self.kwargs["group_slug"]) &
Q(visibility="PUBLIC")
)
).distinct().order_by("slug").all()
else:
return models.ResearchProject.objects.filter(
Q(group__slug=self.kwargs["group_slug"]) & (
@ -27,7 +27,7 @@ class ResearchProjectsByGroupViewSet(ResearchProjectViewSet):
Q(visibility="PRIVATE", group__members__in=[self.request.user]) |
Q(visibility="PRIVATE", group__owner=self.request.user)
)
)
).distinct().order_by("slug").all()
class ResearchProjectsBySlugViewSet(ResearchProjectViewSet):
@ -35,11 +35,11 @@ class ResearchProjectsBySlugViewSet(ResearchProjectViewSet):
if self.request.user.is_anonymous:
return models.ResearchProject.objects.filter(
Q(visibility="PUBLIC")
)
).distinct().order_by("slug").all()
else:
return models.ResearchProject.objects.filter(
Q(visibility="PUBLIC") |
Q(visibility="INTERNAL") |
Q(visibility="PRIVATE", group__members__in=[self.request.user]) |
Q(visibility="PRIVATE", group__owner=self.request.user)
)
).distinct().order_by("slug").all()