From 5b2c404d2955599bb50635b05d9191cb4bd6e34d Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Fri, 30 Dec 2011 02:19:39 +0100 Subject: Improve ListView for news --- sublab_project/news/templates/news/news_list.html | 8 ++++++++ sublab_project/news/urls.py | 5 +++-- sublab_project/news/views.py | 12 ++++++++++++ sublab_project/static/css/sublab.css | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) (limited to 'sublab_project') diff --git a/sublab_project/news/templates/news/news_list.html b/sublab_project/news/templates/news/news_list.html index 6330ffb..ea46320 100644 --- a/sublab_project/news/templates/news/news_list.html +++ b/sublab_project/news/templates/news/news_list.html @@ -8,4 +8,12 @@

{{ post.content_html|safe }}

{% endfor %} + {% if is_paginated %} +

+ {% for page in paginator.page_range %} + {{ page }} + {% endfor %} +

+ {% endif %} + {% endblock content %} diff --git a/sublab_project/news/urls.py b/sublab_project/news/urls.py index c26d12d..fe682ad 100644 --- a/sublab_project/news/urls.py +++ b/sublab_project/news/urls.py @@ -1,9 +1,10 @@ from django.conf.urls.defaults import patterns, include, url -from django.views.generic import ListView, DetailView +from django.views.generic import DetailView from news.models import News +from news.views import NewsListView urlpatterns = patterns('', - url(r'^$', ListView.as_view(model=News, paginate_by=8), name='news_list'), + url(r'^$', NewsListView.as_view(), name='news_list'), url(r'^news/(?P[-\w]+)/$', DetailView.as_view(model=News), name='news_detail'), ) diff --git a/sublab_project/news/views.py b/sublab_project/news/views.py index 60f00ef..ff62be5 100644 --- a/sublab_project/news/views.py +++ b/sublab_project/news/views.py @@ -1 +1,13 @@ # Create your views here. +from django.views.generic import ListView +from django.core.paginator import Paginator + +from news.models import News + +class NewsListView(ListView): + model = News + paginate_by = 8 + + def get_paginator(self, queryset, per_page, **kwargs): + kwargs['orphans'] = 3 + return Paginator(queryset, per_page, **kwargs) diff --git a/sublab_project/static/css/sublab.css b/sublab_project/static/css/sublab.css index 6a974f6..6c75236 100644 --- a/sublab_project/static/css/sublab.css +++ b/sublab_project/static/css/sublab.css @@ -252,7 +252,7 @@ p.header { p.news_date { color: #ddd; - margin-bottom: -20px; + margin-bottom: -17px; margin-left: 10px; font-size: 10px; } -- cgit v1.2.1