Skip to content

Commit

Permalink
Add and apply custom ViewSet classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Walz authored and Jon Walz committed Feb 13, 2024
1 parent e3eddfe commit fb7c73b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 12 deletions.
3 changes: 2 additions & 1 deletion addon_service/authorized_storage_account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from .models import AuthorizedStorageAccount
from .serializers import AuthorizedStorageAccountSerializer

from addon_service.common.viewsets import RetrieveWriteViewSet

class AuthorizedStorageAccountViewSet(ModelViewSet):
class AuthorizedStorageAccountViewSet(RetrieveWriteViewSet):
queryset = AuthorizedStorageAccount.objects.all()
serializer_class = AuthorizedStorageAccountSerializer
21 changes: 21 additions & 0 deletions addon_service/common/viewsets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from rest_framework.viewsets import GenericViewSet
from rest_framework import mixins as drf_mixins
from rest_framework_json_api.views import AutoPrefetchMixin, PreloadIncludesMixin, RelatedMixin


class _DrfJsonApiHelpers(AutoPrefetchMixin, PreloadIncludesMixin, RelatedMixin):
pass

class RetrieveOnlyViewSet(_DrfJsonApiHelpers, drf_mixins.RetrieveModelMixin, GenericViewSet):
http_method_names = ["get", "head", "options"]


class RetrieveWriteViewSet(
_DrfJsonApiHelpers,
drf_mixins.CreateModelMixin,
drf_mixins.RetrieveModelMixin,
drf_mixins.UpdateModelMixin,
drf_mixins.DestroyModelMixin,
GenericViewSet
):
http_method_names = ["get", "post", "patch", "delete", "head", "options"]
5 changes: 2 additions & 3 deletions addon_service/configured_storage_addon/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from rest_framework_json_api.views import ModelViewSet

from .models import ConfiguredStorageAddon
from .serializers import ConfiguredStorageAddonSerializer

from addon_service.common.viewsets import RetrieveWriteViewSet

class ConfiguredStorageAddonViewSet(ModelViewSet):
class ConfiguredStorageAddonViewSet(RetrieveWriteViewSet):
queryset = ConfiguredStorageAddon.objects.all()
serializer_class = ConfiguredStorageAddonSerializer
4 changes: 2 additions & 2 deletions addon_service/external_storage_service/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from rest_framework_json_api.views import ModelViewSet
from rest_framework_json_api.views import ReadOnlyViewSet

from .models import ExternalStorageService
from .serializers import ExternalStorageServiceSerializer


class ExternalStorageServiceViewSet(ModelViewSet):
class ExternalStorageServiceViewSet(ReadOnlyViewSet):
queryset = ExternalStorageService.objects.all()
serializer_class = ExternalStorageServiceSerializer
# TODO: permissions_classes
6 changes: 3 additions & 3 deletions addon_service/resource_reference/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from rest_framework_json_api.views import ReadOnlyModelViewSet

from .models import ResourceReference
from .serializers import ResourceReferenceSerializer

from addon_service.common.viewsets import RetrieveOnlyViewSet

class ResourceReferenceViewSet(ReadOnlyModelViewSet):
class ResourceReferenceViewSet(RetrieveOnlyViewSet):
queryset = ResourceReference.objects.all()
serializer_class = ResourceReferenceSerializer
# TODO: permissions_classes

5 changes: 2 additions & 3 deletions addon_service/user_reference/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from rest_framework_json_api.views import ReadOnlyModelViewSet

from .models import UserReference
from .serializers import UserReferenceSerializer

from addon_service.common.viewsets import RetrieveOnlyViewSet

class UserReferenceViewSet(ReadOnlyModelViewSet):
class UserReferenceViewSet(RetrieveOnlyViewSet):
queryset = UserReference.objects.all()
serializer_class = UserReferenceSerializer
# TODO: permissions_classes

0 comments on commit fb7c73b

Please sign in to comment.