activist
activist copied to clipboard
Bug: “Days ahead” filter only shows events on the exact day
Terms
- [x] I have searched all open bug reports
- [x] I agree to follow activist's Code of Conduct
Behavior
Summary
When I pick a “Days ahead” filter (1/7/30) on the events page, it only shows events happening exactly on that future day. I expect it to show everything coming up between now and that day instead.
Steps to Reproduce
- Visit the events list and open the sidebar filters.
- Choose the “7 days ahead” option.
- Notice that events happening tomorrow or three days out disappear, and only events occurring seven days from now remain.
Actual Behaviour
- “Days ahead” filters behave like single-day lookups; the list only shows events on that exact future date.
Expected Behaviour
- “7 days ahead” should include all upcoming events from now through day 7 inclusive (same for 1 and 30 days).
Acceptance Criteria
- [ ] Update the “Days ahead” filter to treat the selected value as an upper-bound range starting from today.
- [ ] Verify that 1/7/30 selections include all events between now and the chosen day.
- [ ] Add regression tests so the filter keeps working as a range.
Hello @andrewtavis my team and I would like to work on this issue. Here's the rest of my team:
- mfan59
- a-estrada
- lhazard434
Sure thing, @Chuksll! One thing to note is that each of you needs to write into this issue and #1711 so I can assign. You can't assign people without triage rights to the repo unless they write into the issue.
Please let us know if you need any support!
Hi! I'm @Chuksll's teammate, and I would like to be assigned to this issue, please! Thanks :)
Hi, adding to above, I am a teammate of @Chuksll and @mfan59 and would like to be assigned to this issue as well. Thanks!
Can I join too? I think I know how to fix it.
#SPDX-License-Identifier: AGPL-3.0-or-later
"""
A class for filtering events based on user defined properties.
"""
from datetime import date, datetime, timedelta
from typing import Any, Union
import django_filters
from django.db.models.query import QuerySet
from content.models import Topic
from events.models import Event
class EventFilters(django_filters.FilterSet): # type: ignore[misc]
"""
General class to allow filtering events based on URL parameters.
"""
name = django_filters.CharFilter(field_name="name", lookup_expr="icontains")
topics = django_filters.ModelMultipleChoiceFilter(
field_name="topics__type", # simply "topics" if you want to filter by ID
to_field_name="type", # the field on Topic model to match against
queryset=Topic.objects.all(),
)
location = django_filters.CharFilter(
field_name="offline_location__display_name",
lookup_expr="icontains",
)
type = django_filters.CharFilter(
field_name="type",
lookup_expr="iexact",
)
setting = django_filters.CharFilter(
field_name="setting",
lookup_expr="iexact",
)
active_on = django_filters.DateTimeFilter(
method="filter_active_on",
label="Active on (exact datetime)",
)
days_ahead = django_filters.NumberFilter(
method="filter_days_ahead",
label="Days ahead (inclusive range from now)",
)
def filter_active_on(
self, queryset: QuerySet[Any, Any], name: str, day: Union[date, datetime]
) -> QuerySet[Any, Any]:
"""
Filter based on the start and end time of an event.
Parameters
----------
queryset : QuerySet[Any, Any]
The query set of events to check.
name : str
The name of events to filter by.
day : Union[date, datetime]
The date to filter the events by.
Returns
-------
QuerySet[Any, Any]
The query set of active events based on the provided arguments.
"""
start = datetime.combine(day, datetime.min.time())
end = datetime.combine(day, datetime.max.time())
return queryset.filter(start_time__lte=end, end_time__gte=start)
def filter_days_ahead(
self, queryset: QuerySet[Any, Any], name: str, value: int
) -> QuerySet[Any, Any]:
"""
Filter events that occur any time between now and 'value' days from now (inclusive).
Parameters
----------
queryset : QuerySet[Any, Any]
The query set of events to check.
name : str
The filter field name.
value : int
Number of days ahead to include in the range (inclusive).
Returns
-------
QuerySet[Any, Any]
The query set of events active within the date range.
"""
now = datetime.now()
end = now + timedelta(days=value)
return queryset.filter(
start_time__lte=end,
end_time__gte=now
)
class Meta:
model = Event
fields = ["name", "topics", "type", "setting", "active_on", "location", "days_ahead"]
Hi @SuperHappycat; we’re actually doing this issue for a class project and need to push up our changes in order to complete it for our final. Would it be possible for you to work on another by any chance? Thank you so much!