On Thu, May 04, 2006 at 12:43:23PM +0200, [EMAIL PROTECTED] wrote:
>       Is if possible to define easily a set of static variables that will be 
> available inside the templates ?

I know that you're seeking a solution for generic views, but just fyi
here's what I did for my custom views to do this:

In the view I set up a function to allow me to check for and validate
such parameters (e.g. "...sort=xyzzy").  You don't NEED to have a function
for this, but I believe that you definitely should validate these parameters.

def check_arg(request, arg, default, valids):
   result = request.GET.get(arg, default)
   if result not in valids:
      result = default
   return result


Then, in each of my views where I might have some parameter I add
something like:

   sort = check_arg(request, 'sort', 'name', ['name', 'rating'])
or
   view = check_arg(request,'view', 'top', ['top', 'all'])
or
   display = check_arg(request,'display', 'full', ['full', 'brief'])

and finally, in each of those views you need to add each "parameter"
variable (e.g. "sort" above) to the context with something like:

   c = DjangoContext(request, {
      "sort":sort,
      "view":view,
      "display":display,
      "obj_list":obj_list,
      }, None)


Then, in your template you refer to these variables just like
   {{ sort }}


Hope that helps even though it's not generic views...

-- 
Glenn Tenney

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to