0.12.36 pays and subscribes

This commit is contained in:
SDE
2024-04-20 12:15:55 +03:00
parent 5c06aceb27
commit bb319780b6
17 changed files with 347 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
from .models import *
from django.template.loader import render_to_string
from django.utils.translation import get_language, activate
from datetime import datetime, timedelta
def get_cur_user_subscribe(user):
@@ -13,7 +14,7 @@ def get_cur_user_subscribe(user):
return user_subscribe
def get_subsribes_w_options():
def get_subscribes_w_options():
all_options = SubscribeOption.objects.filter(enable=True)
subscribes = Subscribe.objects.filter(enable=True)
for subscribe in subscribes:
@@ -23,6 +24,28 @@ def get_subsribes_w_options():
return subscribes, all_options
def check_n_enable_subscribe_by_order(order):
subscribes_for_user = SubscribeForUser.objects.filter(user=order.user)
if order and order.enable and order.status == 'charged':
kwargs = {
'user': order.user,
'subscribe': order.subscribe,
'last_paid_DT': datetime.now(),
'paid_period_from_DT': datetime.now(),
'paid_period_to_DT': datetime.now() + timedelta(hours=order.subscribe.period),
'receive_finish_subscribe_msg': True,
}
subscribe_for_user = SubscribeForUser.objects.create(**kwargs)
order.subscribe_for_user = subscribe_for_user
order.save()
subscribes_for_user = [subscribe_for_user]
return subscribes_for_user
def get_profile_subscribe_page_content_html(request):
try:
@@ -32,9 +55,20 @@ def get_profile_subscribe_page_content_html(request):
# data = json.loads(request.body)
# all_options = SubscribeOption.objects.filter(enable=True)
subscribes, all_options = get_subsribes_w_options()
subscribes, all_options = get_subscribes_w_options()
subscribe_for_user = None
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 not subscribe_for_user:
subscribe_for_user = SubscribeForUser.objects.filter(user=request.user)
subscribe_for_user = SubscribeForUser.objects.filter(user=request.user)
if not subscribe_for_user:
tpl_name = 'blocks/profile/b_subscribe_variants.html'
else: