Ticket #4720: syndication-500-2-alt.diff
File syndication-500-2-alt.diff, 4.2 KB (added by , 17 years ago) |
---|
-
django/contrib/syndication/feeds.py
55 55 return attr() 56 56 return attr 57 57 58 def get_feed(self, url=None): 58 def get_object(self, bits): 59 return None 60 61 def get_feed(self, url=""): 59 62 """ 60 63 Returns a feedgenerator.DefaultFeed object, fully populated, for 61 64 this feed. Raises FeedDoesNotExist for invalid parameters. 62 65 """ 63 if url: 64 try: 65 obj = self.get_object(url.split('/')) 66 except (AttributeError, ObjectDoesNotExist): 67 raise FeedDoesNotExist 68 else: 69 obj = None 66 try: 67 obj = self.get_object([bit for bit in url.split('/') if bit]) 68 except (AttributeError, ObjectDoesNotExist): 69 raise FeedDoesNotExist 70 70 71 71 if Site._meta.installed: 72 72 current_site = Site.objects.get_current() -
tests/regressiontests/syndication/tests.py
1 # -*- coding: utf-8 -*- 2 3 from django.test import TestCase 4 from django.test.client import Client 5 6 class SyndicationFeedTest(TestCase): 7 def test_complex_base_url(self): 8 """ 9 tests that that the base url for a complex feed doesn't raise a 500 10 exception 11 """ 12 c = Client() 13 response = c.get('/syndication/feeds/complex/') 14 self.assertEquals(response.status_code, 404) -
tests/regressiontests/syndication/urls.py
1 from django.conf.urls.defaults import patterns 2 from django.core.exceptions import ObjectDoesNotExist 3 from django.contrib.syndication import feeds 4 5 6 class ComplexFeed(feeds.Feed): 7 def get_object(self, bits): 8 if len(bits) != 1: 9 raise ObjectDoesNotExist 10 return None 11 12 13 urlpatterns = patterns('', 14 (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', { 15 'feed_dict': dict( 16 complex = ComplexFeed, 17 )}), 18 ) -
docs/syndication_feeds.txt
243 243 raises ``Beat.DoesNotExist`` on failure, and ``Beat.DoesNotExist`` is a 244 244 subclass of ``ObjectDoesNotExist``. Raising ``ObjectDoesNotExist`` in 245 245 ``get_object()`` tells Django to produce a 404 error for that request. 246 247 **New in Django development version:** Note that get_object also gets a 248 chance to handle the ``/rss/beats/`` url. In this case bits will be 249 an empty list. In our example, since ``len(bits) != 1`` an 250 ``ObjectDoesNotExist`` exception will be raised, so ``/rss/beats/`` will 251 generate a 404 page. But you can handle this case however you like. For 252 example you could generate a combined feed for all beats. 253 246 254 * To generate the feed's ``<title>``, ``<link>`` and ``<description>``, 247 255 Django uses the ``title()``, ``link()`` and ``description()`` methods. In 248 256 the previous example, they were simple string class attributes, but this -
tests/urls.py
14 14 15 15 # django built-in views 16 16 (r'^views/', include('regressiontests.views.urls')), 17 18 # test urlconf for syndication tests 19 (r'^syndication/', include('regressiontests.syndication.urls')), 17 20 )