Seems very odd how you're trying to implement this. Unless your pseudocode has me confused. Can you give us the view functions too? Seems like you're trying to use a decorator function on two views. Why don't you just bail on the decorator, and just check for request.GET.get('format') == 'rss', and if true kick out the rss template instead of the html one.
On Apr 26, 7:05 am, Nuno Maltez <nuno.li...@gmail.com> wrote: > Have you tried invoking the pyhton debugger inside _wrapped to find > out the actual values of req_format and fmt and what's happening in > there? > > Nuno > > > > > > On Mon, Apr 19, 2010 at 4:15 AM, 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 > 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.