Code

Opened 6 years ago

Closed 13 months ago

#8135 closed New feature (wontfix)

Make RequestContext act as a dictionary

Reported by: garcia_marc Owned by: nobody
Component: Template system Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When creating the context, using RequestContext to include context processors content, the next doesn't work:

 context = dict(example=value)
 context.update(RequestContext(request))

instead I can use

 context = requestContext(request)
 context.update(dict(example=value))

but I think that also allowing the first case would avoid some confusion.

Attachments (0)

Change History (9)

comment:1 Changed 6 years ago by mk

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

This ticket makes not much sense to me. The Context is more than a simple dict, it is a stack container offering functions which cannot be easily emulated using a dict.

Although it would be possible to further emulate a dict I think this would send a wrong message to the user. Why would you want to construct a RequestContext, update a dict with it and then again create a Context to render the template?

comment:2 Changed 6 years ago by ericholscher

  • milestone set to post-1.0
  • Triage Stage changed from Unreviewed to Design decision needed

I ran into this as well, but don't know if it's a "good thing"

comment:3 Changed 6 years ago by julien

  • Triage Stage changed from Design decision needed to Accepted

This is a valid point. The context is generally assumed to be a dictionary, so RequestContext should behave as such.

comment:4 Changed 6 years ago by julien

  • Triage Stage changed from Accepted to Design decision needed

Ok, after a second thought, there's an easy way around this:

from django.template import Context
context = Context(dict(example=value))
context.update(RequestContext(request))

comment:5 Changed 5 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:6 Changed 3 years ago by lukeplant

  • Severity set to Normal
  • Type set to New feature

comment:7 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:8 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:9 Changed 13 months ago by apollo13

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

I don't see much gain in it -- especially since one usually passes RequestContext as context_instance and not via the normal dict.

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.