Skip to content

Commit 381233b

Browse files
Copilottonyqiu123
andcommitted
Implement server-side filtering to hide past events by default
Co-authored-by: tonyqiu123 <90103972+tonyqiu123@users.noreply.github.com>
1 parent e545538 commit 381233b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

backend/example/views.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .models import Clubs, Events
1111
from django.core.serializers import serialize
1212
import json
13+
from datetime import datetime, timezone, timedelta
1314

1415

1516
@api_view(["GET"])
@@ -19,7 +20,8 @@ def home(request):
1920
{
2021
"message": "Instagram Event Scraper API",
2122
"endpoints": {
22-
"GET /api/events/": "Get all events from database",
23+
"GET /api/events/": "Get events from database (hides past events by default)",
24+
"GET /api/events/?include_past=true": "Get all events including past ones",
2325
"GET /api/clubs/": "Get all clubs from database",
2426
"GET /api/health/": "Health check",
2527
},
@@ -42,6 +44,9 @@ def get_events(request):
4244
offset = int(request.GET.get('offset', 0)) # Default offset 0
4345
search_term = request.GET.get('search', '').strip() # Get search term
4446

47+
# Get date filtering parameter - by default hide past events
48+
include_past = request.GET.get('include_past', 'false').lower() in ('true', '1', 'yes')
49+
4550
# Limit the maximum number of events per request
4651
limit = min(limit, 100) # Max 100 events per request
4752

@@ -53,6 +58,18 @@ def get_events(request):
5358

5459
# Apply filters to create filtered queryset
5560
filtered_queryset = base_queryset
61+
62+
# Apply date filtering by default (hide past events)
63+
if not include_past:
64+
# Include events from today onwards (where today is determined in UTC)
65+
# The requirement mentions "today at 5am utc" as reference, but for simplicity
66+
# we'll use today in UTC timezone as the cutoff
67+
now_utc = datetime.now(timezone.utc)
68+
cutoff_date = now_utc.date()
69+
70+
# Include events from today onwards
71+
filtered_queryset = filtered_queryset.filter(date__gte=cutoff_date)
72+
5673
if search_term:
5774
filtered_queryset = filtered_queryset.filter(name__icontains=search_term)
5875

0 commit comments

Comments
 (0)