Author: russellm
Date: 2011-01-13 08:54:49 -0600 (Thu, 13 Jan 2011)
New Revision: 15190

Added:
   
django/branches/releases/1.2.X/tests/regressiontests/comment_tests/tests/feed_tests.py
Modified:
   django/branches/releases/1.2.X/django/contrib/syndication/views.py
   
django/branches/releases/1.2.X/tests/regressiontests/comment_tests/tests/__init__.py
   django/branches/releases/1.2.X/tests/regressiontests/comment_tests/urls.py
Log:
[1.2.X] Fixed #14176 -- Added forwards compatibility to the legacy syndication 
feed view. This allows class-based feeds to be deployed using the old-style 
feed view, as long as the feed requires no arguments (i.e., get_object returns 
None). Thanks to psychcf for the report, cwhaines for the investigation, and 
Andrew Godwin for the assist.

Backport of r15189 from trunk.

Modified: django/branches/releases/1.2.X/django/contrib/syndication/views.py
===================================================================
--- django/branches/releases/1.2.X/django/contrib/syndication/views.py  
2011-01-13 14:51:34 UTC (rev 15189)
+++ django/branches/releases/1.2.X/django/contrib/syndication/views.py  
2011-01-13 14:54:49 UTC (rev 15190)
@@ -188,6 +188,7 @@
 
 def feed(request, url, feed_dict=None):
     """Provided for backwards compatibility."""
+    from django.contrib.syndication.feeds import Feed as LegacyFeed
     import warnings
     warnings.warn('The syndication feed() view is deprecated. Please use the '
                   'new class based view API.',
@@ -206,6 +207,18 @@
     except KeyError:
         raise Http404("Slug %r isn't registered." % slug)
 
+    # Backwards compatibility within the backwards compatibility;
+    # Feeds can be updated to be class-based, but still be deployed
+    # using the legacy feed view. This only works if the feed takes
+    # no arguments (i.e., get_object returns None). Refs #14176.
+    if not issubclass(f, LegacyFeed):
+        instance = f()
+        instance.feed_url = getattr(f, 'feed_url', None) or request.path
+        instance.title_template = f.title_template or ('feeds/%s_title.html' % 
slug)
+        instance.description_template = f.description_template or 
('feeds/%s_description.html' % slug)
+
+        return instance(request)
+
     try:
         feedgen = f(slug, request).get_feed(param)
     except FeedDoesNotExist:

Modified: 
django/branches/releases/1.2.X/tests/regressiontests/comment_tests/tests/__init__.py
===================================================================
--- 
django/branches/releases/1.2.X/tests/regressiontests/comment_tests/tests/__init__.py
        2011-01-13 14:51:34 UTC (rev 15189)
+++ 
django/branches/releases/1.2.X/tests/regressiontests/comment_tests/tests/__init__.py
        2011-01-13 14:54:49 UTC (rev 15190)
@@ -81,6 +81,7 @@
         return d
 
 from regressiontests.comment_tests.tests.app_api_tests import *
+from regressiontests.comment_tests.tests.feed_tests import *
 from regressiontests.comment_tests.tests.model_tests import *
 from regressiontests.comment_tests.tests.comment_form_tests import *
 from regressiontests.comment_tests.tests.templatetag_tests import *

Added: 
django/branches/releases/1.2.X/tests/regressiontests/comment_tests/tests/feed_tests.py
===================================================================
--- 
django/branches/releases/1.2.X/tests/regressiontests/comment_tests/tests/feed_tests.py
                              (rev 0)
+++ 
django/branches/releases/1.2.X/tests/regressiontests/comment_tests/tests/feed_tests.py
      2011-01-13 14:54:49 UTC (rev 15190)
@@ -0,0 +1,33 @@
+import warnings
+
+from django.test.utils import get_warnings_state, restore_warnings_state
+
+from regressiontests.comment_tests.tests import CommentTestCase
+
+
+class CommentFeedTests(CommentTestCase):
+    urls = 'regressiontests.comment_tests.urls'
+    feed_url = '/rss/comments/'
+
+    def test_feed(self):
+        response = self.client.get(self.feed_url)
+        self.assertEquals(response.status_code, 200)
+        self.assertEquals(response['Content-Type'], 'application/rss+xml')
+        self.assertContains(response, '<rss 
xmlns:atom="http://www.w3.org/2005/Atom"; version="2.0">')
+        self.assertContains(response, '<title>example.com comments</title>')
+        self.assertContains(response, '<link>http://example.com/</link>')
+        self.assertContains(response, '</rss>')
+
+
+class LegacyCommentFeedTests(CommentFeedTests):
+    feed_url = '/rss/legacy/comments/'
+
+    def setUp(self):
+        self._warnings_state = get_warnings_state()
+        warnings.filterwarnings("ignore", category=DeprecationWarning,
+                                module='django.contrib.syndication.views')
+        warnings.filterwarnings("ignore", category=DeprecationWarning,
+                                module='django.contrib.syndication.feeds')
+
+    def tearDown(self):
+        restore_warnings_state(self._warnings_state)

Modified: 
django/branches/releases/1.2.X/tests/regressiontests/comment_tests/urls.py
===================================================================
--- django/branches/releases/1.2.X/tests/regressiontests/comment_tests/urls.py  
2011-01-13 14:51:34 UTC (rev 15189)
+++ django/branches/releases/1.2.X/tests/regressiontests/comment_tests/urls.py  
2011-01-13 14:54:49 UTC (rev 15190)
@@ -1,5 +1,10 @@
 from django.conf.urls.defaults import *
+from django.contrib.comments.feeds import LatestCommentFeed
 
+feeds = {
+     'comments': LatestCommentFeed,
+}
+
 urlpatterns = patterns('regressiontests.comment_tests.custom_comments.views',
     url(r'^post/$',          'custom_submit_comment'),
     url(r'^flag/(\d+)/$',    'custom_flag_comment'),
@@ -7,3 +12,7 @@
     url(r'^approve/(\d+)/$', 'custom_approve_comment'),
 )
 
+urlpatterns += patterns('',
+    (r'^rss/legacy/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', 
{'feed_dict': feeds}),
+    (r'^rss/comments/$', LatestCommentFeed()),
+)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to