Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions djAerolith/wordwalls/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
Medal,
User,
)
from django.http import JsonResponse
from django.core.exceptions import ValidationError
from datetime import datetime


# If not logged in, will ask user to log in and forward back to the main url
Expand Down Expand Up @@ -55,6 +58,18 @@ def get_stats(request, lexicon, type_of_challenge_id):
name=name, lexicon__lexiconName__in=lexica
)

# Validate and parse dates
try:
if start_date:
start_date = datetime.strptime(start_date, "%Y-%m-%d").date()
if end_date:
end_date = datetime.strptime(end_date, "%Y-%m-%d").date()
except ValueError:
return JsonResponse(
{"error": "Invalid date format. Dates must be in YYYY-MM-DD format."},
status=400,
)

if not start_date and not end_date:
pass

Expand Down