mezzanine_events/templatetags/events_tags.py
def upcoming_occurrences(
    context,
    category_slug=None,
    limit=5,
    template="mezzanine_events/includes/upcoming_occurrences.html",
):
    """
    Return a limited number of upcoming event occurrences.
    Optionally can be filtered by category slug.
    """
    occurrences = Occurrence.objects.published()
    try:
        category = EventCategory.objects.get(slug=category_slug)
        context["category"] = category
        occurrences = occurrences.filter(event__categories=category)
    except EventCategory.DoesNotExist:
        context["category"] = None

    # Sort and group by event (grouping doesn't work without sorting)
    by_event = lambda x: x[2].event_id
    occurrence_tuples = occurrences.all_occurrences(from_date=now())
    occurrence_tuples = sorted(occurrence_tuples, key=by_event)
    unique_occurrences = (next(tuples) for event, tuples in groupby(occurrence_tuples, by_event))
    # Sort by the first item (start date) again
    unique_occurrences = sorted(unique_occurrences, key=itemgetter(0))
    context["occurrences"] = islice(unique_occurrences, limit)
    return get_template(template).render(context.flatten())

    Return a limited number of upcoming event occurrences.
    Optionally can be filtered by category slug.
    
Return a limited number of upcoming event occurrences.
Optionally can be filtered by category slug.
Return a limited number of upcoming event occurrences . Optionally can be filtered by category slug .
def upcoming_occurrences(
    context,
    category_slug=None,
    limit=5,
    template="mezzanine_events/includes/upcoming_occurrences.html",
):
    occurrences = Occurrence.objects.published()
    try:
        category = EventCategory.objects.get(slug=category_slug)
        context["category"] = category
        occurrences = occurrences.filter(event__categories=category)
    except EventCategory.DoesNotExist:
        context["category"] = None
    by_event = lambda x: x[2].event_id
    occurrence_tuples = occurrences.all_occurrences(from_date=now())
    occurrence_tuples = sorted(occurrence_tuples, key=by_event)
    unique_occurrences = (next(tuples) for event, tuples in groupby(occurrence_tuples, by_event))
    unique_occurrences = sorted(unique_occurrences, key=itemgetter(0))
    context["occurrences"] = islice(unique_occurrences, limit)
    return get_template(template).render(context.flatten())
def upcoming_occurrences ( context , category_slug = None , limit = 5 , template = "mezzanine_events/includes/upcoming_occurrences.html" , ) : occurrences = Occurrence . objects . published ( ) try : category = EventCategory . objects . get ( slug = category_slug ) context [ "category" ] = category occurrences = occurrences . filter ( event__categories = category ) except EventCategory . DoesNotExist : context [ "category" ] = None by_event = lambda x : x [ 2 ] . event_id occurrence_tuples = occurrences . all_occurrences ( from_date = now ( ) ) occurrence_tuples = sorted ( occurrence_tuples , key = by_event ) unique_occurrences = ( next ( tuples ) for event , tuples in groupby ( occurrence_tuples , by_event ) ) unique_occurrences = sorted ( unique_occurrences , key = itemgetter ( 0 ) ) context [ "occurrences" ] = islice ( unique_occurrences , limit ) return get_template ( template ) . render ( context . flatten ( ) )
Return a limited number of upcoming event occurrences.
Return a limited number of upcoming event occurrences .
"""
    Return a limited number of upcoming event occurrences.
    Optionally can be filtered by category slug.
    """ # Sort and group by event (grouping doesn't work without sorting) # Sort by the first item (start date) again
context
category_slug
limit
template