This is a general question. I think it would be useful to be able to
use template variables as filters. Consider the following: I need to
display dates according to a user's timezone. My options are to create
these translated dates in the view code (assign them to model
instances or create a new data structure, both of which take a few
lines of code, and neither of which I really like), or have a general
datetime translator template filter which takes the timezone as an
argument. IE:
{{ object.date|tz_translate:request.timezone|date:"d/m/y H:i" }}
However, if I could use a template variable as a filter, I think it
would be cleaner and easier for template authors too:
c = RequestContext(request, {
'objects': SomeModel.objects.all(),
'tz_translate': functools.partial(tz_translate, request.timezone),
})
Then in the template:
{{ objects.date|tz_translate|date:"d/m/y H:i" }}
It's easier no?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---