From 5d9b2ee41a83acc7d264197e1d64b259255bc116 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 5 Oct 2018 10:36:13 +0200 Subject: [PATCH] Refactor clearing all session variables --- datacenterlight/utils.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/datacenterlight/utils.py b/datacenterlight/utils.py index 8da408a0..b9edc994 100644 --- a/datacenterlight/utils.py +++ b/datacenterlight/utils.py @@ -89,8 +89,14 @@ def create_vm(billing_address_data, stripe_customer_id, specs, create_vm_task.delay(vm_template_id, user, specs, template, order.id) - for session_var in ['specs', 'template', 'billing_address', - 'billing_address_data', 'card_id', - 'token', 'customer']: - if session_var in request.session: - del request.session[session_var] + clear_all_session_vars(request) + + +def clear_all_session_vars(request): + if request.session is not None: + for session_var in ['specs', 'template', 'billing_address', + 'billing_address_data', 'card_id', + 'token', 'customer','generic_payment_type', + 'generic_payment_details', 'product_id']: + if session_var in request.session: + del request.session[session_var] \ No newline at end of file