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
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
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
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
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
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
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
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
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:
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
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
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
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
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
%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
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
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
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
18 matches
Mail list logo