Ticket #4720: syndication-500-2.diff
File syndication-500-2.diff, 3.4 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.contrib.syndication import feeds 5 from django.core.exceptions import ObjectDoesNotExist 6 from django.http import HttpRequest 7 8 class SyndicationFeedTest(TestCase): 9 def test_send_empty_urls_to_get_object(self): 10 """ 11 tests that get_object gets a chance to handle empty urls 12 """ 13 _test_log = [] 14 class FeedStub(feeds.Feed): 15 def get_object(self, bits): 16 _test_log.append(bits) 17 raise ObjectDoesNotExist 18 19 f = FeedStub('foo', HttpRequest()) 20 self.assertRaises( 21 feeds.FeedDoesNotExist, 22 f.get_feed, 23 '') 24 self.assertEquals(_test_log, [[]]) -
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