Fixed a sobol bug which was causing search views to always use all available searches...
[philo.git] / contrib / penfield / models.py
index 065d033..a03bed8 100644 (file)
@@ -10,6 +10,8 @@ from django.utils.datastructures import SortedDict
 from django.utils.encoding import smart_unicode, force_unicode
 from django.utils.html import escape
 from datetime import date, datetime
 from django.utils.encoding import smart_unicode, force_unicode
 from django.utils.html import escape
 from datetime import date, datetime
+from philo.contrib.penfield.exceptions import HttpNotAcceptable
+from philo.contrib.penfield.middleware import http_not_acceptable
 from philo.contrib.penfield.validators import validate_pagination_count
 from philo.exceptions import ViewCanNotProvideSubpath
 from philo.models import Tag, Titled, Entity, MultiView, Page, register_value_model, TemplateField, Template
 from philo.contrib.penfield.validators import validate_pagination_count
 from philo.exceptions import ViewCanNotProvideSubpath
 from philo.models import Tag, Titled, Entity, MultiView, Page, register_value_model, TemplateField, Template
@@ -44,6 +46,7 @@ class FeedView(MultiView):
        feed_type = models.CharField(max_length=50, choices=FEED_CHOICES, default=ATOM)
        feed_suffix = models.CharField(max_length=255, blank=False, default="feed")
        feeds_enabled = models.BooleanField(default=True)
        feed_type = models.CharField(max_length=50, choices=FEED_CHOICES, default=ATOM)
        feed_suffix = models.CharField(max_length=255, blank=False, default="feed")
        feeds_enabled = models.BooleanField(default=True)
+       feed_length = models.PositiveIntegerField(blank=True, null=True, default=15, help_text="The maximum number of items to return for this feed. All items will be returned if this field is blank.")
        
        item_title_template = models.ForeignKey(Template, blank=True, null=True, related_name="%(app_label)s_%(class)s_title_related")
        item_description_template = models.ForeignKey(Template, blank=True, null=True, related_name="%(app_label)s_%(class)s_description_related")
        
        item_title_template = models.ForeignKey(Template, blank=True, null=True, related_name="%(app_label)s_%(class)s_title_related")
        item_description_template = models.ForeignKey(Template, blank=True, null=True, related_name="%(app_label)s_%(class)s_description_related")
@@ -62,7 +65,7 @@ class FeedView(MultiView):
                urlpatterns = patterns('')
                if self.feeds_enabled:
                        feed_reverse_name = "%s_feed" % reverse_name
                urlpatterns = patterns('')
                if self.feeds_enabled:
                        feed_reverse_name = "%s_feed" % reverse_name
-                       feed_view = self.feed_view(get_items_attr, feed_reverse_name)
+                       feed_view = http_not_acceptable(self.feed_view(get_items_attr, feed_reverse_name))
                        feed_pattern = r'%s%s%s$' % (base, (base and base[-1] != "^") and "/" or "", self.feed_suffix)
                        urlpatterns += patterns('',
                                url(feed_pattern, feed_view, name=feed_reverse_name),
                        feed_pattern = r'%s%s%s$' % (base, (base and base[-1] != "^") and "/" or "", self.feed_suffix)
                        urlpatterns += patterns('',
                                url(feed_pattern, feed_view, name=feed_reverse_name),
@@ -139,8 +142,7 @@ class FeedView(MultiView):
                                else:
                                        feed_type = None
                        if not feed_type:
                                else:
                                        feed_type = None
                        if not feed_type:
-                               # See RFC 2616
-                               return HttpResponse(status=406)
+                               raise HttpNotAcceptable
                return FEEDS[feed_type]
        
        def get_feed(self, obj, request, reverse_name):
                return FEEDS[feed_type]
        
        def get_feed(self, obj, request, reverse_name):
@@ -194,6 +196,9 @@ class FeedView(MultiView):
                except Site.DoesNotExist:
                        current_site = RequestSite(request)
                
                except Site.DoesNotExist:
                        current_site = RequestSite(request)
                
+               if self.feed_length is not None:
+                       items = items[:self.feed_length]
+               
                for item in items:
                        if title_template is not None:
                                title = title_template.render(RequestContext(request, {'obj': item}))
                for item in items:
                        if title_template is not None:
                                title = title_template.render(RequestContext(request, {'obj': item}))
@@ -383,10 +388,8 @@ class BlogView(FeedView):
        
        @property
        def urlpatterns(self):
        
        @property
        def urlpatterns(self):
-               urlpatterns = self.feed_patterns(r'^', 'get_all_entries', 'index_page', 'index')
-               
-               if self.feeds_enabled:
-                       urlpatterns += self.feed_patterns(r'^%s/(?P<tag_slugs>[-\w]+[-+/\w]*)$' % self.tag_permalink_base, 'get_entries_by_tag', 'tag_page', 'get_entries_by_tag')
+               urlpatterns = self.feed_patterns(r'^', 'get_all_entries', 'index_page', 'index') +\
+                       self.feed_patterns(r'^%s/(?P<tag_slugs>[-\w]+[-+/\w]*)$' % self.tag_permalink_base, 'get_entries_by_tag', 'tag_page', 'entries_by_tag')
                
                if self.tag_archive_page:
                        urlpatterns += patterns('',
                
                if self.tag_archive_page:
                        urlpatterns += patterns('',