Files
tripwithbonus/backend/api/utils/permissionChecker.py

14 lines
432 B
Python

from django.utils.timezone import now
from datetime import timedelta
from sitemanagement.models import RoutePromotionLog
MAX_ACTIONS_PER_MONTH = 5
def check_monthly_limit(user, route, action_type):
month_ago = now() - timedelta(days=30)
return RoutePromotionLog.objects.filter(
user=user,
route=route,
action_type=action_type,
created_at__gte=month_ago
).count() < MAX_ACTIONS_PER_MONTH