Commits

Branko Vukelic committed fb60961

Renamed GetExistingMixin to RedirectOnExistingMixin

GetExistingMixin is still available as an alias for the new name, but it is
considered deprecated. It may be removed in future releases. None of the
property or method names have been changed.

Comments (0)

Files changed (3)

 There is no need to add ``related`` to installed apps. It can be used
 directly::
     
-    from related.views import GetExistingMixin, CreateWithRelatedMixin
+    from related.views import RedirectOnExistingMixin, CreateWithRelatedMixin
     ...
 
 GetExistingMixin
 ================
 
+This mixin is deprecated. It is currently just an alias for
+RedirectOnExistingMixin_ to provide backwards compatibility. It will be removed
+because of the confusing name.
+
+Only the class name has changed. All property and method names are left intact.
+
+
+RedirectOnExistingMixin
+=======================
+
+This mixin is used when an attempt to create an object that already exists in
+the database should result in a redirect. If the object does not exist in the
+database, it will not do anything.
+
 Basic usage::
 
-    from related.views import GetExistingMixin
+    from related.views import RedirectOnExistingMixin
     from django.views.gneric import CreateView
 
     from models import Foo
 
-    class MyView(GetExistingMixin, CreateView):
+    class MyView(RedirectOnExistingMixin, CreateView):
         model = Foo
         existing_redirect_url = '/bar'
 
 With the above view, if we submit a form that contains a ``pk`` or ``slug``
 field, and the ``Foo`` object with matching ``pk`` or ``slug`` field exists,
 user will be redirected to ``/bar`` path, and the model form for ``Foo`` will
-not even be processed.
+not even be processed. The redirect path can be customized using the options
+discussed further below.
+
+Note that this mixin _will_ result in extra database queries to determine
+whether an object exists.
 
 The view can be further customized using the following properties (and matching
 methods):
 from django.core.cache import cache
 
 
-class GetExistingMixin(object):
+class RedirectOnExistingMixin(object):
     existing_form_class = None
     existing_form_field = None
     existing_form_initial = None
                 context[context_form_name] = form
 
         context.update(
-            super(GetExistingMixin, self).get_context_data(*arg, **kwarg)
+            super(RedirectOnExistingMixin, self).get_context_data(*arg,
+                                                                  **kwarg)
         )
         return context
 
             return HttpResponseRedirect(
                 self.get_existing_redirect_url(existing_object))
 
-        return super(GetExistingMixin, self).post(request, *args, **kwargs)
+        return super(RedirectOnExistingMixin, self).post(request, *args,
+                                                         **kwargs)
 
+GetExistingMixin = RedirectOnExistingMixin
 
 class RelatedObjectMixin(object):
     related_model = None
 from django.test import TestCase
 from mock import Mock, patch
 
-from related.views import GetExistingMixin, CreateWithRelatedMixin
+from related.views import RedirectOnExistingMixin, CreateWithRelatedMixin
 
 
-class GetExistingMixinTestCase(TestCase):
+class RedirectOnExistingMixinTestCase(TestCase):
     def setUp(self):
         self.request = Mock()
         self.request.REQUEST = Mock()
         self.request.REQUEST.get = Mock()
-        self.view = GetExistingMixin()
+        self.view = RedirectOnExistingMixin()
         self.view.request = self.request
 
     def test_get_existing_redirect_url(self):
             def get_context_data(self):
                 return dict(foo='bar')
 
-        class View(GetExistingMixin, Super):
+        class View(RedirectOnExistingMixin, Super):
             pass
 
         view = View()
             def get_context_data(self):
                 return dict(foo='bar')
 
-        class View(GetExistingMixin, Super):
+        class View(RedirectOnExistingMixin, Super):
             pass
 
         view = View()
             def get_context_data(self):
                 return dict(foo='bar')
 
-        class View(GetExistingMixin, Super):
+        class View(RedirectOnExistingMixin, Super):
             pass
 
         view = View()
             def get_context_data(self):
                 return dict(foo='bar')
 
-        class View(GetExistingMixin, Super):
+        class View(RedirectOnExistingMixin, Super):
             pass
 
         view = View()
             def get_context_data(self):
                 return dict(foo='bar')
 
-        class View(GetExistingMixin, Super):
+        class View(RedirectOnExistingMixin, Super):
             pass
 
         view = View()
             def post(self, request):
                 return 'foo'
 
-        class View(GetExistingMixin, Super):
+        class View(RedirectOnExistingMixin, Super):
             pass
 
         view = View()
         class Super(object):
             post = Mock()
 
-        class View(GetExistingMixin, Super):
+        class View(RedirectOnExistingMixin, Super):
             pass
 
         view = View()
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.