Adjusted feedmultiviewmixin to allow more customization of objects being added to...
authorStephen Burrows <stephen.r.burrows@gmail.com>
Thu, 23 Sep 2010 15:10:47 +0000 (11:10 -0400)
committerStephen Burrows <stephen.r.burrows@gmail.com>
Thu, 23 Sep 2010 16:31:58 +0000 (12:31 -0400)
contrib/penfield/models.py
contrib/penfield/utils.py

index 62d8d2a..3cbff52 100644 (file)
@@ -201,8 +201,15 @@ class BlogView(MultiView, FeedMultiViewMixin):
                
                return entries, context
        
-       def get_obj_description(self, obj):
-               return obj.excerpt
+       def add_item(self, feed, obj, kwargs=None):
+               defaults = {
+                       'title': obj.title,
+                       'description': obj.excerpt or obj.content,
+                       'author_name': obj.author.get_full_name(),
+                       'pubdate': obj.date
+               }
+               defaults.update(kwargs or {})
+               super(BlogView, self).add_item(feed, obj, defaults)
        
        def entry_view(self, request, slug, year=None, month=None, day=None, node=None, extra_context=None):
                entries = self.blog.entries.all()
@@ -408,5 +415,13 @@ class NewsletterView(MultiView, FeedMultiViewMixin):
                context.update({'newsletter': self.newsletter})
                return self.issue_archive_page.render_to_response(node, request, extra_context=context)
        
-       def get_obj_description(self, obj):
-               return obj.lede or obj.full_text
\ No newline at end of file
+       def add_item(self, feed, obj, kwargs=None):
+               defaults = {
+                       'title': obj.title,
+                       'author_name': ', '.join(obj.authors),
+                       'pubdate': obj.date,
+                       'description': obj.lede or obj.full_text,
+                       'categories': [tag.name for tag in obj.tags.all()]
+               }
+               defaults.update(kwargs or {})
+               super(NewsletterView, self).add_item(feed, obj, defaults)
\ No newline at end of file
index 1a53cfe..591ac04 100644 (file)
@@ -1,5 +1,6 @@
 from django.utils.feedgenerator import Atom1Feed, Rss201rev2Feed
 from django.conf.urls.defaults import url, patterns
+from django.contrib.sites.models import Site
 from django.core.urlresolvers import reverse
 from django.http import HttpResponse
 from philo.utils import paginate
@@ -52,9 +53,13 @@ class FeedMultiViewMixin(object):
                                feed_type = 'atom'
                        
                        feed = self.get_feed(feed_type, request, node, kwargs, reverse_name)
+                       current_site = Site.objects.get_current()
                        
                        for obj in objects:
-                               feed.add_item(obj.title, '/%s/%s/' % (node.get_absolute_url().strip('/'), self.get_subpath(obj).strip('/')), description=self.get_obj_description(obj))
+                               kwargs = {
+                                       'link': 'http://%s/%s/%s/' % (current_site.domain, node.get_absolute_url().strip('/'), self.get_subpath(obj).strip('/'))
+                               }
+                               self.add_item(feed, obj, kwargs=kwargs)
        
                        response = HttpResponse(mimetype=feed.mime_type)
                        feed.write(response, 'utf-8')
@@ -64,7 +69,8 @@ class FeedMultiViewMixin(object):
        
        def get_feed(self, feed_type, request, node, kwargs, reverse_name):
                title = self.feed_title
-               link = '/%s/%s/' % (node.get_absolute_url().strip('/'), reverse(reverse_name, urlconf=self, kwargs=kwargs).strip('/'))
+               current_site = Site.objects.get_current()
+               link = 'http://%s/%s/%s/' % (current_site.domain, node.get_absolute_url().strip('/'), reverse(reverse_name, urlconf=self, kwargs=kwargs).strip('/'))
                description = self.feed_description
                if feed_type == 'rss':
                        return self.rss_feed(title, link, description)
@@ -79,5 +85,6 @@ class FeedMultiViewMixin(object):
                )
                return urlpatterns
        
-       def get_obj_description(self, obj):
-               raise NotImplementedError
\ No newline at end of file
+       def add_item(self, feed, obj, kwargs=None):
+               defaults = kwargs or {}
+               feed.add_item(**defaults)
\ No newline at end of file