0.12.51 subscribe page w dynamically load

This commit is contained in:
SDE
2024-05-07 14:21:52 +03:00
parent a0ee72bc81
commit b374e7aeca
2 changed files with 24 additions and 7 deletions

View File

@@ -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)