From 29591598638f9b5c544c4bdd5a8e5e383b8f7eba Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Wed, 21 Jun 2017 01:40:55 +0530 Subject: [PATCH 01/18] Added cache_control decorator to control cache while returning back to the index page --- datacenterlight/views.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 427f8c70..2b304606 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -10,6 +10,7 @@ from django.shortcuts import render from django.shortcuts import redirect from django import forms from django.core.exceptions import ValidationError +from django.views.decorators.cache import cache_control from opennebula_api.models import OpenNebulaManager from opennebula_api.serializers import VirtualMachineTemplateSerializer @@ -170,6 +171,7 @@ class IndexView(CreateView): success_url = "/datacenterlight#requestform" success_message = "Thank you, we will contact you as soon as possible" + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def get(self, request, *args, **kwargs): try: manager = OpenNebulaManager() From 385df4e069a8b78f129a4f9c019b033512ddcbe4 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Wed, 21 Jun 2017 13:13:10 +0530 Subject: [PATCH 02/18] Added vm_name parameter to create_vm --- opennebula_api/models.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/opennebula_api/models.py b/opennebula_api/models.py index 397c0f0c..8059c82b 100644 --- a/opennebula_api/models.py +++ b/opennebula_api/models.py @@ -239,7 +239,7 @@ class OpenNebulaManager(): ) ) - def create_vm(self, template_id, specs, ssh_key=None): + def create_vm(self, template_id, specs, ssh_key=None, vm_name=None): template = self.get_template(template_id) vm_specs_formatter = """ - """.format(ssh=ssh_key) + + """ vm_id = self.client.call(oca.VmTemplate.METHODS['instantiate'], template.id, '', From 52524a97a6381de25bc84f9a54c5b7b1af858eeb Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Wed, 21 Jun 2017 13:14:58 +0530 Subject: [PATCH 03/18] Added PaymentOrderView --- datacenterlight/views.py | 179 ++++++++++++++++++++++++++++++++++----- 1 file changed, 160 insertions(+), 19 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 2b304606..19100aba 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -11,9 +11,15 @@ from django.shortcuts import redirect from django import forms from django.core.exceptions import ValidationError from django.views.decorators.cache import cache_control +from django.conf import settings +from utils.forms import BillingAddressForm, UserBillingAddressForm +from membership.models import StripeCustomer +from hosting.models import HostingOrder, HostingBill +from utils.stripe_utils import StripeUtils +from datetime import datetime from opennebula_api.models import OpenNebulaManager -from opennebula_api.serializers import VirtualMachineTemplateSerializer +from opennebula_api.serializers import VirtualMachineTemplateSerializer, VirtualMachineSerializer class LandingProgramView(TemplateView): template_name = "datacenterlight/landing.html" @@ -21,6 +27,14 @@ class LandingProgramView(TemplateView): class SuccessView(TemplateView): template_name = "datacenterlight/success.html" + def get(self, request, *args, **kwargs): + if 'specs' not in request.session or 'user' not in request.session: + return HttpResponseRedirect(reverse('datacenterlight:index')) + else : + del request.session['specs'] + del request.session['user'] + return render(request, self.template_name) + class PricingView(TemplateView): template_name = "datacenterlight/pricing.html" @@ -171,8 +185,12 @@ class IndexView(CreateView): success_url = "/datacenterlight#requestform" success_message = "Thank you, we will contact you as soon as possible" - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def get(self, request, *args, **kwargs): + if 'specs' in request.session : + del request.session['specs'] + if 'user' in request.session : + del request.session['user'] try: manager = OpenNebulaManager() templates = manager.get_templates() @@ -215,26 +233,22 @@ class IndexView(CreateView): 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, + specs = { + 'cpu': cores, 'memory': memory, - 'storage': storage, - 'price': price, - 'template': template_data['name'], + 'disk_size': storage, + 'price': price } - email_data = { - 'subject': "Data Center Light Order from %s" % context['email'], - 'from_email': '(datacenterlight) datacenterlight Support ', - 'to': ['info@ungleich.ch'], - 'body': "\n".join(["%s=%s" % (k, v) for (k, v) in context.items()]), - 'reply_to': [context['email']], + + this_user = { + 'name': name, + 'email': email } - email = EmailMessage(**email_data) - email.send() - - return HttpResponseRedirect(reverse('datacenterlight:order_success')) + + request.session['specs'] = specs + request.session['template'] = template_data + request.session['user'] = this_user + return HttpResponseRedirect(reverse('datacenterlight:payment')) def get_success_url(self): success_url = reverse('datacenterlight:index') @@ -283,3 +297,130 @@ class IndexView(CreateView): messages.add_message(self.request, messages.SUCCESS, self.success_message) return super(IndexView, self).form_valid(form) + + +class PaymentOrderView(FormView): + template_name = 'hosting/payment.html' + form_class = BillingAddressForm + + def get_context_data(self, **kwargs): + context = super(PaymentOrderView, self).get_context_data(**kwargs) + context.update({ + 'stripe_key': settings.STRIPE_API_PUBLIC_KEY + }) + return context + + @cache_control(no_cache=True, must_revalidate=True, no_store=True) + def get(self, request, *args, **kwargs): + if 'specs' not in request.session or 'user' not in request.session: + return HttpResponseRedirect(reverse('datacenterlight:index')) + return self.render_to_response(self.get_context_data()) + + def post(self, request, *args, **kwargs): + form = self.get_form() + if form.is_valid(): + # Get billing address data + billing_address_data = form.cleaned_data + context = self.get_context_data() + template = request.session.get('template') + specs = request.session.get('specs') + user = request.session.get('user') + vm_template_id = template.get('id', 1) + final_price = specs.get('price') + token = form.cleaned_data.get('token') + owner = self.request.user + + # Get or create stripe customer + customer = StripeCustomer.get_or_create(email=user.get('email'), + token=token) + if not customer: + form.add_error("__all__", "Invalid credit card") + return self.render_to_response(self.get_context_data(form=form)) + + # Create Billing Address + billing_address = form.save() + + # Make stripe charge to a customer + stripe_utils = StripeUtils() + charge_response = stripe_utils.make_charge(amount=final_price, + customer=customer.stripe_id) + charge = charge_response.get('response_object') + + # Check if the payment was approved + if not charge: + context.update({ + 'paymentError': charge_response.get('error'), + 'form': form + }) + return render(request, self.template_name, context) + + charge = charge_response.get('response_object') + + # Create OpenNebulaManager + manager = OpenNebulaManager(email=settings.OPENNEBULA_USERNAME, + password=settings.OPENNEBULA_PASSWORD) + + # Create a vm using logged user + vm_id = manager.create_vm( + template_id=vm_template_id, + specs=specs, + name="{email}-{template_name}-{date}".format( + email=user.get('email'), + template_name=template.get('name'), + date=int(datetime.now().strftime("%s"))) + ) + + # Create a Hosting Order + #order = HostingOrder.create( + # price=final_price, + # vm_id=vm_id, + # customer=customer, + # billing_address=billing_address + #) + + ## Create a Hosting Bill + #bill = HostingBill.create( + # customer=customer, billing_address=billing_address) + # + ## Create Billing Address for User if he does not have one + #if not customer.user.billing_addresses.count(): + # billing_address_data.update({ + # 'user': customer.user.id + # }) + # billing_address_user_form = UserBillingAddressForm( + # billing_address_data) + # billing_address_user_form.is_valid() + # billing_address_user_form.save() + # + ## Associate an order with a stripe payment + #order.set_stripe_charge(charge) + + # If the Stripe payment was successed, set order status approved + #order.set_approved() + + vm = VirtualMachineSerializer(manager.get_vm(vm_id)).data + + context = { + 'name': user.get('name'), + 'email': user.get('email'), + 'cores': specs.get('cpu'), + 'memory': specs.get('memory'), + 'storage': specs.get('disk_size'), + 'price': specs.get('price'), + 'template': template.get('name'), + 'vm.name': vm['name'], + 'vm.id': vm['vm_id'], + 'order id': order.id + } + email_data = { + 'subject': "Data Center Light Order from %s" % context['email'], + 'from_email': '(Data Center Light) Data Center Light Support ', + 'to': ['info@ungleich.ch'], + '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')) + else: + return self.form_invalid(form) From 66f82572f1ce1a93e5dd35bf9724b1257e05d35a Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Wed, 21 Jun 2017 13:15:37 +0530 Subject: [PATCH 04/18] Added payment url --- datacenterlight/urls.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/datacenterlight/urls.py b/datacenterlight/urls.py index aad6442e..8dac321e 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, SuccessView +from .views import IndexView, BetaProgramView, LandingProgramView, BetaAccessView, PricingView, SuccessView, PaymentOrderView urlpatterns = [ @@ -8,6 +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'^/payment/?$', PaymentOrderView.as_view(), name='payment'), url(r'^/order-success/?$', SuccessView.as_view(), name='order_success'), url(r'^/beta_access?$', BetaAccessView.as_view(), name='beta_access'), ] From bbfc7e851549dbc5615dd6c9a05635c5426eebd1 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Wed, 21 Jun 2017 23:37:36 +0530 Subject: [PATCH 05/18] Not persisting stripe details to db --- datacenterlight/views.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 19100aba..fd024c94 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -331,19 +331,22 @@ class PaymentOrderView(FormView): owner = self.request.user # Get or create stripe customer - customer = StripeCustomer.get_or_create(email=user.get('email'), - token=token) - if not customer: + stripe_utils = StripeUtils() + stripe_data = stripe_utils.create_customer(token, user.get('email')) + customer_stripe_id = None + if stripe_data.get('response_object'): + customer_stripe_id = stripe_data.get('response_object').get('id') + + if customer_stripe_id is None: form.add_error("__all__", "Invalid credit card") return self.render_to_response(self.get_context_data(form=form)) - - # Create Billing Address + billing_address = form.save() # Make stripe charge to a customer stripe_utils = StripeUtils() charge_response = stripe_utils.make_charge(amount=final_price, - customer=customer.stripe_id) + customer=customer_stripe_id) charge = charge_response.get('response_object') # Check if the payment was approved @@ -364,7 +367,7 @@ class PaymentOrderView(FormView): vm_id = manager.create_vm( template_id=vm_template_id, specs=specs, - name="{email}-{template_name}-{date}".format( + vm_name="{email}-{template_name}-{date}".format( email=user.get('email'), template_name=template.get('name'), date=int(datetime.now().strftime("%s"))) @@ -395,7 +398,7 @@ class PaymentOrderView(FormView): ## Associate an order with a stripe payment #order.set_stripe_charge(charge) - # If the Stripe payment was successed, set order status approved + # If the Stripe payment is success, set order status approved #order.set_approved() vm = VirtualMachineSerializer(manager.get_vm(vm_id)).data @@ -409,8 +412,7 @@ class PaymentOrderView(FormView): 'price': specs.get('price'), 'template': template.get('name'), 'vm.name': vm['name'], - 'vm.id': vm['vm_id'], - 'order id': order.id + 'vm.id': vm['vm_id'] } email_data = { 'subject': "Data Center Light Order from %s" % context['email'], From 387c45b96951a076788d645ed4970c05a79996fd Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Wed, 21 Jun 2017 23:38:35 +0530 Subject: [PATCH 06/18] We need the logo in the payment page even when user is not logged in --- hosting/templates/hosting/base_short.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hosting/templates/hosting/base_short.html b/hosting/templates/hosting/base_short.html index cf9f54d9..0ccfe5f9 100644 --- a/hosting/templates/hosting/base_short.html +++ b/hosting/templates/hosting/base_short.html @@ -46,7 +46,7 @@ - {% if request.user.is_authenticated %} + - {% endif %} +
{% block content %} From da0d8bf937a92b3b4bbf2d332494260c880444d7 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 22 Jun 2017 00:17:53 +0530 Subject: [PATCH 07/18] Added one.vm.rename xml-rpc call to rename a created vm --- opennebula_api/models.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/opennebula_api/models.py b/opennebula_api/models.py index 8059c82b..d18524c5 100644 --- a/opennebula_api/models.py +++ b/opennebula_api/models.py @@ -286,10 +286,7 @@ class OpenNebulaManager(): """.format(size=1024 * int(specs['disk_size']), image=image, image_uname=image_uname) - - if vm_name is not None: - vm_specs += """{template_vm_name} - """.format(template_vm_name=vm_name) + vm_specs += "" if ssh_key: vm_specs += "{ssh}".format(ssh=ssh_key) @@ -309,6 +306,13 @@ class OpenNebulaManager(): 'release', vm_id ) + + if vm_name is not None: + self.oneadmin_client.call( + 'vm.rename', + vm_id, + vm_name + ) return vm_id def delete_vm(self, vm_id): From 041352ac6d5049fef6d77211f25265d69e9dd750 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 22 Jun 2017 00:28:44 +0530 Subject: [PATCH 08/18] Cleaned up some commented code --- datacenterlight/views.py | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index fd024c94..0c576f3a 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -373,34 +373,6 @@ class PaymentOrderView(FormView): date=int(datetime.now().strftime("%s"))) ) - # Create a Hosting Order - #order = HostingOrder.create( - # price=final_price, - # vm_id=vm_id, - # customer=customer, - # billing_address=billing_address - #) - - ## Create a Hosting Bill - #bill = HostingBill.create( - # customer=customer, billing_address=billing_address) - # - ## Create Billing Address for User if he does not have one - #if not customer.user.billing_addresses.count(): - # billing_address_data.update({ - # 'user': customer.user.id - # }) - # billing_address_user_form = UserBillingAddressForm( - # billing_address_data) - # billing_address_user_form.is_valid() - # billing_address_user_form.save() - # - ## Associate an order with a stripe payment - #order.set_stripe_charge(charge) - - # If the Stripe payment is success, set order status approved - #order.set_approved() - vm = VirtualMachineSerializer(manager.get_vm(vm_id)).data context = { From e848c318d0813a203c5d0d8bce9e35b96f07d1d6 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 22 Jun 2017 13:18:54 +0530 Subject: [PATCH 09/18] Addd order confirmation url --- datacenterlight/urls.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/datacenterlight/urls.py b/datacenterlight/urls.py index 8dac321e..65401b13 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, SuccessView, PaymentOrderView +from .views import IndexView, BetaProgramView, LandingProgramView, BetaAccessView, PricingView, SuccessView, PaymentOrderView, OrderConfirmationView urlpatterns = [ @@ -9,6 +9,7 @@ urlpatterns = [ url(r'^/landing/?$', LandingProgramView.as_view(), name='landing'), url(r'^/pricing/?$', PricingView.as_view(), name='pricing'), url(r'^/payment/?$', PaymentOrderView.as_view(), name='payment'), + url(r'^/order-confirmation/(?P\d+)/?$', OrderConfirmationView.as_view(), name='order_confirmation'), url(r'^/order-success/?$', SuccessView.as_view(), name='order_success'), url(r'^/beta_access?$', BetaAccessView.as_view(), name='beta_access'), ] From c4c110b50672973d03a55d3a07fdffc01b683671 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 22 Jun 2017 13:21:07 +0530 Subject: [PATCH 10/18] Added OrderConfirmationView to dcl --- datacenterlight/views.py | 95 +++++++++++++++++++++++++++++++++------- 1 file changed, 79 insertions(+), 16 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 0c576f3a..b9372514 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -1,4 +1,4 @@ -from django.views.generic import FormView, CreateView, TemplateView +from django.views.generic import FormView, CreateView, TemplateView, DetailView from django.http import HttpResponseRedirect from .forms import BetaAccessForm from .models import BetaAccess, BetaAccessVMType, BetaAccessVM @@ -17,6 +17,7 @@ from membership.models import StripeCustomer from hosting.models import HostingOrder, HostingBill from utils.stripe_utils import StripeUtils from datetime import datetime +from membership.models import CustomUser, StripeCustomer from opennebula_api.models import OpenNebulaManager from opennebula_api.serializers import VirtualMachineTemplateSerializer, VirtualMachineSerializer @@ -328,27 +329,33 @@ class PaymentOrderView(FormView): vm_template_id = template.get('id', 1) final_price = specs.get('price') token = form.cleaned_data.get('token') - owner = self.request.user - - # Get or create stripe customer - stripe_utils = StripeUtils() - stripe_data = stripe_utils.create_customer(token, user.get('email')) - customer_stripe_id = None - if stripe_data.get('response_object'): - customer_stripe_id = stripe_data.get('response_object').get('id') + custom_user = CustomUser.objects.get(email=user.get('email')) + if custom_user is None: + password = CustomUser.get_random_password() + # Register the user, and do not send emails + CustomUser.register(user.get('name'), + password, + user.get('email'), + app='dcl', + base_url=None, send_email=False) - if customer_stripe_id is None: + + # Get or create stripe customer + customer = StripeCustomer.get_or_create(email=user.get('name'), + token=token) + if not customer: form.add_error("__all__", "Invalid credit card") return self.render_to_response(self.get_context_data(form=form)) + # Create Billing Address billing_address = form.save() - + # Make stripe charge to a customer stripe_utils = StripeUtils() charge_response = stripe_utils.make_charge(amount=final_price, - customer=customer_stripe_id) + customer=customer.stripe_id) charge = charge_response.get('response_object') - + # Check if the payment was approved if not charge: context.update({ @@ -356,7 +363,7 @@ class PaymentOrderView(FormView): 'form': form }) return render(request, self.template_name, context) - + charge = charge_response.get('response_object') # Create OpenNebulaManager @@ -372,7 +379,35 @@ class PaymentOrderView(FormView): template_name=template.get('name'), date=int(datetime.now().strftime("%s"))) ) + + # Create a Hosting Order + order = HostingOrder.create( + price=final_price, + vm_id=vm_id, + customer=customer, + billing_address=billing_address + ) + + # Create a Hosting Bill + bill = HostingBill.create( + customer=customer, billing_address=billing_address) + # Create Billing Address for User if he does not have one + if not customer.user.billing_addresses.count(): + billing_address_data.update({ + 'user': customer.user.id + }) + billing_address_user_form = UserBillingAddressForm( + billing_address_data) + billing_address_user_form.is_valid() + billing_address_user_form.save() + + # Associate an order with a stripe payment + order.set_stripe_charge(charge) + + # If the Stripe payment was successed, set order status approved + order.set_approved() + vm = VirtualMachineSerializer(manager.get_vm(vm_id)).data context = { @@ -384,7 +419,8 @@ class PaymentOrderView(FormView): 'price': specs.get('price'), 'template': template.get('name'), 'vm.name': vm['name'], - 'vm.id': vm['vm_id'] + 'vm.id': vm['vm_id'], + 'order.id': order.id } email_data = { 'subject': "Data Center Light Order from %s" % context['email'], @@ -395,6 +431,33 @@ class PaymentOrderView(FormView): } email = EmailMessage(**email_data) email.send() - return HttpResponseRedirect(reverse('datacenterlight:order_success')) + return HttpResponseRedirect(reverse('datacenterlight:order_confirmation', kwargs={'pk': order.id})) else: return self.form_invalid(form) + +class OrderConfirmationView(DetailView): + template_name = "datacenterlight/order_detail.html" + context_object_name = "order" + model = HostingOrder + def get_context_data(self, **kwargs): + # Get context + context = super(DetailView, self).get_context_data(**kwargs) + obj = self.get_object() + manager = OpenNebulaManager(email=settings.OPENNEBULA_USERNAME, + password=settings.OPENNEBULA_PASSWORD) + try: + vm = manager.get_vm(obj.vm_id) + context['vm'] = VirtualMachineSerializer(vm).data + context['next_url'] = reverse('datacenterlight:order_success') + except WrongIdError: + messages.error(self.request, + 'The VM you are looking for is unavailable at the moment. \ + Please contact Data Center Light support.' + ) + self.kwargs['error'] = 'WrongIdError' + context['error'] = 'WrongIdError' + except ConnectionRefusedError: + messages.error(self.request, + 'In order to create a VM, you need to create/upload your SSH KEY first.' + ) + return context From b4c3172a4d5bae18240e10399197e13af4d0cb98 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 22 Jun 2017 13:22:14 +0530 Subject: [PATCH 11/18] Added send_email flag to send/not send email on user registration. Added get_random_password method to CustomUser --- membership/models.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/membership/models.py b/membership/models.py index 8bd9feec..44da4ef7 100644 --- a/membership/models.py +++ b/membership/models.py @@ -6,6 +6,7 @@ from django.contrib.auth.hashers import make_password from django.core.validators import RegexValidator from django.contrib.auth.models import User from django.contrib.sites.models import Site +from django.utils.crypto import get_random_string from utils.stripe_utils import StripeUtils from utils.mailer import DigitalGlarusRegistrationMailer @@ -73,7 +74,7 @@ class CustomUser(AbstractBaseUser, PermissionsMixin): REQUIRED_FIELDS = ['name', 'password'] @classmethod - def register(cls, name, password, email, app='digital_glarus', base_url=None): + def register(cls, name, password, email, app='digital_glarus', base_url=None, send_email=True): user = cls.objects.filter(email=email).first() if not user: user = cls.objects.create_user(name=name, email=email, password=password) @@ -83,17 +84,18 @@ class CustomUser(AbstractBaseUser, PermissionsMixin): dg.send_mail(to=user.email) elif app == 'dcl': user.is_active = False - email_data = { - 'subject': _('Activate your Data Center Light account'), - 'from_address': '(Data Center Light) Data Center Light Support ', - 'to': user.email, - 'context': {'base_url' : base_url, - 'activation_link' : reverse('hosting:validate', kwargs={'validate_slug': user.validation_slug})}, - 'template_name': 'user_activation', - 'template_path': 'datacenterlight/emails/' - } - email = BaseEmail(**email_data) - email.send() + if send_email is True: + email_data = { + 'subject': _('Activate your Data Center Light account'), + 'from_address': '(Data Center Light) Data Center Light Support ', + 'to': user.email, + 'context': {'base_url' : base_url, + 'activation_link' : reverse('hosting:validate', kwargs={'validate_slug': user.validation_slug})}, + 'template_name': 'user_activation', + 'template_path': 'datacenterlight/emails/' + } + email = BaseEmail(**email_data) + email.send() return user else: return None @@ -113,6 +115,10 @@ class CustomUser(AbstractBaseUser, PermissionsMixin): return True return False + @classmethod + def get_random_password(cls): + return get_random_string(24) + def is_superuser(self): return False From 31c389e72cd9732092bb86094b64f07038c78613 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 22 Jun 2017 13:23:13 +0530 Subject: [PATCH 12/18] Added order_detail.html for dcl --- .../datacenterlight/order_detail.html | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 datacenterlight/templates/datacenterlight/order_detail.html diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html new file mode 100644 index 00000000..a866dac8 --- /dev/null +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -0,0 +1,84 @@ +{% extends "hosting/base_short.html" %} +{% load staticfiles bootstrap3 %} +{% load i18n %} +{% block content %} + +
+ {% if messages %} +
+
+
+
+ {% for message in messages %} + {{ message }} + {% endfor %} +
+
+
+ {% endif %} + {% if not error %} +
+
+
+

