profile static pages
This commit is contained in:
SDE
2023-09-04 12:08:25 +03:00
parent 436cd9aa58
commit 7dd1fe5dfe
14 changed files with 354 additions and 173 deletions

35
SubscribesApp/funcs.py Normal file
View File

@@ -0,0 +1,35 @@
from .models import *
from django.template.loader import render_to_string
def get_profile_subscribe_page_content_html(request):
try:
# data = json.loads(request.body)
all_options = SubscribeOption.objects.filter(enable=True)
subscribe_for_user = SubscribeForUser.objects.filter(user=request.user)
if not subscribe_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_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)
subscribes = Subscribe.objects.filter(enable=True)
for subscribe in subscribes:
subscribe_options_ids = subscribe.options.values_list('id', flat=True)
subscribe.disabled_options = all_options.exclude(id__in=subscribe_options_ids)
Dict = {
'subscribe_for_user': subscribe_for_user,
'subscribes': subscribes
}
html = render_to_string(tpl_name, Dict, request=request)
return html
except Exception as e:
msg = f'show_cur_subscribe_ajax Error = {str(e)}'
return msg

View File

@@ -11,13 +11,14 @@ from django.utils.translation import gettext as _
from datetime import datetime
from django.template.loader import render_to_string
from django.urls import reverse
# from .funcs import *
from .funcs import *
import json
from datetime import datetime, time, timedelta
from channels.layers import get_channel_layer
from asgiref.sync import async_to_sync
@login_required(login_url='/profile/login/')
def subscribe_now_ajax(request):
@@ -76,33 +77,36 @@ def show_cur_subscribe_ajax(request):
if request.method != 'POST':
raise Http404
try:
html = get_profile_subscribe_page_content_html(request)
return JsonResponse({'html': html}, status=200)
# data = json.loads(request.body)
all_options = SubscribeOption.objects.filter(enable=True)
subscribe_for_user = SubscribeForUser.objects.filter(user=request.user)
if not subscribe_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_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)
subscribes = Subscribe.objects.filter(enable=True)
for subscribe in subscribes:
subscribe_options_ids = subscribe.options.values_list('id', flat=True)
subscribe.disabled_options = all_options.exclude(id__in=subscribe_options_ids)
Dict = {
'subscribe_for_user': subscribe_for_user,
'subscribes': subscribes
}
html = render_to_string(tpl_name, Dict, request=request)
return JsonResponse({'html': html}, status=200)
except Exception as e:
msg = f'show_cur_subscribe_ajax Error = {str(e)}'
return JsonResponse({'error': msg}, status=400)
# try:
#
# # data = json.loads(request.body)
# all_options = SubscribeOption.objects.filter(enable=True)
#
# subscribe_for_user = SubscribeForUser.objects.filter(user=request.user)
# if not subscribe_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_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)
#
# subscribes = Subscribe.objects.filter(enable=True)
# for subscribe in subscribes:
# subscribe_options_ids = subscribe.options.values_list('id', flat=True)
# subscribe.disabled_options = all_options.exclude(id__in=subscribe_options_ids)
#
# Dict = {
# 'subscribe_for_user': subscribe_for_user,
# 'subscribes': subscribes
# }
#
# html = render_to_string(tpl_name, Dict, request=request)
# return JsonResponse({'html': html}, status=200)
#
# except Exception as e:
# msg = f'show_cur_subscribe_ajax Error = {str(e)}'
# return JsonResponse({'error': msg}, status=400)