Code

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#13014 closed (fixed)

Document using LANGUAGE_CODE with the cache template tag

Reported by: yml Owned by:
Component: Documentation Version: master
Severity: Keywords:
Cc: fgutierrez@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Issue:
The cache templatetag does not take into account the Language (i18n).

Solution:
The cache templatetag[1] should be updated to use the new _i18n_cache_key_suffix[2]. Given context in which this code is evaluated the request is not required :
cache_key = _i18n_cache_key_suffix(request=None, cache_key):

This is in fact a follow up this ticket : #5691 which reported a similar issue with the cache middleware. the infrastructure for this change has been added in r12624 and r12546

[1]http://code.djangoproject.com/browser/django/trunk/django/templatetags/cache.py#L28
[2] http://code.djangoproject.com/browser/django/trunk/django/utils/cache.py#L137

Attachments (2)

13014.diff (5.8 KB) - added by SmileyChris 4 years ago.
13014_doc.diff (1.4 KB) - added by anonymous 4 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 4 years ago by SmileyChris

  • milestone set to 1.2
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

I think that it makes sense to achieve parity between decorator and template tag caching before 1.2

Changed 4 years ago by SmileyChris

comment:2 Changed 4 years ago by SmileyChris

  • Component changed from Uncategorized to Template system
  • Has patch set
  • Owner changed from nobody to SmileyChris
  • Status changed from new to assigned
  • Summary changed from Cache templatetag and i18n to Cache templatetag is not locale aware
  • Version changed from 1.1 to SVN

comment:3 Changed 4 years ago by SmileyChris

  • Needs documentation set
  • Triage Stage changed from Accepted to Design decision needed

Yann brought up the point that maybe a user should be told to just do this manually by passing the locale as a cache argument.

Some short docs should be added to explain either the difference in behaviour or the parity.

comment:4 Changed 4 years ago by jezdez

IMO, we should simply mention in the docs that this works well:

{% cache 60 welcome request.LANGUAGE_CODE %}
    {% trans "Welcome to zombo.com" %}
{% endcache %}

It's not exactly the same as the cache/middleware approach, but that's true for fragment caching anyway -- it's built to be flexible in contrast to out of the box caching of the middleware/decorator mechanism.

comment:5 Changed 4 years ago by SmileyChris

You'd also want to mention that they'd have to pass request in the context, or use the request context processor & a requestcontext.

But sure, if that's enough then someone can just write some nice docs :)

comment:6 Changed 4 years ago by jacob

Doesn't the i18n context processor put LANGUAGE_CODEin the context? Seems to me that's the right approach -- "explicit is better than implicit". Any reason we should do anything more than a doc addition?

comment:7 Changed 4 years ago by SmileyChris

  • Component changed from Template system to Documentation
  • Has patch unset
  • Needs documentation unset
  • Owner SmileyChris deleted
  • Status changed from assigned to new
  • Summary changed from Cache templatetag is not locale aware to Document using LANGUAGE_CODE with the cache template tag
  • Triage Stage changed from Design decision needed to Accepted

Good point, Jacob. Definitely just a documentation job.

comment:8 Changed 4 years ago by anonymous

  • Has patch set

comment:9 Changed 4 years ago by SmileyChris

  • Has patch unset

The patch doesn't address the decision made to just document this behavior, Mr Anonymous.

Changed 4 years ago by anonymous

comment:10 Changed 4 years ago by fgutierrez@…

  • Cc fgutierrez@… added
  • Has patch set

Just added a doc patch. Hope it is correct.

comment:11 Changed 4 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

(In [12787]) Fixed #13014 - Added section about how to use the language code with fragement caching. Thanks for the initial patch, fgutierrez.

comment:12 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.