happenings/utils/displays.py
def month_display(year, month, all_month_events,
                  start_day, net, qs, mini=False, request=None, context=None):
    """
    A function that returns an html calendar for the given
    month in the given year, with the number of events for that month
    shown on the generated calendar. Start_day is the day the calendar
    should start on (default is Monday).
    """
    # count the number of times events happen on a given day
    count = CountHandler(year, month, all_month_events).get_count()

    # sort count by start date using all_month_events (which is already sorted)
    for event in all_month_events[::-1]:
        for l in count.values():
            for item in l:
                if item[1] == event.pk:
                    l.insert(0, l.pop(l.index(item)))

    args = (year, month, count, all_month_events, start_day)
    if not mini:
        html_cal = EventCalendar(request=request, context=context, *args).formatmonth(year, month, net=net, qs=qs)
    else:
        html_cal = MiniEventCalendar(request=request, context=context, *args).formatmonth(year, month, net=net, qs=qs)

    nxt, prev = get_next_and_prev(net)
    extra_qs = ('&' + '&'.join(qs)) if qs else ''
    # inject next/prev querystring urls and make them aware of any querystrings
    # already present in the url
    html_cal = html_cal.replace(
        'class="month">\n<tr>',
        'class="month">\n<tr><th colspan="1" class="month-arrow-left">\
        <a href="?cal_prev=%d%s">&larr;</a></th>' % (prev, extra_qs)
    ).replace(
        '%d</th>' % year,
        '%d</th><th colspan="1" class="month-arrow-right">\
        <a href="?cal_next=%d%s">&rarr;</a></th>' % (year, nxt, extra_qs)
    )

    add_occurrences(all_month_events, count)

    return html_cal
def month_display(year, month, all_month_events,
                  start_day, net, qs, mini=False, request=None, context=None):
    """
    A function that returns an html calendar for the given
    month in the given year, with the number of events for that month
    shown on the generated calendar. Start_day is the day the calendar
    should start on (default is Monday).
    """
    # count the number of times events happen on a given day
    count = CountHandler(year, month, all_month_events).get_count()

    # sort count by start date using all_month_events (which is already sorted)
    for event in all_month_events[::-1]:
        for l in count.values():
            for item in l:
                if item[1] == event.pk:
                    l.insert(0, l.pop(l.index(item)))

    args = (year, month, count, all_month_events, start_day)
    if not mini:
        html_cal = EventCalendar(request=request, context=context, *args).formatmonth(year, month, net=net, qs=qs)
    else:
        html_cal = MiniEventCalendar(request=request, context=context, *args).formatmonth(year, month, net=net, qs=qs)

    nxt, prev = get_next_and_prev(net)
    extra_qs = ('&' + '&'.join(qs)) if qs else ''
    # inject next/prev querystring urls and make them aware of any querystrings
    # already present in the url
    html_cal = html_cal.replace(
        'class="month">\n<tr>',
        'class="month">\n<tr><th colspan="1" class="month-arrow-left">\
        <a href="?cal_prev=%d%s">&larr;</a></th>' % (prev, extra_qs)
    ).replace(
        '%d</th>' % year,
        '%d</th><th colspan="1" class="month-arrow-right">\
        <a href="?cal_next=%d%s">&rarr;</a></th>' % (year, nxt, extra_qs)
    )

    add_occurrences(all_month_events, count)

    return html_cal
A function that returns an html calendar for the given
    month in the given year, with the number of events for that month
    shown on the generated calendar. Start_day is the day the calendar
    should start on (default is Monday).