No insights? I'm still plugging away at it but it's not working for some reason.
On Apr 18, 11:15 pm, Streamweaver <streamwea...@gmail.com> wrote: > I'm having trouble developing a feed decorator. I feel like the > decorator I've come up with should work but isn't and I wanted to ask > if someone can spot my error. > > I have two view methods one that returns a normal HTML view and > another that returns an rss feed of the same data. They both take the > same arguments. I am trying to create a decorator that checks the > request objects for a format variable in the querystring and returns > the feed view instead of the html view. Like so: > > my_view_feed > > @format_req('rss', my_view_feed) > my_view > > So a request for '/site/foo/bar' would return 'my_view' but '/site/foo/ > bar?format=rss' would return 'my_view_feed' > > This is the decorator method I created and I would think would work > but I'm still struggling a bit with decorators with arguments, even > after reading Bruce's excellent post (http://www.artima.com/weblogs/ > viewpost.jsp?thread=240845) > > def format_req(fmt, new_fn): > > def _decorator(view_fn): > > def _wraped(request, *args, **kwargs): > req_format = request.GET.get('format', None) > if req_format == fmt: > return new_fn(request, *args, **kwargs) > # Default to returning the original method > return view_fn(request, *args, **kwargs) > > return _wraped > > return _decorator > > I would have though a request with 'format=rss' would return new_view > but no matter what I do I always get view_fn returned. > > Can anyone point me toward where I'm going wrong. As usual I'll post > the final code once I get it working for reference. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.