diff --git a/hosting/mixins.py b/hosting/mixins.py index 359b1434..c8539eee 100644 --- a/hosting/mixins.py +++ b/hosting/mixins.py @@ -1,19 +1,19 @@ from django.shortcuts import redirect from django.core.urlresolvers import reverse +from opennebula_api.serializers import VirtualMachineTemplateSerializer +from opennebula_api.models import OpenNebulaManager + class ProcessVMSelectionMixin(object): def post(self, request, *args, **kwargs): - #configuration = request.POST.get('configuration') - #configuration_display = dict(VirtualMachinePlan.VM_CONFIGURATION).get(configuration) - vm_template_id = request.POST.get('vm_template_id') - vm_specs.update({ - 'configuration_display': configuration_display, - 'configuration': configuration, - 'vm_template_id': vm_template_id - }) - request.session['vm_specs'] = vm_specs + + template_id = int(request.POST.get('vm_template_id')) + template = OpenNebulaManager().get_template(template_id) + data = VirtualMachineTemplateSerializer(template).data + request.session['template'] = data + if not request.user.is_authenticated(): request.session['next'] = reverse('hosting:payment') return redirect(reverse('hosting:login')) diff --git a/hosting/templates/hosting/includes/_pricing.html b/hosting/templates/hosting/includes/_pricing.html index 4c95a73e..c1b2fa11 100644 --- a/hosting/templates/hosting/includes/_pricing.html +++ b/hosting/templates/hosting/includes/_pricing.html @@ -24,7 +24,7 @@ {% csrf_token %} - + @@ -53,17 +53,17 @@ -
  • +
  • -

    {{vm.final_price|floatformat}}CHF

    +

    {{vm.price|floatformat}} CHF

    per month
  • diff --git a/hosting/views.py b/hosting/views.py index b292ce45..313f765b 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -42,16 +42,20 @@ class DjangoHostingView(ProcessVMSelectionMixin, View): def get_context_data(self, **kwargs): HOSTING = 'django' - configuration_detail = dict(VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING) + templates = OpenNebulaManager().get_templates() + data = VirtualMachineTemplateSerializer(templates, many=True).data + + # configuration_detail = dict(VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING) context = { 'hosting': HOSTING, 'hosting_long': "Django", - 'configuration_detail': configuration_detail, + # 'configuration_detail': configuration_detail, 'domain': "django-hosting.ch", 'google_analytics': "UA-62285904-6", + 'vm_types': data, 'email': "info@django-hosting.ch", - 'vm_types': VirtualMachineType.get_serialized_vm_types(), - 'configuration_options': dict(VirtualMachinePlan.VM_CONFIGURATION) + # 'vm_types': VirtualMachineType.get_serialized_vm_types(), + # 'configuration_options': dict(VirtualMachinePlan.VM_CONFIGURATION) } return context @@ -68,15 +72,17 @@ class RailsHostingView(ProcessVMSelectionMixin, View): def get_context_data(self, **kwargs): HOSTING = 'rails' - configuration_detail = dict(VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING) + + templates = OpenNebulaManager().get_templates() + data = VirtualMachineTemplateSerializer(templates, many=True).data + context = { 'hosting': HOSTING, - 'configuration_detail': configuration_detail, 'hosting_long': "Ruby On Rails", 'domain': "rails-hosting.ch", 'google_analytics': "UA-62285904-5", 'email': "info@rails-hosting.ch", - 'vm_types': VirtualMachineType.get_serialized_vm_types(), + 'vm_types': data, } return context @@ -91,15 +97,18 @@ class NodeJSHostingView(ProcessVMSelectionMixin, View): def get_context_data(self, **kwargs): HOSTING = 'nodejs' - configuration_detail = dict(VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING) + # configuration_detail = dict(VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING) + templates = OpenNebulaManager().get_templates() + data = VirtualMachineTemplateSerializer(templates, many=True).data + context = { - 'hosting': "nodejs", + 'hosting': HOSTING, 'hosting_long': "NodeJS", - 'configuration_detail': configuration_detail, + # 'configuration_detail': configuration_detail, 'domain': "node-hosting.ch", 'google_analytics': "UA-62285904-7", 'email': "info@node-hosting.ch", - 'vm_types': VirtualMachineType.get_serialized_vm_types(), + 'vm_types': data, } return context @@ -114,11 +123,14 @@ class HostingPricingView(ProcessVMSelectionMixin, View): template_name = "hosting/hosting_pricing.html" def get_context_data(self, **kwargs): - configuration_options = dict(VirtualMachinePlan.VM_CONFIGURATION) + # configuration_options = dict(VirtualMachinePlan.VM_CONFIGURATION) + templates = OpenNebulaManager().get_templates() + data = VirtualMachineTemplateSerializer(templates, many=True).data + context = { - 'configuration_options': configuration_options, + # 'configuration_options': configuration_options, 'email': "info@django-hosting.ch", - 'vm_types': VirtualMachineType.get_serialized_vm_types(), + 'vm_types': data, } return context @@ -134,13 +146,17 @@ class IndexView(View): template_name = "hosting/index.html" def get_context_data(self, **kwargs): + templates = OpenNebulaManager().get_templates() + data = VirtualMachineTemplateSerializer(templates, many=True).data + context = { 'hosting': "nodejs", 'hosting_long': "NodeJS", 'domain': "node-hosting.ch", 'google_analytics': "UA-62285904-7", 'email': "info@node-hosting.ch", - 'vm_types': VirtualMachineType.get_serialized_vm_types(), + 'vm_types': data + # 'vm_types': VirtualMachineType.get_serialized_vm_types(), } return context