#16074: Class-based views clash get_context_data
------------------------------------+-------------------------------
Reporter: emyller | Owner: nobody
Type: Bug | Status: new
Milestone: | Component: Generic views
Version: 1.3 | Severity: Normal
Resolution: | Keywords: cbv
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
------------------------------------+-------------------------------
Changes (by lukeplant):
* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted
Comment:
Getting views to modify a `context_data` dictionary instead of using
`get_context_data` would be a backwards incompatible change. And it still
wouldn't fix the actual problem, which is that these methods that provide
context data don't call `super()`.
So the best fix is to add the appropriate `super()` calls. If we fix that,
we have the problem that `object` doesn't have `get_context_data` so will
barf. Given the hierarchies that we have (with mixins that don't inherit
from View), the only solution I can see is that every `get_context_data`
implementation calls `super()`, but if it can't be sure that it has a
superclass with `get_context_data` defined, it does this (using
`FormMixin` as an example):
{{{
#!python
class FormMixin(object):
def get_context_data(self, **kwargs):
try:
m = super(FormMixin, self).get_context_data
except AttributeError:
return kwargs
d = m()
d.update(kwargs)
return d
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/16074#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.