Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: django/django
...
head fork: dracos/django
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 10, 2013
@dracos dracos Add 'object' to context in SingleObjectMixin
To match the documentation of SingleObjectMixin, if it is used separately from (Base)DetailView.
e352f70
Showing with 5 additions and 2 deletions.
  1. +3 −1 django/views/generic/detail.py
  2. +2 −1  tests/generic_views/base.py
View
4 django/views/generic/detail.py
@@ -93,6 +93,8 @@ def get_context_data(self, **kwargs):
Insert the single object into the context dict.
"""
context = {}
+ if self.object:
+ context['object'] = self.object
context_object_name = self.get_context_object_name(self.object)
if context_object_name:
context[context_object_name] = self.object
@@ -106,7 +108,7 @@ class BaseDetailView(SingleObjectMixin, View):
"""
def get(self, request, *args, **kwargs):
self.object = self.get_object()
- context = self.get_context_data(object=self.object)
+ context = self.get_context_data()
return self.render_to_response(context)
View
3  tests/generic_views/base.py
@@ -403,8 +403,9 @@ def test_get_context_data_super(self):
test_view = views.CustomContextView()
context = test_view.get_context_data(kwarg_test='kwarg_value')
- # the test_name key is inserted by the test classes parent
+ # the test_name and object keys are inserted by the test class's parent
self.assertTrue('test_name' in context)
+ self.assertTrue('object' in context)
self.assertEqual(context['kwarg_test'], 'kwarg_value')
self.assertEqual(context['custom_key'], 'custom_value')

No commit comments for this range

Something went wrong with that request. Please try again.