On Mar 7, 10:48 pm, Brian Neal <[email protected]> wrote:
> Before the Django 1.2 beta and the class-based Feed views, I was doing
> this to cache my RSS feeds:
>
> urls.py:
> from django.contrib.syndication.views import feed as syndication_feed
> from django.views.decorators.cache import cache_page
>
> urlpatterns = patterns('',
> url(r'^feeds/(?P<url>.*)/$',
> cache_page(syndication_feed, 60 * 15),
> {'feed_dict': feeds},
> 'feeds-news'),
>
> Is there a way to do something similar to this now with the 1.2 Feed
> classes? This doesn't seem to work when the argument to cache_page is
> now an instance of a Feed object (I get an AttributeError; my feed
> class has no attribute '__name__'):
>
> url(r'^feeds/news/$',
> cache_page(LatestNewsFeed(), 60 * 15),
> name='feeds-news'),
>
Well, I'm not sure if it was the intent to break this use case. Any
thoughts?
But I found a work around after talking to Rob Hudson. You can
override the syndication base class __call__ function and decorate
that. But another new thing here is you have to use the new
method_decorator [1]:
class MyFeed(Feed):
@method_decorator(cache_page(60 * 60))
def __call__(self, request, *args, **kwargs):
return super(MyFeed, self).__call__(request, *args, **kwargs)
Again, I'm not sure if this was supposed to break like this, as there
are certain advantages to do this in the URLconf, as noted in the docs
for cache_page.
BN
[1]
http://docs.djangoproject.com/en/dev/releases/1.2/#user-passes-test-login-required-and-permission-required
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.