Changeset - 00995bff4d0c
[Not reviewed]
0 1 0
Bradley Kuhn (bkuhn) - 7 years ago 2015-03-04 20:22:33
bkuhn@ebb.org
Fix cut and paste error from documentation

This is trying to build a pagination of a news queryset.

HT tmarble for pointing this out.
1 file changed with 6 insertions and 6 deletions:
0 comments (0 inline, 0 general)
www/conservancy/apps/news/views.py
Show inline comments
...
 
@@ -19,25 +19,25 @@ class NewsListView(ListView):
 
        return context
 
                                    
 
def listing(request):
 
    news = PressRelease.objects.all()
 
    news_queryset = PressRelease.objects.all()
 

	
 
#    if (not kwargs.has_key('allow_future')) or not kwargs['allow_future']:
 
    news = news.filter(**{'%s__lte' % kwargs['date_field']:
 
    news_queryset = news_queryset.filter(**{'%s__lte' % kwargs['date_field']:
 
                          datetime.now()})
 

	
 
    date_list = news.dates(kwargs['date_field'], 'year')
 

	
 
    paginator = Paginator(news, 6) # Show 6 news items per page
 
    paginator = Paginator(news_queryset, 6) # Show 6 news items per page
 

	
 
    page = request.GET.get('page')
 
    try:
 
        contacts = paginator.page(page)
 
        news = paginator.page(page)
 
    except PageNotAnInteger:
 
        # If page is not an integer, deliver first page.
 
        contacts = paginator.page(1)
 
        news = paginator.page(1)
 
    except EmptyPage:
 
        # If page is out of range (e.g. 9999), deliver last page of results.
 
        contacts = paginator.page(paginator.num_pages)
 
        news = paginator.page(paginator.num_pages)
 

	
 
    return render_to_response('pressrelease_list.html', {"news": news, "date_list" : date_list})
 

	
0 comments (0 inline, 0 general)