From b374e7aecaf2eb7f94a7caadd4ee30c5676b0f07 Mon Sep 17 00:00:00 2001 From: SDE Date: Tue, 7 May 2024 14:21:52 +0300 Subject: [PATCH] 0.12.51 subscribe page w dynamically load --- BillingApp/funcs.py | 4 ++-- SubscribesApp/funcs.py | 27 ++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/BillingApp/funcs.py b/BillingApp/funcs.py index 6da202a..d5a2f5c 100644 --- a/BillingApp/funcs.py +++ b/BillingApp/funcs.py @@ -20,7 +20,7 @@ def get_order_status(order): # if res['amount'] == res['amount_charged'] and res['status'] == 'charged': order.save() - return order.status + # return order.status except Exception as e: @@ -29,7 +29,7 @@ def get_order_status(order): msg = f'Exception get_order_status (data = {str(order.id)}) = {str(e)}' print(msg) - return None + return order def get_orders_for_user(user): diff --git a/SubscribesApp/funcs.py b/SubscribesApp/funcs.py index f8614a8..2fb1afa 100644 --- a/SubscribesApp/funcs.py +++ b/SubscribesApp/funcs.py @@ -2,6 +2,8 @@ from .models import * from django.template.loader import render_to_string from django.utils.translation import get_language, activate from datetime import datetime, timedelta +import json + def get_cur_user_subscribe(user): @@ -53,7 +55,12 @@ def get_profile_subscribe_page_content_html(request): from GeneralApp.funcs import get_and_set_lang lang = get_and_set_lang(request) - # data = json.loads(request.body) + data = {} + if request.body: + data = json.loads(request.body) + check_orders_required = False + if data and 'check_orders_required' in data: #Требуется проверка статусов заказов + check_orders_required = True # all_options = SubscribeOption.objects.filter(enable=True) subscribes, all_options = get_subscribes_w_options() @@ -63,9 +70,19 @@ def get_profile_subscribe_page_content_html(request): if request.user and request.user.is_authenticated: from BillingApp.funcs import get_orders_for_user, get_order_status orders = get_orders_for_user(request.user) - # for order in orders: - # res = get_order_status(order) - # subscribe_for_user = check_n_enable_subscribe_by_order(order) + if orders: + if check_orders_required: + for order in orders: + order = get_order_status(order) + subscribes_for_user = check_n_enable_subscribe_by_order(order) + if subscribes_for_user: + subscribe_for_user = subscribes_for_user[0] + else: + subscribes.get(id=order.subscribe.id).order_error = order.status + check_orders_required = False + else: + check_orders_required = True + if not subscribe_for_user: subscribe_for_user = SubscribeForUser.objects.filter(user=request.user) @@ -86,7 +103,7 @@ def get_profile_subscribe_page_content_html(request): Dict = { 'subscribe_for_user': subscribe_for_user, 'subscribes': subscribes, - 'active_orders': orders, + 'check_orders_required': check_orders_required, } html = render_to_string(tpl_name, Dict, request=request)