1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #16074 -- Added ContextMixin to class-based generic views to handle get_context_data. Thanks emyller, Luke Plant, Preston Holmes for working on the ticket and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17875 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Claude Paroz
2012-04-06 21:24:33 +00:00
parent b4a9827133
commit 8663bc1103
9 changed files with 77 additions and 38 deletions

View File

@@ -8,6 +8,16 @@ from django.utils.decorators import classonlymethod
logger = getLogger('django.request')
class ContextMixin(object):
"""
A default context mixin that passes the keyword arguments received by
get_context_data as the template context.
"""
def get_context_data(self, **kwargs):
return kwargs
class View(object):
"""
Intentionally simple parent class for all views. Only implements
@@ -110,17 +120,13 @@ class TemplateResponseMixin(object):
return [self.template_name]
class TemplateView(TemplateResponseMixin, View):
class TemplateView(TemplateResponseMixin, ContextMixin, View):
"""
A view that renders a template.
A view that renders a template. This view is different from all the others
insofar as it also passes ``kwargs`` as ``params`` to the template context.
"""
def get_context_data(self, **kwargs):
return {
'params': kwargs
}
def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
context = self.get_context_data(params=kwargs)
return self.render_to_response(context)