diff options
| author | Karol Sikora <elektrrrus@gmail.com> | 2013-05-18 12:42:18 +0200 |
|---|---|---|
| committer | Karol Sikora <elektrrrus@gmail.com> | 2013-05-18 21:13:27 +0200 |
| commit | 3eba8c7f7fc4877e7df0f83fe3bacd88082ac33e (patch) | |
| tree | 9a42100a0374c50d3e244da1ac65e5154b7d6158 /django | |
| parent | 0038296135502331c302935106d7aa568f715200 (diff) | |
Fixed #20234 and #20236 -- SingleObjectMixin fixes
Added object on SingleObjectMixin returned context,
some code clanup.
Diffstat (limited to 'django')
| -rw-r--r-- | django/views/generic/detail.py | 10 | ||||
| -rw-r--r-- | django/views/generic/edit.py | 14 |
2 files changed, 6 insertions, 18 deletions
diff --git a/django/views/generic/detail.py b/django/views/generic/detail.py index 58302bbe23..23000641b4 100644 --- a/django/views/generic/detail.py +++ b/django/views/generic/detail.py @@ -93,9 +93,11 @@ class SingleObjectMixin(ContextMixin): Insert the single object into the context dict. """ context = {} - context_object_name = self.get_context_object_name(self.object) - if context_object_name: - context[context_object_name] = self.object + 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 context.update(kwargs) return super(SingleObjectMixin, self).get_context_data(**context) @@ -122,7 +124,7 @@ class SingleObjectTemplateResponseMixin(TemplateResponseMixin): * the value of ``template_name`` on the view (if provided) * the contents of the ``template_name_field`` field on the object instance that the view is operating upon (if available) - * ``<app_label>/<object_name><template_name_suffix>.html`` + * ``<app_label>/<object_name><template_name_suffix>.html`` """ try: names = super(SingleObjectTemplateResponseMixin, self).get_template_names() diff --git a/django/views/generic/edit.py b/django/views/generic/edit.py index e2cc741ffb..cf87aeed27 100644 --- a/django/views/generic/edit.py +++ b/django/views/generic/edit.py @@ -136,20 +136,6 @@ class ModelFormMixin(FormMixin, SingleObjectMixin): self.object = form.save() return super(ModelFormMixin, self).form_valid(form) - def get_context_data(self, **kwargs): - """ - If an object has been supplied, inject it into the context with the - supplied context_object_name name. - """ - 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 - context.update(kwargs) - return super(ModelFormMixin, self).get_context_data(**context) - class ProcessFormView(View): """ |
