Re: View decorator for common navigation elements?

2011-10-03 Thread Thomas Orozco
Maybe you can use template inheritance and have the base template access the data through, alternatively, template filters or instance methods? To make those work, you can take advantage of the existing template processors (notably the auth one). If you want to not have the topnav on a particular

Re: View decorator for common navigation elements?

2011-10-02 Thread Victor Hooi
heya, This SO post seems to suggest that data and template tags shouldn't mix... http://stackoverflow.com/questions/5046046/where-put-database-interaction-in-django-templatetags Not sure how I feel about that myself - I see the philosophical argument behind it, but I don't see another more effi

Re: View decorator for common navigation elements?

2011-10-01 Thread colinta
ter pages. But since it's a CP, it gets called on *every* page, not just those that need it. _I'd_ rather it not execute except on those pages that explicitly need that data. I played with a view-decorator pattern that had view methods returning *either* a response object or a (templa

Re: View decorator for common navigation elements?

2011-09-30 Thread Victor Hooi
heya, I do like the idea of just including a custom template tag =). Hmm, can custom template tags interact with models or query the database like that? Firstly, Is it possible, and secondly, is it considered good practice? Cheers, Victor -- You received this message because you are subscri

Re: View decorator for common navigation elements?

2011-09-30 Thread Luis Morales
wouldn't a template tag work best in a case like this? something like {% NavBar %} or {% GetNav NavName %} that way you can have your own cache code inside you template tag code, like storing the database result into memcached or redis and avoid a relational db call each page. them you you modify

Re: View decorator for common navigation elements?

2011-09-29 Thread Alex Chan
Hi Victor, I think this is a very good question. I've been considering what the best approach would be and decided on either using a decorator as you've mentioned or implementing class based views. You can create base view classes that load common data for the different types of pages. You woul

View decorator for common navigation elements?

2011-09-29 Thread Victor Hooi
Hi, We have a common navigation bar on nearly every page (view) that contains a dropdown - this dropdown is populated with items from a database table. This dropdown also has AJAX behaviour attached to it. I'm thinking I can create a decorator that will retrieve the list from the database, and

Re: View Decorator

2010-08-05 Thread Steve Holden
I don't know whether it will help, but it seems that it isn't the top-level urls.py that the error is complaining about but the one in your persons app. Presumably the top-level urlconf includes that? As to why applying a decorator should trigger the problem, I am a bit stumped. regards Steve O

Re: View Decorator

2010-08-05 Thread Dan Gentry
Steve, thanks for the guidance. I'm heading in the right direction with a better understanding of the concept, but still stymied by the urls error. Not seeing the connection between adding a decorator and having trouble with urls.py. I'll get there. Dan On Aug 4, 11:31 am, Steve Holden wrote:

Re: View Decorator

2010-08-04 Thread Steve Holden
On 8/4/2010 10:52 AM, Dan Gentry wrote: > When I attempt to use the decorator logic, the view becomes this: > > views.py > @institution_required > def list_type(request): > > inst_id=request.session.get('inst_id',None) > > queryset = RecordType.objects.filter(institution=inst_id) > r

Re: View Decorator

2010-08-04 Thread Dan Gentry
Forgot to paste in the urls. urls.py from django.conf.urls.defaults import * from django.views.generic.simple import redirect_to from views import * urlpatterns = patterns('person', url(r'^create_type/$',create_type,name='type_create'), url(r'^view_type/(?P\d+)/$',view_type,name='type_v

Re: View Decorator

2010-08-04 Thread Dan Gentry
When I attempt to use the decorator logic, the view becomes this: views.py @institution_required def list_type(request): inst_id=request.session.get('inst_id',None) queryset = RecordType.objects.filter(institution=inst_id) return object_list(request, queryset, paginate_by = 12) I do

Re: View Decorator

2010-08-04 Thread Daniel Roseman
id',None): >             path = urlquote(request.get_full_path()) >             tup = inst_url, redirect_field_name, path >             return HttpResponseRedirect('%s?%s=%s' % tup) >         return fn(request, *args, **kwargs) >     return _wrapped_view > > Would anyone like

Re: View Decorator

2010-08-04 Thread Franklin Einspruch
t_full_path()) >            tup = inst_url, redirect_field_name, path >            return HttpResponseRedirect('%s?%s=%s' % tup) >        return fn(request, *args, **kwargs) >    return _wrapped_view > > > > Would anyone like to school me on the correct way to wri

View Decorator

2010-08-04 Thread Dan Gentry
%s' % tup) return fn(request, *args, **kwargs) return _wrapped_view Would anyone like to school me on the correct way to write a view decorator? Thanks in advance. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to t

Unexpected view decorator arguments

2010-02-18 Thread Travis the Software Maven
I'm trying to write a simple view decorator that does some permission checking based on an ID passed as part of the URL and the authenticated user. Some relevant code: The decorator: def owns_item(failure_redirect_url='/'): def check_ownership(method): def _wrapper(re

Re: custom view decorator with parameter

2009-11-03 Thread bruno desthuilliers
On 2 nov, 19:39, nostradamnit wrote: > I'm trying to write a custom view decorator that takes a parameter, > and I can't for the life of me figure out how to pass the parameter. > I've tried the nested function pattern, the class with __init__ and > __call__ method

custom view decorator with parameter

2009-11-02 Thread nostradamnit
I'm trying to write a custom view decorator that takes a parameter, and I can't for the life of me figure out how to pass the parameter. I've tried the nested function pattern, the class with __init__ and __call__ methods pattern, and I always run into the same basic error. It eit