Commit 1a9a8829 by Chif Gergő

Template list now uses new serializer

parent a63c5cd1
Pipeline #1045 failed with stage
in 2 minutes 23 seconds
from rest_framework import serializers from rest_framework import serializers
from template.models import ImageTemplate from template.models import ImageTemplate
from instance.serializers import FlavorSerializer, LeaseSerializer
class ImageTemplateListItemSerializer(serializers.ModelSerializer):
flavor = FlavorSerializer(read_only=True)
lease = LeaseSerializer(read_only=True)
class Meta:
model = ImageTemplate
fields = ["id", "name", "distro", "flavor", "lease", "system_type"]
read_only_fields = ("id", "name", "distro", "flavor", "lease", "system_type")
class InstanceFromTemplateSerializer(serializers.Serializer): class InstanceFromTemplateSerializer(serializers.Serializer):
......
...@@ -3,6 +3,6 @@ from rest_framework import routers ...@@ -3,6 +3,6 @@ from rest_framework import routers
from template import views from template import views
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register(r"templates/image-templates", views.ImageTemplateViewSet, basename="image-template") router.register(r"templates", views.ImageTemplateViewSet, basename="image-template")
urlpatterns = router.urls urlpatterns = router.urls
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet from rest_framework.viewsets import ModelViewSet
from template.serializers import ImageTemplateModelSerializer from template.serializers import ImageTemplateModelSerializer, ImageTemplateListItemSerializer
from template.models import ImageTemplate from template.models import ImageTemplate
...@@ -31,7 +31,7 @@ class ImageTemplateViewSet(ModelViewSet): ...@@ -31,7 +31,7 @@ class ImageTemplateViewSet(ModelViewSet):
def update(self, request, *args, **kwargs): def update(self, request, *args, **kwargs):
# only the name, description, lease, flavor can be updated # only the name, description, lease, flavor can be updated
allowed_keys = ["name", "description", "lease", "flavor"] allowed_keys = ["name", "description", "access_prtotocol", "distro", "lease", "flavor"]
# delete not allowed key # delete not allowed key
for key in request.data.keys(): for key in request.data.keys():
...@@ -39,3 +39,9 @@ class ImageTemplateViewSet(ModelViewSet): ...@@ -39,3 +39,9 @@ class ImageTemplateViewSet(ModelViewSet):
request.data.pop(key, None) request.data.pop(key, None)
return super(ImageTemplateViewSet, self).update(request, partial=True) return super(ImageTemplateViewSet, self).update(request, partial=True)
def list(self, request, *args, **kwargs):
# TODO: Filter for owned and shared tempaltes
query = ImageTemplate.objects.all()
serializer = ImageTemplateListItemSerializer(query, many=True)
return Response(serializer.data)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment