mirror of
https://github.com/Steffo99/sophon.git
synced 2024-12-22 14:54:22 +00:00
🔧 Order and "distinct" all querysets
This commit is contained in:
parent
d1977fa6c5
commit
fae22ac62c
3 changed files with 10 additions and 10 deletions
|
@ -175,7 +175,7 @@ class UserViewSet(ReadSophonViewSet):
|
||||||
A viewset to list registered users.
|
A viewset to list registered users.
|
||||||
"""
|
"""
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return User.objects.all()
|
return User.objects.order_by("username").all()
|
||||||
|
|
||||||
def get_serializer_class(self):
|
def get_serializer_class(self):
|
||||||
return serializers.UserSerializer
|
return serializers.UserSerializer
|
||||||
|
@ -199,7 +199,7 @@ class ResearchGroupViewSet(WriteSophonViewSet):
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
# All research groups are public, so it's fine to do this
|
# 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]:
|
def hook_create(self, serializer) -> dict[str, t.Any]:
|
||||||
# Add the owner field to the serializer
|
# Add the owner field to the serializer
|
||||||
|
|
|
@ -97,7 +97,7 @@ class NotebooksByProjectViewSet(NotebooksViewSet):
|
||||||
return Notebook.objects.filter(
|
return Notebook.objects.filter(
|
||||||
Q(project__slug=self.kwargs["project_slug"]) &
|
Q(project__slug=self.kwargs["project_slug"]) &
|
||||||
Q(project__visibility="PUBLIC")
|
Q(project__visibility="PUBLIC")
|
||||||
)
|
).distinct().order_by("slug").all()
|
||||||
else:
|
else:
|
||||||
return Notebook.objects.filter(
|
return Notebook.objects.filter(
|
||||||
Q(project__slug=self.kwargs["project_slug"]) & (
|
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__members__in=[self.request.user]) |
|
||||||
Q(project__visibility="PRIVATE", project__group__owner=self.request.user)
|
Q(project__visibility="PRIVATE", project__group__owner=self.request.user)
|
||||||
)
|
)
|
||||||
)
|
).distinct().order_by("slug").all()
|
||||||
|
|
||||||
def get_serializer_class(self):
|
def get_serializer_class(self):
|
||||||
# Get the base serializer
|
# Get the base serializer
|
||||||
|
@ -145,11 +145,11 @@ class NotebooksBySlugViewSet(NotebooksViewSet):
|
||||||
if self.request.user.is_anonymous:
|
if self.request.user.is_anonymous:
|
||||||
return Notebook.objects.filter(
|
return Notebook.objects.filter(
|
||||||
Q(project__visibility="PUBLIC")
|
Q(project__visibility="PUBLIC")
|
||||||
)
|
).distinct().order_by("slug").all()
|
||||||
else:
|
else:
|
||||||
return Notebook.objects.filter(
|
return Notebook.objects.filter(
|
||||||
Q(project__visibility="PUBLIC") |
|
Q(project__visibility="PUBLIC") |
|
||||||
Q(project__visibility="INTERNAL") |
|
Q(project__visibility="INTERNAL") |
|
||||||
Q(project__visibility="PRIVATE", project__group__members__in=[self.request.user]) |
|
Q(project__visibility="PRIVATE", project__group__members__in=[self.request.user]) |
|
||||||
Q(project__visibility="PRIVATE", project__group__owner=self.request.user)
|
Q(project__visibility="PRIVATE", project__group__owner=self.request.user)
|
||||||
)
|
).distinct().order_by("slug").all()
|
||||||
|
|
|
@ -18,7 +18,7 @@ class ResearchProjectsByGroupViewSet(ResearchProjectViewSet):
|
||||||
return models.ResearchProject.objects.filter(
|
return models.ResearchProject.objects.filter(
|
||||||
Q(group__slug=self.kwargs["group_slug"]) &
|
Q(group__slug=self.kwargs["group_slug"]) &
|
||||||
Q(visibility="PUBLIC")
|
Q(visibility="PUBLIC")
|
||||||
)
|
).distinct().order_by("slug").all()
|
||||||
else:
|
else:
|
||||||
return models.ResearchProject.objects.filter(
|
return models.ResearchProject.objects.filter(
|
||||||
Q(group__slug=self.kwargs["group_slug"]) & (
|
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__members__in=[self.request.user]) |
|
||||||
Q(visibility="PRIVATE", group__owner=self.request.user)
|
Q(visibility="PRIVATE", group__owner=self.request.user)
|
||||||
)
|
)
|
||||||
)
|
).distinct().order_by("slug").all()
|
||||||
|
|
||||||
|
|
||||||
class ResearchProjectsBySlugViewSet(ResearchProjectViewSet):
|
class ResearchProjectsBySlugViewSet(ResearchProjectViewSet):
|
||||||
|
@ -35,11 +35,11 @@ class ResearchProjectsBySlugViewSet(ResearchProjectViewSet):
|
||||||
if self.request.user.is_anonymous:
|
if self.request.user.is_anonymous:
|
||||||
return models.ResearchProject.objects.filter(
|
return models.ResearchProject.objects.filter(
|
||||||
Q(visibility="PUBLIC")
|
Q(visibility="PUBLIC")
|
||||||
)
|
).distinct().order_by("slug").all()
|
||||||
else:
|
else:
|
||||||
return models.ResearchProject.objects.filter(
|
return models.ResearchProject.objects.filter(
|
||||||
Q(visibility="PUBLIC") |
|
Q(visibility="PUBLIC") |
|
||||||
Q(visibility="INTERNAL") |
|
Q(visibility="INTERNAL") |
|
||||||
Q(visibility="PRIVATE", group__members__in=[self.request.user]) |
|
Q(visibility="PRIVATE", group__members__in=[self.request.user]) |
|
||||||
Q(visibility="PRIVATE", group__owner=self.request.user)
|
Q(visibility="PRIVATE", group__owner=self.request.user)
|
||||||
)
|
).distinct().order_by("slug").all()
|
||||||
|
|
Loading…
Reference in a new issue