1.0.12 subscribe buy routines
This commit is contained in:
@@ -16,42 +16,33 @@ def get_cur_user_subscribe(user):
|
||||
return user_subscribe
|
||||
|
||||
|
||||
def get_subscribes_w_options():
|
||||
def get_subscribes_w_options(user=None, check_subscribe_orders=False):
|
||||
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)
|
||||
if user and check_subscribe_orders:
|
||||
order = subscribe.get_last_order(user)
|
||||
if order and order.status not in ['charged']:
|
||||
error = f'{order.status}'
|
||||
if 'status' in order.json_data and 'failure_message' in order.json_data['status']:
|
||||
error = f'{error} ({order.json_data["status"]["failure_message"]})'
|
||||
subscribe.order_error = error
|
||||
|
||||
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:
|
||||
if order.status == 'charged':
|
||||
order = order.activate_subscribe_for_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,
|
||||
'enable': True,
|
||||
}
|
||||
subscribe_for_user = SubscribeForUser.objects.create(**kwargs)
|
||||
order.subscribe_for_user = subscribe_for_user
|
||||
order.save()
|
||||
|
||||
SubscribeForUser.objects.filter(user=order.user).exclude(id=subscribe_for_user.id).update(enable=False)
|
||||
|
||||
subscribes_for_user = [subscribe_for_user]
|
||||
|
||||
return subscribes_for_user
|
||||
return order
|
||||
|
||||
|
||||
def get_profile_subscribe_page_content_Dict(request):
|
||||
def get_profile_subscribe_page_content_Dict(request, check_orders_required=False):
|
||||
|
||||
try:
|
||||
|
||||
@@ -61,14 +52,15 @@ def get_profile_subscribe_page_content_Dict(request):
|
||||
data = {}
|
||||
if request.body:
|
||||
data = json.loads(request.body)
|
||||
check_orders_required = False
|
||||
# check_orders_required = False
|
||||
if data and 'check_orders_required' in data: #Требуется проверка статусов заказов
|
||||
check_orders_required = data['check_orders_required']
|
||||
# all_options = SubscribeOption.objects.filter(enable=True)
|
||||
subscribes, all_options = get_subscribes_w_options()
|
||||
|
||||
subscribes_for_user = None
|
||||
|
||||
subscribes = []
|
||||
subscribe_for_user = None
|
||||
all_options = []
|
||||
|
||||
orders = None
|
||||
if request.user and request.user.is_authenticated:
|
||||
@@ -78,21 +70,21 @@ def get_profile_subscribe_page_content_Dict(request):
|
||||
if check_orders_required:
|
||||
for order in orders:
|
||||
order = get_order_status(order)
|
||||
subscribes_for_user = check_n_enable_subscribe_by_order(order)
|
||||
if not subscribes_for_user:
|
||||
error = f'{order.status}'
|
||||
if 'status' in order.json_data and 'failure_message' in order.json_data['status']:
|
||||
error = f'{error} ({order.json_data["status"]["failure_message"]})'
|
||||
for subscribe in subscribes:
|
||||
if subscribe == order.subscribe:
|
||||
subscribe.order_error = error
|
||||
order = check_n_enable_subscribe_by_order(order)
|
||||
subscribe_for_user = order.subscribe_for_user
|
||||
|
||||
subscribes, all_options = get_subscribes_w_options(
|
||||
request.user, check_subscribe_orders=True)
|
||||
|
||||
check_orders_required = False
|
||||
else:
|
||||
check_orders_required = True
|
||||
|
||||
if not subscribes:
|
||||
subscribes, all_options = get_subscribes_w_options()
|
||||
|
||||
if not subscribes_for_user:
|
||||
subscribes_for_user = SubscribeForUser.objects.filter(enable=True, user=request.user)
|
||||
# if not subscribes_for_user:
|
||||
subscribes_for_user = SubscribeForUser.objects.filter(enable=True, user=request.user)
|
||||
|
||||
if not subscribes_for_user:
|
||||
tpl_name = 'blocks/profile/b_subscribe_variants.html'
|
||||
|
||||
Reference in New Issue
Block a user