dynamicweb/hosting/mixins.py

35 lines
1.2 KiB
Python
Raw Normal View History

from django.shortcuts import redirect
from django.conf import settings
from django.core.urlresolvers import reverse
2017-05-13 05:31:29 +00:00
from opennebula_api.serializers import VirtualMachineTemplateSerializer
from opennebula_api.models import OpenNebulaManager
from .models import HostingPlan
class ProcessVMSelectionMixin(object):
def post(self, request, *args, **kwargs):
2017-05-13 05:31:29 +00:00
template_id = int(request.POST.get('vm_template_id'))
configuration_id = int(request.POST.get('configuration'))
2017-05-13 05:31:29 +00:00
template = OpenNebulaManager().get_template(template_id)
data = VirtualMachineTemplateSerializer(template).data
configuration = HostingPlan.objects.get(id=configuration_id)
2017-05-13 05:31:29 +00:00
request.session['template'] = data
request.session['specs'] = configuration.serialize()
2017-05-13 05:31:29 +00:00
if not request.user.is_authenticated():
2016-04-30 18:55:55 +00:00
request.session['next'] = reverse('hosting:payment')
return redirect(reverse('hosting:login'))
return redirect(reverse('hosting:payment'))
class HostingContextMixin(object):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['MULTISITE_CMS_FALLBACK'] = settings.MULTISITE_CMS_FALLBACK
return context