X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/aa974af0f752e8b3e23337764e0bbd5e140217d8..e06925fc9be46b2c07863440212600b2e7ecb597:/contrib/penfield/models.py?ds=inline diff --git a/contrib/penfield/models.py b/contrib/penfield/models.py index 94ad5c3..bf5178e 100644 --- a/contrib/penfield/models.py +++ b/contrib/penfield/models.py @@ -3,11 +3,10 @@ from django.conf import settings from philo.models import Tag, Titled, Entity, MultiView, Page, register_value_model from philo.exceptions import ViewCanNotProvideSubpath from django.conf.urls.defaults import url, patterns -from django.core.paginator import EmptyPage from django.core.urlresolvers import reverse from django.http import Http404, HttpResponse from datetime import datetime -from philo.contrib.penfield.utils import paginate +from philo.utils import paginate from philo.contrib.penfield.validators import validate_pagination_count @@ -27,7 +26,7 @@ register_value_model(Blog) class BlogEntry(Entity, Titled): - blog = models.ForeignKey(Blog, related_name='entries') + blog = models.ForeignKey(Blog, related_name='entries', blank=True, null=True) author = models.ForeignKey(getattr(settings, 'PHILO_PERSON_MODULE', 'auth.User'), related_name='blogentries') date = models.DateTimeField(default=datetime.now) content = models.TextField() @@ -130,17 +129,11 @@ class BlogView(MultiView): ) return base_patterns + entry_patterns - def paginate(self, objects, page_number): - try: - return paginate(objects, self.entries_per_page, page_number) - except EmptyPage: - raise Http404 - def index_view(self, request, node=None, extra_context=None): - paginated_page, entries = self.paginate(self.blog.entries.all(), request.GET.get('page', 1)) + paginator, page, entries = paginate(self.blog.entries.all(), self.entries_per_page, request.GET.get('page', 1)) context = {} context.update(extra_context or {}) - context.update({'blog': self.blog, 'entries': entries, 'paginated_page': paginated_page}) + context.update({'blog': self.blog, 'paginator': paginator, 'paginated_page': page, 'entries': entries}) return self.index_page.render_to_response(node, request, extra_context=context) def entry_view(self, request, slug, year=None, month=None, day=None, node=None, extra_context=None): @@ -171,10 +164,10 @@ class BlogView(MultiView): if day: entries = entries.filter(date__day=day) - paginated_page, entries = self.paginate(entries, request.GET.get('page', 1)) + paginator, page, entries = paginate(entries, self.entries_per_page, request.GET.get('page', 1)) context = {} context.update(extra_context or {}) - context.update({'blog': self.blog, 'year': year, 'month': month, 'day': day, 'entries': entries, 'paginated_page': paginated_page}) + context.update({'blog': self.blog, 'year': year, 'month': month, 'day': day, 'paginator': paginator, 'paginated_page': page, 'entries': entries}) return self.entry_archive_page.render_to_response(node, request, extra_context=context) def tag_view(self, request, tag_slugs, node=None, extra_context=None): @@ -195,10 +188,10 @@ class BlogView(MultiView): if entries.count() <= 0: raise Http404 - paginated_page, entries = self.paginate(entries, request.GET.get('page', 1)) + paginator, page, entries = paginate(entries, self.entries_per_page, request.GET.get('page', 1)) context = {} context.update(extra_context or {}) - context.update({'blog': self.blog, 'tags': tags, 'entries': entries, 'paginated_page': paginated_page}) + context.update({'blog': self.blog, 'tags': tags, 'paginator': paginator, 'paginated_page': page, 'entries': entries}) return self.tag_page.render_to_response(node, request, extra_context=context) def tag_archive_view(self, request, node=None, extra_context=None):