add get_ai_response

This commit is contained in:
2026-02-01 15:59:32 +03:30
parent 17096924c1
commit d6b6b46e3b
81 changed files with 331 additions and 202 deletions

View File

@@ -177,3 +177,77 @@ class SSLAdapter(HTTPAdapter):
self.context = create_urllib3_context()
self.context.options |= 0x4 # OP_LEGACY_SERVER_CONNECT
super().__init__(*args, **kwargs)
from datetime import datetime, timedelta
from django.utils import timezone
def apply_date_filter(queryset, date_filter):
if not date_filter:
return queryset
field = date_filter.get("field", "Date")
filter_type = date_filter.get("type")
value = date_filter.get("value")
now = timezone.now()
if filter_type == "today":
start = now.replace(hour=0, minute=0, second=0, microsecond=0)
end = start + timedelta(days=1)
return queryset.filter(
**{f"{field}__gte": start, f"{field}__lt": end}
)
if filter_type == "yesterday":
start = (now - timedelta(days=1)).replace(
hour=0, minute=0, second=0, microsecond=0
)
end = start + timedelta(days=1)
return queryset.filter(
**{f"{field}__gte": start, f"{field}__lt": end}
)
if filter_type == "last_n_days" and value:
start = now - timedelta(days=int(value))
return queryset.filter(**{f"{field}__gte": start})
if filter_type == "this_week":
start = now - timedelta(days=now.weekday())
start = start.replace(hour=0, minute=0, second=0, microsecond=0)
return queryset.filter(**{f"{field}__gte": start})
if filter_type == "this_month":
start = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
return queryset.filter(**{f"{field}__gte": start})
if filter_type == "last_n_month" and value:
start = now
for _ in range(int(value)):
start = (start.replace(day=1) - timedelta(days=1)).replace(day=1)
start = start.replace(hour=0, minute=0, second=0, microsecond=0)
return queryset.filter(**{f"{field}__gte": start})
if filter_type == "this_year":
start = now.replace(
month=1, day=1, hour=0, minute=0, second=0, microsecond=0
)
return queryset.filter(**{f"{field}__gte": start})
if filter_type == "last_n_year" and value:
start = now.replace(
year=now.year - int(value),
month=1,
day=1,
hour=0,
minute=0,
second=0,
microsecond=0
)
return queryset.filter(**{f"{field}__gte": start})
return queryset