happenings/managers.py
def all_month_events(self, year, month, category=None, tag=None,
                         loc=False, cncl=False):
        """
        Returns all events that have an occurrence within the given
        month & year.
        """
        kwargs = self._get_kwargs(category, tag)
        ym_first, ym_last = self.get_first_and_last(year, month)

        pref = []
        if loc:
            pref.append("location")
        if cncl:
            pref.append("cancellations")

        # for yearly repeat, we need to check the start and end date months
        # b/c yearly events should occur every year in the same month
        r = Q(repeat="YEARLY")
        dstart_mo = Q(start_date__month=month)
        dend_mo = Q(end_date__month=month)

        dstart_yr = Q(start_date__year=year)
        dend_yr = Q(end_date__year=year)

        return self.model.objects.filter(
            # only events that are still repeating
            r & (dstart_mo | dend_mo) |  # yearly repeat
            (~Q(repeat="NEVER")) |  # all other repeats
            ((dstart_yr | dend_yr) & (dstart_mo | dend_yr)),  # non-repeating
            Q(end_repeat=None) | Q(end_repeat__gte=ym_first),
            start_date__lte=ym_last  # no events that haven't started yet
        ).filter(**kwargs).prefetch_related(*pref).order_by('start_date').distinct()
def all_month_events(self, year, month, category=None, tag=None,
                         loc=False, cncl=False):
        kwargs = self._get_kwargs(category, tag)
        ym_first, ym_last = self.get_first_and_last(year, month)

        pref = []
        if loc:
            pref.append("location")
        if cncl:
            pref.append("cancellations")

        # for yearly repeat, we need to check the start and end date months
        # b/c yearly events should occur every year in the same month
        r = Q(repeat="YEARLY")
        dstart_mo = Q(start_date__month=month)
        dend_mo = Q(end_date__month=month)

        dstart_yr = Q(start_date__year=year)
        dend_yr = Q(end_date__year=year)

        return self.model.objects.filter(
            # only events that are still repeating
            r & (dstart_mo | dend_mo) |  # yearly repeat
            (~Q(repeat="NEVER")) |  # all other repeats
            ((dstart_yr | dend_yr) & (dstart_mo | dend_yr)),  # non-repeating
            Q(end_repeat=None) | Q(end_repeat__gte=ym_first),
            start_date__lte=ym_last  # no events that haven't started yet
        ).filter(**kwargs).prefetch_related(*pref).order_by('start_date').distinct()
def all_month_events ( self , year , month , category = None , tag = None , loc = False , cncl = False ) : kwargs = self . _get_kwargs ( category , tag ) ym_first , ym_last = self . get_first_and_last ( year , month ) pref = [ ] if loc : pref . append ( "location" ) if cncl : pref . append ( "cancellations" ) # for yearly repeat, we need to check the start and end date months # b/c yearly events should occur every year in the same month r = Q ( repeat = "YEARLY" ) dstart_mo = Q ( start_date__month = month ) dend_mo = Q ( end_date__month = month ) dstart_yr = Q ( start_date__year = year ) dend_yr = Q ( end_date__year = year ) return self . model . objects . filter ( # only events that are still repeating r & ( dstart_mo | dend_mo ) | # yearly repeat ( ~ Q ( repeat = "NEVER" ) ) | # all other repeats ( ( dstart_yr | dend_yr ) & ( dstart_mo | dend_yr ) ) , # non-repeating Q ( end_repeat = None ) | Q ( end_repeat__gte = ym_first ) , start_date__lte = ym_last # no events that haven't started yet ) . filter ( * * kwargs ) . prefetch_related ( * pref ) . order_by ( 'start_date' ) . distinct ( )
Returns all events that have an occurrence within the given
        month & year.
Returns all events that have an occurrence within the given month & year .