2023-12-06 11:13:47 +00:00
|
|
|
from django.shortcuts import redirect
|
2023-11-22 10:12:05 +00:00
|
|
|
from django.conf import settings
|
2023-12-06 11:13:47 +00:00
|
|
|
from django.urls import reverse
|
|
|
|
from django.utils.decorators import method_decorator
|
|
|
|
from django.views.decorators.cache import cache_control
|
2023-11-22 10:12:05 +00:00
|
|
|
|
2023-12-06 11:13:47 +00:00
|
|
|
from opennebula_api.serializers import VirtualMachineTemplateSerializer
|
|
|
|
from opennebula_api.opennebula_manager import OpenNebulaManager
|
2023-11-22 10:12:05 +00:00
|
|
|
|
2023-12-06 11:13:47 +00:00
|
|
|
from .models import HostingPlan
|
2023-11-22 10:12:05 +00:00
|
|
|
|
|
|
|
|
2023-12-06 11:13:47 +00:00
|
|
|
class ProcessVMSelectionMixin(object):
|
2023-11-22 10:12:05 +00:00
|
|
|
|
2023-12-06 11:13:47 +00:00
|
|
|
def post(self, request, *args, **kwargs):
|
2023-11-22 10:12:05 +00:00
|
|
|
|
2023-12-06 11:13:47 +00:00
|
|
|
template_id = int(request.POST.get('vm_template_id'))
|
|
|
|
configuration_id = int(request.POST.get('configuration'))
|
|
|
|
template = OpenNebulaManager().get_template(template_id)
|
|
|
|
data = VirtualMachineTemplateSerializer(template).data
|
|
|
|
configuration = HostingPlan.objects.get(id=configuration_id)
|
2023-11-22 10:12:05 +00:00
|
|
|
|
2023-12-06 11:13:47 +00:00
|
|
|
request.session['template'] = data
|
|
|
|
request.session['specs'] = configuration.serialize()
|
2023-11-22 10:12:05 +00:00
|
|
|
|
2023-12-06 11:13:47 +00:00
|
|
|
if not request.user.is_authenticated():
|
|
|
|
request.session['next'] = reverse('hosting:payment')
|
|
|
|
return redirect(reverse('hosting:login'))
|
|
|
|
return redirect(reverse('hosting:payment'))
|
2023-11-22 10:12:05 +00:00
|
|
|
|
|
|
|
|
2023-12-06 11:13:47 +00:00
|
|
|
class HostingContextMixin(object):
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
#context['MULTISITE_CMS_FALLBACK'] = settings.MULTISITE_CMS_FALLBACK
|
2023-11-22 10:12:05 +00:00
|
|
|
return context
|