From e3a57e859bca11f80ee4469399273d93f183cc56 Mon Sep 17 00:00:00 2001 From: Frank Sauerburger <frank@sauerburger.com> Date: Fri, 27 Nov 2020 18:43:01 +0100 Subject: [PATCH] Remove special writable serializer --- uhepp_org/uhepp_api/views.py | 24 ++++--------------- uhepp_org/uhepp_vault/models.py | 4 ++-- .../templates/uhepp_vault/home.html | 1 - uhepp_org/uhepp_vault/urls.py | 2 +- 4 files changed, 7 insertions(+), 24 deletions(-) diff --git a/uhepp_org/uhepp_api/views.py b/uhepp_org/uhepp_api/views.py index ebe07dc..fd2737e 100644 --- a/uhepp_org/uhepp_api/views.py +++ b/uhepp_org/uhepp_api/views.py @@ -41,7 +41,7 @@ class UserViewSet(MaskedRelatedMixin, viewsets.ReadOnlyModelViewSet): location = {'Location': api_url} return { - "Link": f'{ui_url}; rel="ui"', + "Link": f'<{ui_url}>; rel="ui"', **location } @@ -81,7 +81,7 @@ class CollectionViewSet(viewsets.ModelViewSet): location = {"Location": api_url} return { - "Link": f'{ui_url}; rel="ui"', + "Link": f'<{ui_url}>; rel="ui"', **location } @@ -128,7 +128,7 @@ class PlotViewSet(viewsets.ModelViewSet): permission_classes = [IsCollectionOwnerOrReadOnly] def create(self, request, *args, **kwds): - serializer = self.get_serializer_visible(data=request.data) + serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) prototype = Namespace(**serializer.validated_data) @@ -151,7 +151,7 @@ class PlotViewSet(viewsets.ModelViewSet): location = {"Location": api_url} return { - "Link": f'{ui_url}; rel="ui"', + "Link": f'<{ui_url}>; rel="ui"', "X-Resource-UUID": uuid, **location } @@ -165,22 +165,6 @@ class PlotViewSet(viewsets.ModelViewSet): def get_serializer(self, *args, **kwds): serializer = super().get_serializer(*args, **kwds) - # Filter queryset for browsable API choices - patching = serializer - if hasattr(patching, "child"): - patching = patching.child - - queryset = patching.fields["collection"].queryset - if self.request.user.is_authenticated: - patching.fields["collection"].queryset = queryset.filter(owner=self.request.user) - else: - patching.fields["collection"].queryset = queryset.none() - - return serializer - - def get_serializer_visible(self, *args, **kwds): - serializer = super().get_serializer(*args, **kwds) - # Filter queryset for browsable API choices patching = serializer if hasattr(patching, "child"): diff --git a/uhepp_org/uhepp_vault/models.py b/uhepp_org/uhepp_vault/models.py index 720d385..546a18f 100644 --- a/uhepp_org/uhepp_vault/models.py +++ b/uhepp_org/uhepp_vault/models.py @@ -12,9 +12,9 @@ PRIVATE_LEVEL = 10 INTERNAL_LEVEL = 20 PUBLIC_LEVEL = 30 VISIBILITY_LEVELS = [ - (PUBLIC_LEVEL, _("Publicly accessible")), + (PRIVATE_LEVEL, _("Accessible only by you")), (INTERNAL_LEVEL, _("Accessible only by members of your collaboration")), - (PRIVATE_LEVEL, _("Accessible only by you")) + (PUBLIC_LEVEL, _("Publicly accessible")), ] class Collection(models.Model): diff --git a/uhepp_org/uhepp_vault/templates/uhepp_vault/home.html b/uhepp_org/uhepp_vault/templates/uhepp_vault/home.html index cbbb003..20fe0df 100644 --- a/uhepp_org/uhepp_vault/templates/uhepp_vault/home.html +++ b/uhepp_org/uhepp_vault/templates/uhepp_vault/home.html @@ -1,2 +1 @@ <p>uhepp.org – home of {{ plot_count }} plots</p> -<a href="{% url 'uhepp_vault:plot-index' %}">Browser index</a> diff --git a/uhepp_org/uhepp_vault/urls.py b/uhepp_org/uhepp_vault/urls.py index 99205b7..982b1a4 100644 --- a/uhepp_org/uhepp_vault/urls.py +++ b/uhepp_org/uhepp_vault/urls.py @@ -5,7 +5,7 @@ from . import views app_name = 'uhepp_vault' urlpatterns = [ - # path('', views.home, name='home'), + path('', views.home, name='home'), # path('p/', views.PlotIndex.as_view(), name='plot-index'), # path('accounts/', views.account, name='account'), # path('accounts/login/', auth_views.LoginView.as_view()), -- GitLab