mirror of
https://github.com/lemeow125/DRF_Template.git
synced 2025-06-29 08:35:44 +08:00
Overhauled entire project config, added notifications, email templates, optimized stripe subscriptions, redis caching, and webdriver utilities
This commit is contained in:
parent
7cbe8fd720
commit
99dfcef67b
84 changed files with 4300 additions and 867 deletions
42
backend/subscriptions/tasks.py
Normal file
42
backend/subscriptions/tasks.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
from celery import shared_task
|
||||
|
||||
|
||||
@shared_task
|
||||
def get_user_subscription(user_id):
|
||||
from subscriptions.models import UserSubscription
|
||||
from accounts.models import CustomUser
|
||||
|
||||
USER = CustomUser.objects.get(id=user_id)
|
||||
|
||||
# Get a list of subscriptions for the specified user
|
||||
active_subscriptions = None
|
||||
if USER.user_group:
|
||||
active_subscriptions = UserSubscription.objects.filter(
|
||||
user_group=USER.user_group, valid=True)
|
||||
else:
|
||||
active_subscriptions = UserSubscription.objects.filter(
|
||||
user=USER, valid=True)
|
||||
|
||||
# Return first valid subscription if there is one
|
||||
if len(active_subscriptions) > 0:
|
||||
return active_subscriptions[0]
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
@shared_task
|
||||
def get_user_group_subscription(user_group):
|
||||
from subscriptions.models import UserSubscription
|
||||
from user_groups.models import UserGroup
|
||||
|
||||
USER_GROUP = UserGroup.objects.get(id=user_group)
|
||||
# Get a list of subscriptions for the specified user
|
||||
active_subscriptions = None
|
||||
active_subscriptions = UserSubscription.objects.filter(
|
||||
user_group=USER_GROUP, valid=True)
|
||||
|
||||
# Return first valid subscription if there is one
|
||||
if len(active_subscriptions) > 0:
|
||||
return active_subscriptions[0]
|
||||
else:
|
||||
return None
|
Loading…
Add table
Add a link
Reference in a new issue