{% trans "Invoice"%}

{% trans "Order #"%} {{order.id}}

+
+
+
+
+
+

{% trans "Billed To:"%}

+ {{user.name}}
+ {{order.billing_address.street_address}},{{order.billing_address.postal_code}}
+ {{order.billing_address.city}}, {{order.billing_address.country}}. +
+
+
+
+ {% trans "Billed To:"%}
+ {{order.created_at}}

+ {% trans "Status:"%}
+ {{order.status}} +

+
+ +
+
+
+
+
+ {% trans "Payment Method:"%}
+ {{order.cc_brand}} ending **** {{order.last4}}
+ {{user.email}} +
+
+
+
+
+ +
+
+

{% trans "Order summary"%}

+
+
+

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

+
+

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

+
+

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

+
+

{% trans "Total"%}

{{vm.price}} CHF

+
+
+ {% url 'datacenterlight:payment' as payment_url %} + {% if payment_url in request.META.HTTP_REFERER %} + + {% endif %} +
+
+ {% endif %} +
+{%endblock%} From 5caa79f1990066df954faf0664b0536dc49bebe5 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 22 Jun 2017 13:40:39 +0530 Subject: [PATCH 13/18] Added CustomUser.DoesNotExist error exception --- datacenterlight/views.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index b9372514..9708eb24 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -329,8 +329,9 @@ class PaymentOrderView(FormView): vm_template_id = template.get('id', 1) final_price = specs.get('price') token = form.cleaned_data.get('token') - custom_user = CustomUser.objects.get(email=user.get('email')) - if custom_user is None: + try: + custom_user = CustomUser.objects.get(email=user.get('email')) + except CustomUser.DoesNotExist: password = CustomUser.get_random_password() # Register the user, and do not send emails CustomUser.register(user.get('name'), From d4e7eb9511b2adc4ad15f55ac775727a12fcc50f Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 22 Jun 2017 23:48:14 +0530 Subject: [PATCH 14/18] Added CustomUser model reload code --- membership/models.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/membership/models.py b/membership/models.py index 44da4ef7..e491031e 100644 --- a/membership/models.py +++ b/membership/models.py @@ -176,16 +176,14 @@ class StripeCustomer(models.Model): return stripe_customer except StripeCustomer.DoesNotExist: + CustomUser.refresh_from_db() user = CustomUser.objects.get(email=email) - stripe_utils = StripeUtils() stripe_data = stripe_utils.create_customer(token, email) if stripe_data.get('response_object'): stripe_cus_id = stripe_data.get('response_object').get('id') - stripe_customer = StripeCustomer.objects.\ create(user=user, stripe_id=stripe_cus_id) - return stripe_customer else: return None From e5929b8f769ec0f546308835da35d9be72673870 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Fri, 23 Jun 2017 00:15:47 +0530 Subject: [PATCH 15/18] Removed call to refresh_from_db as it was wrongly used --- membership/models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/membership/models.py b/membership/models.py index e491031e..72b56d3c 100644 --- a/membership/models.py +++ b/membership/models.py @@ -176,7 +176,6 @@ class StripeCustomer(models.Model): return stripe_customer except StripeCustomer.DoesNotExist: - CustomUser.refresh_from_db() user = CustomUser.objects.get(email=email) stripe_utils = StripeUtils() stripe_data = stripe_utils.create_customer(token, email) From 5b8a26eeb3db3b2fdb0662136066a1a54f7fd703 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Fri, 23 Jun 2017 00:31:08 +0530 Subject: [PATCH 16/18] Fixed a blunder mistake. Was using name instead of email --- datacenterlight/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 9708eb24..e4329b89 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -342,7 +342,7 @@ class PaymentOrderView(FormView): # Get or create stripe customer - customer = StripeCustomer.get_or_create(email=user.get('name'), + customer = StripeCustomer.get_or_create(email=user.get('email'), token=token) if not customer: form.add_error("__all__", "Invalid credit card") From 3ca7153414484f0b22f7cac437a5e9f785542e58 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Fri, 23 Jun 2017 01:34:31 +0530 Subject: [PATCH 17/18] Changed invoice text --- datacenterlight/templates/datacenterlight/order_detail.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index a866dac8..ebde2171 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -20,7 +20,7 @@
-

{% trans "Invoice"%}

{% trans "Order #"%} {{order.id}}

+

{% trans "Confirm Order"%}

{% trans "Order #"%} {{order.id}}


From 796fbbe1f83b1f3132ca90ec3350076dc1eec1c8 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Fri, 23 Jun 2017 04:38:10 +0530 Subject: [PATCH 18/18] Removed status from the order page --- .../templates/datacenterlight/order_detail.html | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index ebde2171..cb412558 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -34,13 +34,8 @@
- {% trans "Billed To:"%}
+ {% trans "Date"%}:
{{order.created_at}}

- {% trans "Status:"%}
- {{order.status}} -