2008/2/2, Grupo Django <[EMAIL PROTECTED]>:
>
>
> Hello, I'm having a problem using the cache system with different
> languages.
> I have used the vary_on_cookie decorator in my view:
>
> @vary_on_cookie
> @cache_page(60 * 60 * 12)
> def my_view(request):
> ...
>
>
> I've even test with:
> @vary_on_headers('Cookie')
>
> and:
>
> my_view = vary_on_headers(my_view, 'Cookie')
>
> but not working at all. the cache doesn't difference the language.
> Any idea?
>
> Thank you.
>
> I have the same problem and I have filed a bug report on Django. My
workarround has been to modify the cache decorator. You can do it yourself
patching Django source o by application basis, just write this code in on of
the __init__.py files on one of the applications. You should need to add the
missing imports.
def _generate_cache_key_i18n(request, headerlist, key_prefix):
"""Returns a cache key from the headers given in the header list.
This function overrides the one that django provides in orde to consider
the page language"""
ctx = md5.new()
lang = translation.get_language()
for header in headerlist:
value = request.META.get(header, None)
if value is not None:
ctx.update(value)
return 'views.decorators.cache.cache_page.%s.%s.%s.%s' % (
key_prefix, iri_to_uri(request.path), ctx.hexdigest(),lang)
cache._generate_cache_key=_generate_cache_key_i18n
Hope it helps!
--
Antoni Aloy López
Blog: http://www.trespams.com
Site: http://apls.net
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---