[Django] #21695: Allow blocktrans to set a context variable

37 views
Skip to first unread message

Django

unread,
Dec 28, 2013, 6:37:15 AM12/28/13
to django-...@googlegroups.com
#21695: Allow blocktrans to set a context variable
---------------------------------+--------------------
Reporter: mitar | Owner: nobody
Type: New feature | Status: new
Component: Template system | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------
Currently, we can use `{% trans "string" as var %}` to set `var` to
translated string. Nothing similar exists for `blocktrans`.

--
Ticket URL: <https://code.djangoproject.com/ticket/21695>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 2, 2014, 8:19:42 PM1/2/14
to django-...@googlegroups.com
#21695: Allow blocktrans to set a context variable
---------------------------------+--------------------------------------

Reporter: mitar | Owner: nobody
Type: New feature | Status: new
Component: Template system | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by timo):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Do any other block tags support `as var`? I'm not sure it's a good idea
(or feasible for that matter). Could you describe your use case? Do you
have interest in trying to implement it?

--
Ticket URL: <https://code.djangoproject.com/ticket/21695#comment:1>

Django

unread,
Jan 2, 2014, 9:32:01 PM1/2/14
to django-...@googlegroups.com
#21695: Allow blocktrans to set a context variable
---------------------------------+--------------------------------------

Reporter: mitar | Owner: nobody
Type: New feature | Status: new
Component: Template system | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by mitar):

Ehm, use case is string interpolation. I cannot use `{% trans "foo {{ bar
}}" as var %}`. Having only constant translated strings are vars is a bit
problematic.

I use that for setting title of the page (`{% blocktrans %}{{ username
}}'s block{% endblocktrans %}`) and I would like to set it to the context
variable so that I can reuse it around (title, heading, links ...).

Currently I am using [http://django-
missing.readthedocs.org/en/latest/templatetags.html#missing.templatetags.context_tags.setcontext
this custom tag] to achieve this. But I think this would be useful in the
tag itself. Or maybe `{% trans "foo {{ bar }}" as var %}` should be
supported at least? And `_("foo {{ bar }}")`.

--
Ticket URL: <https://code.djangoproject.com/ticket/21695#comment:2>

Django

unread,
Mar 20, 2014, 5:38:16 AM3/20/14
to django-...@googlegroups.com
#21695: Allow blocktrans to set a context variable
---------------------------------+--------------------------------------

Reporter: mitar | Owner: nobody
Type: New feature | Status: new
Component: Template system | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by bmihelac):

* cc: bmihelac@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/21695#comment:3>

Django

unread,
Mar 20, 2014, 6:54:07 AM3/20/14
to django-...@googlegroups.com
#21695: Allow blocktrans to set a context variable
---------------------------------+--------------------------------------

Reporter: mitar | Owner: nobody
Type: New feature | Status: new
Component: Template system | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by bmihelac):

Here is a link to branch that implements this feature and two simple
tests:

https://github.com/bmihelac/django-1/compare/fix-21695-allow-blocktrans-
to-set-a-context-variable?expand=1

Please note that assigning option is named `asvar` contrary to usual `as`
to avoid confusion between legacy format for using `with`.

If there is interest in merging this I will add docs and changelog and any
more tests if needed.

--
Ticket URL: <https://code.djangoproject.com/ticket/21695#comment:4>

Django

unread,
Mar 20, 2014, 5:42:30 PM3/20/14
to django-...@googlegroups.com
#21695: Allow blocktrans to set a context variable
---------------------------------+------------------------------------

Reporter: mitar | Owner: nobody
Type: New feature | Status: new
Component: Template system | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by aaugustin):

* stage: Unreviewed => Accepted


Comment:

It seems that every tag is going to gain this feature eventually...

--
Ticket URL: <https://code.djangoproject.com/ticket/21695#comment:5>

Django

unread,
Mar 20, 2014, 7:35:18 PM3/20/14
to django-...@googlegroups.com
#21695: Allow blocktrans to set a context variable
---------------------------------+------------------------------------

Reporter: mitar | Owner: nobody
Type: New feature | Status: new
Component: Template system | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by mitar):

This is why I created [http://django-
missing.readthedocs.org/en/latest/templatetags.html#missing.templatetags.context_tags.setcontext
this tag] which simply sets the context based on whatever is in there.
Then there is no need to modify all tags to be able to set context. DRY.
:-)

--
Ticket URL: <https://code.djangoproject.com/ticket/21695#comment:6>

Django

unread,
Jun 12, 2015, 8:56:46 AM6/12/15
to django-...@googlegroups.com
#21695: Allow blocktrans to set a context variable
---------------------------------+------------------------------------
Reporter: mitar | Owner: dracos
Type: New feature | Status: assigned

Component: Template system | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by dracos):

* owner: nobody => dracos
* status: new => assigned
* has_patch: 0 => 1


Comment:

I have rebased bmihelac's patch on current master, made a few changes,
added more tests and documentation, and submitted a PR at
https://github.com/django/django/pull/4854

I have a need for this at the moment - exactly the same situation as why
it's useful for trans, using the output in multiple places (most commonly,
title element and heading). It works great for trans, but if the title
happens to include a variable, I'm stuck.

--
Ticket URL: <https://code.djangoproject.com/ticket/21695#comment:7>

Django

unread,
Jun 30, 2015, 3:19:19 PM6/30/15
to django-...@googlegroups.com
#21695: Allow blocktrans to set a context variable
---------------------------------+------------------------------------
Reporter: mitar | Owner: dracos
Type: New feature | Status: assigned
Component: Template system | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/21695#comment:8>

Django

unread,
Jun 30, 2015, 4:44:58 PM6/30/15
to django-...@googlegroups.com
#21695: Allow blocktrans to set a context variable
-------------------------------------+-------------------------------------

Reporter: mitar | Owner: dracos
Type: New feature | Status: assigned
Component: Template system | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by dracos):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/21695#comment:9>

Django

unread,
Jul 1, 2015, 10:03:23 AM7/1/15
to django-...@googlegroups.com
#21695: Allow blocktrans to set a context variable
-------------------------------------+-------------------------------------
Reporter: mitar | Owner: dracos
Type: New feature | Status: closed

Component: Template system | Version: 1.6
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"839edcebb39f55acf163266f1ce1f0dc537de95b" 839edceb]:
{{{
#!CommitTicketReference repository=""
revision="839edcebb39f55acf163266f1ce1f0dc537de95b"
Fixed #21695 -- Added asvar option to blocktrans.

Thanks Bojan Mihelac for the initial patch.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21695#comment:10>

Reply all
Reply to author
Forward
0 new messages