def event_list(request, year=None, month=None, day=None, calendar_slug=None, page=1):
    """
    Shows a list of upcoming events for either a specific calendar or no 
    calendar at all.
    """
    try:
        page = int(page)
        if year:
            year = int(year)
        if month:
            month = int(month)
        if day:
            day = int(day)
    except __HOLE__:
        raise Http404
    
    calendar = None
    events = Event.not_past.all()
    if calendar_slug:
        calendar = get_object_or_404(Calendar, slug=calendar_slug)
        events = events.filter(calendars=calendar)
    
    if not year:
        events = events
        page_name = "Upcoming events"
    elif not month:
        events = events.filter(Q(start__year=year) | Q(end__year=year))
        page_name = "Events in %s" % year
    elif not day:
        events = events.filter(Q(start__year=year, start__month=month) | Q(end__year=year, end__month=month))
        page_name = "Events in %s" % date(year, month, 1).strftime("%B %Y")
    else:
        events = events.filter(Q(start__year=year, start__month=month, start__day=day) | Q(end__year=year, end__month=month, end__day=day))
        #ymd = datetime.date(year, month, day)
        #events = events.filter(Q(start__gte=ymd) & Q(end__lte=ymd))
        page_name = "Events on %s" % date(year, month, day).strftime("%B %d, %Y")
    
    if calendar:
        page_name += " from %s" % calendar
    
    paginator = Paginator(events, 10)
    
    try:
        event_page = paginator.page(page)
    except (EmptyPage, InvalidPage):
        raise Http404
    
    page = {
        'calendar': calendar,
        'calendar_slug': calendar_slug,
        'event_page': event_page,
        'page_name': page_name
    }
    
    return render_to_response('events/event_list.html', page, context_instance=RequestContext(request))
dataset/ETHPy150Open albatrossandco/brubeck_cms/brubeck/events/views.py/event_list