From fca291c6a5afbf548f520c560fb87ba8097679ff Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 27 Jul 2017 12:05:01 +0530 Subject: [PATCH] Added VMTemplateSerializer --- datacenterlight/views.py | 5 +++-- opennebula_api/serializers.py | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 401be537..017a1f3a 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -21,7 +21,7 @@ from datetime import datetime from membership.models import CustomUser, StripeCustomer from opennebula_api.models import OpenNebulaManager -from opennebula_api.serializers import VirtualMachineTemplateSerializer, VirtualMachineSerializer +from opennebula_api.serializers import VirtualMachineTemplateSerializer, VirtualMachineSerializer, VMTemplateSerializer class LandingProgramView(TemplateView): @@ -212,7 +212,8 @@ class IndexView(CreateView): storage = request.POST.get('storage') price = request.POST.get('total') template_id = int(request.POST.get('config')) - template_data = VMTemplate.objects.all() + template = VMTemplate.objects.filter(opennebula_vm_template_id=template_id).first() + template_data = VMTemplateSerializer(template).data name = request.POST.get('name') email = request.POST.get('email') diff --git a/opennebula_api/serializers.py b/opennebula_api/serializers.py index 16ab1e76..12b313af 100644 --- a/opennebula_api/serializers.py +++ b/opennebula_api/serializers.py @@ -129,6 +129,12 @@ class VirtualMachineSerializer(serializers.Serializer): return obj.name.strip('public-') +class VMTemplateSerializer(serializers.Serializer): + """Serializer to map the VMTemplate instance into JSON format.""" + id = serializers.IntegerField(read_only=True, source='opennebula_vm_template_id') + name = serializers.CharField(read_only=True) + + def hexstr2int(string): return int(string.replace(':', ''), 16)