1. Monwara LLC
  2. Untitled project
  3. django-related

Commits

Branko Vukelic  committed 6953379

Sometimes we don't use a form

  • Participants
  • Parent commits e92972e
  • Branches master

Comments (0)

Files changed (2)

File related/views.py

View file
 
     def get_context_data(self, *arg, **kwarg):
         context = dict()
-        context['existing_form'] = self.get_existing_form(data=self.request.GET)
+
+        if self.get_existing_form_class():
+            context['existing_form'] = self.get_existing_form(
+                data=self.request.GET
+            )
+
         context.update(
             super(GetExistingMixin, self).get_context_data(*arg, **kwarg)
         )

File tests/tests.py

View file
         view = View()
 
         view.request = Mock()
-        view.request.GET = dict(fam='dam')
+        view.request.get = dict(fam='dam')
+        view.get_existing_form_class = Mock()
         view.get_existing_form = Mock()
 
         ctx = view.get_context_data()
 
         self.assertTrue(ctx.has_key('existing_form'))
 
+    def test_without_form(self):
+        class Super(object):
+            def get_context_data(self):
+                return dict(foo='bar')
+
+        class View(GetExistingMixin, Super):
+            pass
+
+        view = View()
+
+        view.request = Mock()
+        view.request.get = dict(fam='dam')
+
+        ctx = view.get_context_data()
+        self.assertFalse(ctx.has_key('existing_form'))
+
     def test_post(self):
         class Super(object):
             def post(self, request):