def post(self, request): cores = request.POST.get('cpu') memory = request.POST.get('ram') storage = request.POST.get('storage') price = request.POST.get('total') template_id = int(request.POST.get('config')) manager = OpenNebulaManager() template = manager.get_template(template_id) request.session['template'] = VirtualMachineTemplateSerializer( template).data if not request.user.is_authenticated(): request.session['next'] = reverse('hosting:payment') request.session['specs'] = { 'cpu': cores, 'memory': memory, 'disk_size': storage, 'price': price, } return redirect(reverse('hosting:payment'))
def get(self, request, *args, **kwargs): if not UserHostingKey.objects.filter(user=self.request.user).exists(): messages.success( request, 'In order to create a VM, you need to create/upload your SSH KEY first.' ) return HttpResponseRedirect(reverse('hosting:ssh_keys')) try: manager = OpenNebulaManager() templates = manager.get_templates() configuration_options = HostingPlan.get_serialized_configs() context = { 'templates': VirtualMachineTemplateSerializer(templates, many=True).data, 'configuration_options': configuration_options, } except: messages.error( request, 'We could not load the VM templates due to a backend connection \ error. Please try again in a few minutes') context = {'error': 'connection'} return render(request, self.template_name, context)
def post(self, request): manager = OpenNebulaManager() template_id = request.POST.get('vm_template_id') template = manager.get_template(template_id) configuration_id = int(request.POST.get('configuration')) configuration = HostingPlan.objects.get(id=configuration_id) request.session['template'] = VirtualMachineTemplateSerializer( template).data request.session['specs'] = configuration.serialize() return redirect(reverse('hosting:payment'))
def post(self, request): cores = request.POST.get('cpu') memory = request.POST.get('ram') storage = request.POST.get('storage') price = request.POST.get('total') template_id = int(request.POST.get('config')) manager = OpenNebulaManager() template = manager.get_template(template_id) template_data = VirtualMachineTemplateSerializer(template).data name = request.POST.get('name') email = request.POST.get('email') name_field = forms.CharField() email_field = forms.EmailField() try: name = name_field.clean(name) except ValidationError as err: messages.add_message(self.request, messages.ERROR, '%(value) is not a proper name.'.format(name)) return HttpResponseRedirect(reverse('datacenterlight:index')) try: email = email_field.clean(email) except ValidationError as err: messages.add_message( self.request, messages.ERROR, '%(value) is not a proper email.'.format(email)) return HttpResponseRedirect(reverse('datacenterlight:index')) context = { 'name': name, 'email': email, 'cores': cores, 'memory': memory, 'storage': storage, 'price': price, 'template': template_data['name'], } email_data = { 'subject': "Data Center Light Order from %s" % context['email'], 'from_email': '(datacenterlight) datacenterlight Support <*****@*****.**>', 'to': ['*****@*****.**'], 'body': "\n".join(["%s=%s" % (k, v) for (k, v) in context.items()]), 'reply_to': [context['email']], } email = EmailMessage(**email_data) email.send() return HttpResponseRedirect(reverse('datacenterlight:order_success'))
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': "*****@*****.**", 'vm_types': data # 'vm_types': VirtualMachineType.get_serialized_vm_types(), } return context
def post(self, request): cores = request.POST.get('cpu') memory = request.POST.get('ram') storage = request.POST.get('storage') price = request.POST.get('total') template_id = int(request.POST.get('config')) manager = OpenNebulaManager() template = manager.get_template(template_id) template_data = VirtualMachineTemplateSerializer(template).data name = request.POST.get('name') email = request.POST.get('email') name_field = forms.CharField() email_field = forms.EmailField() try: name = name_field.clean(name) except ValidationError as err: msg = '{} {}.'.format(name, _('is not a proper name')) messages.add_message(self.request, messages.ERROR, msg, extra_tags='name') return HttpResponseRedirect( reverse('datacenterlight:index') + "#order_form") try: email = email_field.clean(email) except ValidationError as err: msg = '{} {}.'.format(email, _('is not a proper email')) messages.add_message(self.request, messages.ERROR, msg, extra_tags='email') return HttpResponseRedirect( reverse('datacenterlight:index') + "#order_form") specs = { 'cpu': cores, 'memory': memory, 'disk_size': storage, 'price': price } this_user = {'name': name, 'email': email} request.session['specs'] = specs request.session['template'] = template_data request.session['user'] = this_user return HttpResponseRedirect(reverse('datacenterlight:payment'))
def get(self, request, *args, **kwargs): try: manager = OpenNebulaManager() templates = manager.get_templates() context = { 'templates': VirtualMachineTemplateSerializer(templates, many=True).data, } except: messages.error( request, 'We have a temporary problem to connect to our backend. \ Please try again in a few minutes') context = {'error': 'connection'} return render(request, self.template_name, context)
def post(self, request, *args, **kwargs): 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) request.session['template'] = data request.session['specs'] = configuration.serialize() if not request.user.is_authenticated(): request.session['next'] = reverse('hosting:payment') return redirect(reverse('hosting:login')) return redirect(reverse('hosting:payment'))
def get(self, request, *args, **kwargs): for session_var in ['specs', 'user', 'billing_address_data']: if session_var in request.session: del request.session[session_var] try: manager = OpenNebulaManager() templates = manager.get_templates() context = { 'templates': VirtualMachineTemplateSerializer(templates, many=True).data } except: messages.error( request, 'We have a temporary problem to connect to our backend. \ Please try again in a few minutes') context = {'error': 'connection'} return render(request, self.template_name, context)
def get_context_data(self, **kwargs): HOSTING = 'django' templates = OpenNebulaManager().get_templates() data = VirtualMachineTemplateSerializer(templates, many=True).data configuration_options = HostingPlan.get_serialized_configs() # configuration_detail = dict(VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING) context = { 'hosting': HOSTING, 'hosting_long': "Django", # 'configuration_detail': configuration_detail, 'domain': "django-hosting.ch", 'google_analytics': "UA-62285904-6", 'vm_types': data, 'email': "*****@*****.**", 'configuration_options': configuration_options, 'templates': templates, } return context