Code

Opened 5 months ago

Closed 2 months ago

#21417 closed Bug (fixed)

use TEMPLATE_STRING_IF_INVALID format string in blocktrans

Reported by: keturn Owned by: Claude Paroz <claude@…>
Component: Template system Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

ticket:19915 makes it so that TEMPLATE_STRING_IF_INVALID may show when template strings fail inside blocktrans blocks. It doesn't, however, treat that as a format string in the way that FilterExpression.resolve does (as is described in the documentation).

Attachments (0)

Change History (5)

comment:1 Changed 5 months ago by chrismedrela

  • Component changed from Uncategorized to Template system
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

To reproduce:

  • set TEMPLATE_STRING_IF_INVALID = "Invalid(%s)"
  • run python manage.py shell and type:
from django.template import Template, Context
t = Template("""{% load i18n %}
    Outside: {{ missing }}
    {% blocktrans %}Inside: {{ missing }}{% endblocktrans %}""")
print(t.render(Context()))
>>>    Outside: Invalid(missing)
>>>    Inside: Invalid(%s)

Missing variables in blocktrans tag are handled here: https://github.com/django/django/blob/326539f6a4936cda031b4a5f7caad788569f3329/django/templatetags/i18n.py#L152. It should work the same like FilterExpression.resolve.

comment:2 Changed 5 months ago by claudep

  • Owner changed from nobody to claudep
  • Status changed from new to assigned

comment:3 Changed 5 months ago by claudep

  • Has patch set
  • Owner claudep deleted
  • Status changed from assigned to new

comment:4 Changed 2 months ago by timo

  • Triage Stage changed from Accepted to Ready for checkin

comment:5 Changed 2 months ago by Claude Paroz <claude@…>

  • Owner set to Claude Paroz <claude@…>
  • Resolution set to fixed
  • Status changed from new to closed

In 02add43568b694ef25afeae474b5b1da883826c6:

Fixed #21417 -- Expanded TEMPLATE_STRING_IF_INVALID in blocktrans

Thanks keturn for the reporti, Chris Medrela for details and
Tim Graham for the review.
Refs #19915.

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.