[Django] #32429: Configurable "always available" InclusionNode context variables

14 views
Skip to first unread message

Django

unread,
Feb 7, 2021, 5:03:36 PM2/7/21
to django-...@googlegroups.com
#32429: Configurable "always available" InclusionNode context variables
-------------------------------------+-------------------------------------
Reporter: Michael | Owner: nobody
Gisi |
Type: New | Status: new
feature |
Component: Template | Version: 3.1
system | Keywords: context, inclusion
Severity: Normal | tag, template
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Currently, the `csrf_token` is always added to the context of an inclusion
tag. It would be useful to define a list of additional variables that
should always be available in any context.

e.g. something like this defined in settings
{{{#!python
INCLUSION_CONTEXT_VARIABLES = ['idempotency_key', ]
}}}

and a few lines added to the `render` method of `InclusionNode`
{{{#!python
def render(self, context):
...
csrf_token = context.get('csrf_token')
if csrf_token is not None:
new_context['csrf_token'] = csrf_token
for var in settings.INCLUSION_CONTEXT_VARIABLES:
value = context.get(var)
if value is not None:
new_context[var] = value
return t.render(new_context)
}}}

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

Django

unread,
Feb 8, 2021, 12:01:53 AM2/8/21
to django-...@googlegroups.com
#32429: Configurable "always available" InclusionNode context variables
-------------------------------------+-------------------------------------
Reporter: Michael Gisi | Owner: nobody
Type: New feature | Status: closed
Component: Template system | Version: 3.1
Severity: Normal | Resolution: wontfix
Keywords: context, inclusion | Triage Stage:
tag, template | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => wontfix


Comment:

Thanks for this ticket, however creating a new setting is always
controversial and we don't want tag-specific settings. The `csrf_token` is
a special case (see #12095) to make CSRF protection to be as simple as
possible. You can always subclass `InclusionNode` and add a custom
decorator.

Feel-free to start a discussion on DevelopersMailingList if you don't
agree.

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

Django

unread,
Feb 8, 2021, 12:18:03 PM2/8/21
to django-...@googlegroups.com
#32429: Configurable "always available" InclusionNode context variables
-------------------------------------+-------------------------------------
Reporter: Michael Gisi | Owner: nobody
Type: New feature | Status: closed
Component: Template system | Version: 3.1
Severity: Normal | Resolution: wontfix
Keywords: context, inclusion | Triage Stage:
tag, template | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Michael Gisi):

Replying to [comment:1 Mariusz Felisiak]:


> Thanks for this ticket, however creating a new setting is always
controversial and we don't want tag-specific settings. The `csrf_token` is
a special case (see #12095) to make CSRF protection to be as simple as
possible. You can always subclass `InclusionNode` and add a custom
decorator.
>
> Feel-free to start a discussion on DevelopersMailingList if you don't
agree.

Understood - we will subclass `InclusionNode` to get the desired behavior.
Thanks for the quick response.

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

Reply all
Reply to author
Forward
0 new messages