From 8ed567496b639cf25833cc8cab5654ebdf4aecab Mon Sep 17 00:00:00 2001 From: SDE Date: Tue, 7 May 2024 15:01:13 +0300 Subject: [PATCH] 0.12.52 subscribe page w dynamically load --- AuthApp/funcs.py | 5 +++-- SubscribesApp/funcs.py | 22 +++++++++++----------- SubscribesApp/js_views.py | 4 ++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/AuthApp/funcs.py b/AuthApp/funcs.py index 9f6ce96..114792b 100644 --- a/AuthApp/funcs.py +++ b/AuthApp/funcs.py @@ -42,8 +42,9 @@ def get_profile_page_content_html(request, page_name, data): elif page_name == 'support': return get_profile_support_page_content_html(request, data) elif page_name == 'my_subscribe': - from SubscribesApp.funcs import get_profile_subscribe_page_content_html - return get_profile_subscribe_page_content_html(request) + from SubscribesApp.funcs import get_profile_subscribe_page_content_Dict + res = get_profile_subscribe_page_content_Dict(request) + return res['html'] elif page_name == 'change_profile': return get_profile_change_page_content_html(request) elif page_name == 'dashboard': diff --git a/SubscribesApp/funcs.py b/SubscribesApp/funcs.py index 2fb1afa..18fdc62 100644 --- a/SubscribesApp/funcs.py +++ b/SubscribesApp/funcs.py @@ -48,7 +48,7 @@ def check_n_enable_subscribe_by_order(order): return subscribes_for_user -def get_profile_subscribe_page_content_html(request): +def get_profile_subscribe_page_content_Dict(request): try: @@ -64,7 +64,7 @@ def get_profile_subscribe_page_content_html(request): # all_options = SubscribeOption.objects.filter(enable=True) subscribes, all_options = get_subscribes_w_options() - subscribe_for_user = None + subscribes_for_user = None orders = None if request.user and request.user.is_authenticated: @@ -75,23 +75,21 @@ def get_profile_subscribe_page_content_html(request): 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: + if not subscribes_for_user: 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) + if not subscribes_for_user: + subscribes_for_user = SubscribeForUser.objects.filter(user=request.user) - if not subscribe_for_user: + if not subscribes_for_user: tpl_name = 'blocks/profile/b_subscribe_variants.html' else: tpl_name = 'blocks/profile/b_subscribe_current.html' - subscribe_for_user = subscribe_for_user[0] + subscribe_for_user = subscribes_for_user[0] subscribe_options_ids = subscribe_for_user.subscribe.options.values_list('id', flat=True) subscribe_for_user.subscribe.disabled_options = all_options.exclude(id__in=subscribe_options_ids) @@ -103,11 +101,13 @@ def get_profile_subscribe_page_content_html(request): Dict = { 'subscribe_for_user': subscribe_for_user, 'subscribes': subscribes, - 'check_orders_required': check_orders_required, } html = render_to_string(tpl_name, Dict, request=request) - return html + return { + 'html': html, + 'check_orders_required': check_orders_required, + } except Exception as e: msg = f'show_cur_subscribe_ajax Error = {str(e)}' diff --git a/SubscribesApp/js_views.py b/SubscribesApp/js_views.py index 17328be..5389032 100644 --- a/SubscribesApp/js_views.py +++ b/SubscribesApp/js_views.py @@ -91,8 +91,8 @@ def show_cur_subscribe_ajax(request): lang = get_and_set_lang(request) - html = get_profile_subscribe_page_content_html(request) - return JsonResponse({'html': html}, status=200) + Dict = get_profile_subscribe_page_content_Dict(request) + return JsonResponse(Dict, status=200) # try: #