Commits

Branko Vukelic committed a4bbd33

Implemented adding related_object to context

Related to #1. There is still no 410 exception on POST, and no caching, but
this is a usable solution.

Comments (0)

Files changed (2)

             return super(CreateWithRelatedMixin, self).form_invalid(form)
 
         return HttpResponseRedirect(self.get_success_url())
+
+    def get_context_data(self, *args, **kwargs):
+        context = super(
+            CreateWithRelatedMixin, self
+        ).get_context_data(*args, **kwargs)
+        context['related_object'] = self.get_related_object()
+        return context
+
         with self.assertRaises(Http404):
             self.view.related_object_not_found()
 
+    def test_context(self):
+        class Super(object):
+            def get_context_data(self):
+                return dict()
+
+        class View(CreateWithRelatedMixin, Super):
+            pass
+
+        view = View()
+        view.get_related_object = Mock()
+
+        ctx = view.get_context_data()
+        view.get_related_object.assert_called_once()
+        self.assertEqual(ctx['related_object'],
+                         view.get_related_object.return_value)
+
     def test_form_valid(self):
         self.view.get_related_field = Mock()
         self.view.get_related_field.return_value = 'foo'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.