Explicit declaration of keys for AttributeFields and RelationshipFields is now unnece...
[philo.git] / contrib / penfield / models.py
index c4cb49e..957c277 100644 (file)
@@ -6,7 +6,7 @@ from django.conf.urls.defaults import url, patterns
 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
 
 
@@ -130,15 +130,10 @@ class BlogView(MultiView):
                return base_patterns + entry_patterns
        
        def index_view(self, request, node=None, extra_context=None):
-               entries = self.blog.entries.all()
-               if self.entries_per_page:
-                       paginated_page = paginate(request, entries, self.entries_per_page)
-                       entries = paginated_page.object_list
-               else:
-                       paginated_page = None
+               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):
@@ -168,14 +163,11 @@ class BlogView(MultiView):
                        entries = entries.filter(date__month=month)
                if day:
                        entries = entries.filter(date__day=day)
-               if self.entries_per_page:
-                       paginated_page = paginate(request, entries, self.entries_per_page)
-                       entries = paginated_page.object_list
-               else:
-                       paginated_page = None
+               
+               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):
@@ -196,14 +188,10 @@ class BlogView(MultiView):
                if entries.count() <= 0:
                        raise Http404
                
-               if self.entries_per_page:
-                       paginated_page = paginate(request, entries, self.entries_per_page)
-                       entries = paginated_page.object_list
-               else:
-                       paginated_page = None
+               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):
@@ -230,6 +218,7 @@ class NewsletterArticle(Entity, Titled):
        full_text = models.TextField()
        
        class Meta:
+               get_latest_by = 'date'
                ordering = ['-date']
                unique_together = (('newsletter', 'slug'),)
 
@@ -240,7 +229,7 @@ register_value_model(NewsletterArticle)
 class NewsletterIssue(Entity, Titled):
        newsletter = models.ForeignKey(Newsletter, related_name='issues')
        number = models.PositiveIntegerField()
-       articles = models.ManyToManyField(NewsletterArticle)
+       articles = models.ManyToManyField(NewsletterArticle, related_name='issues')
        
        class Meta:
                ordering = ['-number']