0.6.13
subscribe_now ajax
This commit is contained in:
@@ -8,6 +8,7 @@ from RoutesApp.js_views import new_route_view_ajax
|
||||
|
||||
urlpatterns = [
|
||||
path('show_cur_subscribe/', show_cur_subscribe_ajax, name='show_cur_subscribe_ajax'),
|
||||
path('subscribe_now/', subscribe_now_ajax, name='subscribe_now_ajax'),
|
||||
# path('create_ticket/', create_ticket_ajax, name='create_ticket_ajax'),
|
||||
# path('support_show_chat_by_ticket/', support_show_chat_by_ticket_ajax, name='support_show_chat_by_ticket_ajax'),
|
||||
# # path('send_msg/', send_msg_ajax, name='send_msg_ajax'),
|
||||
|
||||
@@ -13,11 +13,62 @@ from django.template.loader import render_to_string
|
||||
from django.urls import reverse
|
||||
# from .funcs import *
|
||||
import json
|
||||
from datetime import datetime, time
|
||||
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):
|
||||
|
||||
if request.method != 'POST':
|
||||
raise Http404
|
||||
|
||||
try:
|
||||
|
||||
data = json.loads(request.body)
|
||||
|
||||
subscribe = Subscribe.objects.get(id=data['subscribe_id'])
|
||||
|
||||
kwargs = {
|
||||
'user': request.user,
|
||||
'subscribe': subscribe,
|
||||
'last_paid_DT': datetime.now(),
|
||||
'paid_period_from_DT': datetime.now(),
|
||||
'paid_period_to_DT': datetime.now() + timedelta(hours=subscribe.period),
|
||||
'receive_finish_subscribe_msg': True,
|
||||
}
|
||||
|
||||
subscribe_for_user = SubscribeForUser.objects.filter(user=request.user)
|
||||
if subscribe_for_user:
|
||||
subscribe_for_user.update(**kwargs)
|
||||
else:
|
||||
subscribe_for_user = SubscribeForUser.objects.create(**kwargs)
|
||||
|
||||
if not subscribe_for_user:
|
||||
tpl_name = 'blocks/profile/b_subscribe_variants.html'
|
||||
else:
|
||||
tpl_name = 'blocks/profile/b_subscribe_current.html'
|
||||
|
||||
all_options = SubscribeOption.objects.filter(enable=True)
|
||||
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)
|
||||
|
||||
|
||||
@login_required(login_url='/profile/login/')
|
||||
def show_cur_subscribe_ajax(request):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user