35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
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 |