activist icon indicating copy to clipboard operation
activist copied to clipboard

Bug: “Days ahead” filter only shows events on the exact day

Open aasimsyed opened this issue 3 weeks ago • 4 comments

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

  1. Visit the events list and open the sidebar filters.
  2. Choose the “7 days ahead” option.
  3. 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.

aasimsyed avatar Nov 11 '25 20:11 aasimsyed

Hello @andrewtavis my team and I would like to work on this issue. Here's the rest of my team:

  • mfan59
  • a-estrada
  • lhazard434

Chuksll avatar Nov 14 '25 21:11 Chuksll

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!

andrewtavis avatar Nov 14 '25 22:11 andrewtavis

Hi! I'm @Chuksll's teammate, and I would like to be assigned to this issue, please! Thanks :)

mfan59 avatar Nov 14 '25 22:11 mfan59

Hi, adding to above, I am a teammate of @Chuksll and @mfan59 and would like to be assigned to this issue as well. Thanks!

a-estrada avatar Nov 14 '25 22:11 a-estrada

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"]

SuperHappycat avatar Nov 26 '25 14:11 SuperHappycat

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!

mfan59 avatar Nov 26 '25 14:11 mfan59