From a48188a1905068101e862237089fa67332bebf41 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Fri, 22 Sep 2017 21:20:00 +0200 Subject: [PATCH] datacenterlight: Added create vm modal and responding with json --- .../datacenterlight/order_detail.html | 199 ++++++++++-------- datacenterlight/views.py | 29 ++- 2 files changed, 143 insertions(+), 85 deletions(-) diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index 8000c925..ddad8673 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -9,98 +9,133 @@ {% block content %} -
- {% if messages %} -
-
-
-
- {% for message in messages %} - {{ message }} - {% endfor %} -
+
+ {% if messages %} +
+
+
+
+ {% for message in messages %} + {{ message }} + {% endfor %}
- {% endif %} - {% if not error %} -
-
-
-

{% trans "Confirm Order"%}

-
-
-
-
-
- {% trans "Date"%}:
- {% now "Y-m-d H:i" %}

-
-
-
-
-

{% trans "Billed To:"%}

- {% with billing_address_data as billing_address %} - {{billing_address.cardholder_name}}
{{billing_address.street_address}}, {{billing_address.postal_code}}
- {{billing_address.city}}, {{billing_address.country}}. - {% endwith %} -
-
-
-
-
-
- {% trans "Payment Method:"%}
- {{cc_brand}} {% trans "ending in" %} **** {{cc_last4}}
- {{request.session.user.email}} -
-
-
+
+ {% endif %} + {% if not error %} +
+
+
+

{% trans "Confirm Order"%}

-
- -
-
-

{% trans "Order summary"%}

-
-
- {% with request.session.specs as vm %} -

{% trans "Cores"%} {{vm.cpu}}

-
-

{% trans "Memory"%} {{vm.memory}} GB

-
-

{% trans "Disk space"%} {{vm.disk_size}} GB

-
-

{% trans "Configuration"%} {{request.session.template.name}}

-
-

{% trans "Total"%}

{{vm.price}} CHF /{% trans "Month" %}

+
+
+
+
+ {% trans "Date"%}:
+ {% now "Y-m-d H:i" %}

+
+
+
+
+

{% trans "Billed To:"%}

+ {% with billing_address_data as billing_address %} + {{billing_address.cardholder_name}}
{{billing_address.street_address}}, {{billing_address.postal_code}}
+ {{billing_address.city}}, {{billing_address.country}}. {% endwith %} +
+
+
+
+
+
+ {% trans "Payment Method:"%}
+ {{cc_brand}} {% trans "ending in" %} **** {{cc_last4}}
+ {{request.session.user.email}} +
-
-
- {% csrf_token %} -
-
-

{% blocktrans with vm_price=request.session.specs.price %}By clicking "Place order" this plan will charge your credit card account with the fee of {{ vm_price }}CHF/month{% endblocktrans %}.

-
- -
-
- {% endif %} +
+ +
+
+

{% trans "Order summary"%}

+
+
+ {% with request.session.specs as vm %} +

{% trans "Cores"%} {{vm.cpu}}

+
+

{% trans "Memory"%} {{vm.memory}} GB

+
+

{% trans "Disk space"%} {{vm.disk_size}} GB

+
+

{% trans "Configuration"%} {{request.session.template.name}}

+
+

{% trans "Total"%}

{{vm.price}} CHF /{% trans "Month" %}

+ {% endwith %} +
+
+
+ {% csrf_token %} +
+
+

{% blocktrans with vm_price=request.session.specs.price %}By clicking "Place order" this plan will charge your credit card account with the fee of {{ vm_price }}CHF/month{% endblocktrans %}.

+
+
+ +
+
+
+
+
+ {% endif %} +
+ + + - + {%endblock%} diff --git a/datacenterlight/views.py b/datacenterlight/views.py index e7d5fffa..1f2f8895 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -1,4 +1,5 @@ import logging +import json from django import forms from django.conf import settings @@ -6,7 +7,7 @@ from django.contrib import messages from django.contrib.auth import login, authenticate from django.core.exceptions import ValidationError from django.core.urlresolvers import reverse -from django.http import HttpResponseRedirect +from django.http import HttpResponseRedirect, HttpResponse from django.shortcuts import redirect from django.shortcuts import render from django.utils.translation import get_language, ugettext_lazy as _ @@ -554,6 +555,9 @@ class OrderConfirmationView(DetailView): try: custom_user = CustomUser.objects.get( email=user.get('email')) + customer = StripeCustomer.objects.filter( + user_id=custom_user.id).first() + stripe_customer_id = customer.id except CustomUser.DoesNotExist: logger.debug( "Customer {} does not exist.".format(user.get('email'))) @@ -577,6 +581,7 @@ class OrderConfirmationView(DetailView): customer = StripeCustomer.objects.filter( id=stripe_customer_id).first() custom_user = customer.user + stripe_customer_id = customer.id # Save billing address billing_address_data = request.session.get('billing_address_data') @@ -603,5 +608,23 @@ class OrderConfirmationView(DetailView): stripe_customer_id, billing_address_data, billing_address_id, stripe_subscription_obj, card_details_dict) - request.session['order_confirmation'] = True - return HttpResponseRedirect(reverse('datacenterlight:order_success')) + for session_var in ['specs', 'template', 'billing_address', + 'billing_address_data', + 'token', 'customer']: + if session_var in request.session: + del request.session[session_var] + + response = { + 'status': True, + 'redirect': reverse( + 'hosting:dashboard') if request.user.is_authenticated() else reverse( + 'datacenterlight:index'), + 'msg_title': str(_('Thank you for the order.')), + 'msg_body': str( + _('Your VM will be up and running in a few moments.' + ' We will send you a confirmation email as soon as' + ' it is ready.')) + } + + return HttpResponse(json.dumps(response), + content_type="application/json")