From a99924b94cd904e688b140037fce58d36b4e86ee Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 23 Dec 2020 17:09:27 +0530 Subject: [PATCH] Rename do_create_vm to do_provisioning; and pass real_request --- datacenterlight/views.py | 28 +++++++++++++++++----------- webhook/views.py | 7 ++++--- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index fac5f6fe..9e4e7ed7 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -1016,11 +1016,12 @@ class OrderConfirmationView(DetailView, FormView): "requires_source_action") msg = subscription_result.get('error') return show_error(msg, self.request) - do_create_vm( + do_provisioning( req, user, stripe_api_cus_id, card_details_response, stripe_subscription_obj, stripe_onetime_charge, gp_details, specs, vm_template_id, - template, request.session.get('billing_address_data') + template, request.session.get('billing_address_data'), + self.request ) try: custom_user = CustomUser.objects.get(email=user.get('email')) @@ -1047,9 +1048,10 @@ class OrderConfirmationView(DetailView, FormView): return JsonResponse(response) -def do_create_vm(request, user, stripe_api_cus_id, card_details_response, - stripe_subscription_obj, stripe_onetime_charge, gp_details, - specs, vm_template_id, template, billing_address_data): +def do_provisioning(request, user, stripe_api_cus_id, card_details_response, + stripe_subscription_obj, stripe_onetime_charge, gp_details, + specs, vm_template_id, template, billing_address_data, + real_request): """ :param request: a dict { @@ -1077,6 +1079,7 @@ def do_create_vm(request, user, stripe_api_cus_id, card_details_response, :param specs: :param vm_template_id: :param template: + :param real_request: :return: """ # Create user if the user is not logged in and if he is not already @@ -1255,14 +1258,14 @@ def do_create_vm(request, user, stripe_api_cus_id, card_details_response, 'reply_to': ['info@ungleich.ch'], } send_plain_email_task.delay(email_data) - + redirect_url = reverse('datacenterlight:index') + if real_request: + clear_all_session_vars(real_request) + if real_request.user.is_authenticated(): + redirect_url = reverse('hosting:invoices') response = { 'status': True, - 'redirect': ( - reverse('hosting:invoices') - if request.user.is_authenticated() - else reverse('datacenterlight:index') - ), + 'redirect': redirect_url, 'msg_title': str(_('Thank you for the payment.')), 'msg_body': str( _('You will soon receive a confirmation email of the ' @@ -1290,6 +1293,9 @@ def do_create_vm(request, user, stripe_api_cus_id, card_details_response, vm_template_id, template, user ) + if real_request: + clear_all_session_vars(real_request) + def show_error(msg, request): messages.add_message(request, messages.ERROR, msg, diff --git a/webhook/views.py b/webhook/views.py index 20ee6c45..c61bf3f0 100644 --- a/webhook/views.py +++ b/webhook/views.py @@ -9,7 +9,7 @@ from django.http import HttpResponse from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST -from datacenterlight.views import do_create_vm +from datacenterlight.views import do_provisioning from membership.models import StripeCustomer from hosting.models import IncompleteSubscriptions @@ -180,7 +180,7 @@ def handle_webhook(request): logger.debug("5*******") logger.debug(template) logger.debug("6*******") - do_create_vm( + do_provisioning( request=request, user={'name': incomplete_sub.name, 'email': incomplete_sub.email}, @@ -192,7 +192,8 @@ def handle_webhook(request): specs=specs, vm_template_id=incomplete_sub.vm_template_id, template=template, - billing_address_data=billing_address_data + billing_address_data=billing_address_data, + real_request=None ) except (IncompleteSubscriptions.DoesNotExist, IncompleteSubscriptions.MultipleObjectsReturned) as ex: