From cd524350d8748e0f9c7f2232be9760e6f55116e2 Mon Sep 17 00:00:00 2001
From: "M.Ravi"
diff --git a/datacenterlight/templates/datacenterlight/pricing.html b/datacenterlight/templates/datacenterlight/pricing.html index 6c1be74c..7c8e66a6 100644 --- a/datacenterlight/templates/datacenterlight/pricing.html +++ b/datacenterlight/templates/datacenterlight/pricing.html @@ -1,7 +1,7 @@ {% load staticfiles i18n%} {% get_current_language as LANGUAGE_CODE %} - +
diff --git a/datacenterlight/urls.py b/datacenterlight/urls.py index 9c3c84fb..f14e7186 100644 --- a/datacenterlight/urls.py +++ b/datacenterlight/urls.py @@ -1,6 +1,6 @@ from django.conf.urls import url -from .views import IndexView, BetaProgramView, LandingProgramView, BetaAccessView, PricingView +from .views import IndexView, BetaProgramView, LandingProgramView, BetaAccessView, PricingView, SuccessView, OrderView urlpatterns = [ @@ -8,5 +8,7 @@ urlpatterns = [ url(r'^/beta-program/?$', BetaProgramView.as_view(), name='beta'), url(r'^/landing/?$', LandingProgramView.as_view(), name='landing'), url(r'^/pricing/?$', PricingView.as_view(), name='pricing'), + url(r'^/order/?$', OrderView.as_view(), name='order'), + url(r'^/order-success/?$', SuccessView.as_view(), name='order_success'), url(r'^/beta_access?$', BetaAccessView.as_view(), name='beta_access'), ] diff --git a/datacenterlight/views.py b/datacenterlight/views.py index f8a5de6a..19591339 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -7,6 +7,8 @@ from django.core.urlresolvers import reverse_lazy, reverse from utils.mailer import BaseEmail from django.shortcuts import render from django.shortcuts import redirect +from django import forms +from django.core.exceptions import ValidationError from opennebula_api.models import OpenNebulaManager from opennebula_api.serializers import VirtualMachineTemplateSerializer @@ -14,6 +16,9 @@ from opennebula_api.serializers import VirtualMachineTemplateSerializer class LandingProgramView(TemplateView): template_name = "datacenterlight/landing.html" +class SuccessView(TemplateView): + template_name = "datacenterlight/success.html" + class PricingView(TemplateView): template_name = "datacenterlight/pricing.html" @@ -63,6 +68,81 @@ class PricingView(TemplateView): return redirect(reverse('hosting:payment')) +class OrderView(TemplateView): + template_name = "datacenterlight/order.html" + + 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): + + 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:order')) + + 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:order')) + + # We have valid email and name of the customer, hence send an + # email to the admin + + context = { + 'base_url': "{0}://{1}".format(self.request.scheme, self.request.get_host()), + 'name': name, + 'email': email, + 'cores': cores, + 'memory': memory, + 'storage': storage, + 'price': price, + 'template': template_data['name'], + } + email_data = { + 'subject': 'New Order Received', + 'to': 'info@ungleich.ch', + 'context': context, + 'template_name': 'new_order_notification', + 'template_path': 'datacenterlight/emails/' + } + email = BaseEmail(**email_data) + email.send() + + return HttpResponseRedirect(reverse('datacenterlight:order_success')) + + class BetaAccessView(FormView): template_name = "datacenterlight/beta_access.html" form_class = BetaAccessForm