@cache_page(60 * 30)
def archive(request, slug=None, year=None, month=None, day=None, page=1):
    if year:
        year = int(year)
    if month:
        month = int(month)
    if day:
        day = int(day)
    
    # The URL pattern for the year-only archive's first page matches the old
    # standard URL for individual episodes (based on episode ID). If the view
    # gets passed a year that makes no sense, assume it's an episode ID and
    # redirect to the detail view.
    if year and year < 2008:  # The year we first had comics online at all.
        episode = ComicEpisode.objects.get(id=year)
        return HttpResponsePermanentRedirect('/comics/%s/%s/%s/%s/%s/' % (episode.strip.slug, episode.pub_date.year, episode.pub_date.month, episode.pub_date.day, episode.id))
    
    strip = ComicStrip.objects.filter(slug=slug)[0]
    images = ComicEpisode.objects.filter(strip__slug=slug)
    
    if not year:
        images = images
        archive_name = "%s" % strip.title
    elif not month:
        images = images.filter(pub_date__year=year)
        archive_name = "%s episodes from %s" % (strip.title, year)
    elif not day:
        images = images.filter(pub_date__year=year, pub_date__month=month)
        archive_name = "%s episodes from %s" % (strip.title, date(year, month, 1).strftime("%B %Y"))
    else:
        images = images.filter(pub_date=date(year, month, day))
        archive_name = "%s episodes from %s" % (strip.title, date(year, month, day).strftime("%B %d, %Y"))
    
    paginator = Paginator(images, 10)
    
    try:
        archive_page = paginator.page(page)
    except (EmptyPage, InvalidPage):
        raise Http404
    
    page = {
        'archive_name': archive_name,
        'archive_page': archive_page
    }
    
    return render_to_response('core/archive.html', page, context_instance=RequestContext(request))
Show a paginated, optionally date-based archive of comic episodes.
dataset/ETHPy150Open albatrossandco/brubeck_cms/brubeck/comics/views.py/archive