thoughts/views.py @ e1000c7e0906

Fixed the feed Mint stats.
author Steve Losh <steve@stevelosh.com>
date Thu, 15 Jan 2009 19:34:16 -0500
parents 5d5a567385bb
children 4503e2493b8d
from stevelosh.thoughts.models import TextThought, LinkThought
from django.shortcuts import render_to_response
import operator

ENTRIES_PER_PAGE = 10

def list(request, page=0):
    page = int(page)
    start_index = page * ENTRIES_PER_PAGE
    end_index = start_index + ENTRIES_PER_PAGE
    total_count = TextThought.objects.count() + LinkThought.objects.count()
    
    thoughts = []
    thoughts += TextThought.objects.all().order_by('-posted')
    thoughts += LinkThought.objects.all().order_by('-posted')
    thoughts.sort(key=operator.attrgetter('posted'))
    thoughts.reverse()
    thoughts = thoughts[start_index:end_index]
    
    return render_to_response('thoughts/list.html', 
        { 'thoughts': thoughts,
          'older_page': page+1 if end_index < total_count else None,
          'newer_page': page-1 if page != 0 else None } )