Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #5968 -- Allowed (un-)registering with databrowse several model…

…s at once.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17405 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1cc800783c0f02a8f65e85b53ecb05ae5c0a4d88 1 parent 4a3acee
Aymeric Augustin authored January 28, 2012
14  django/contrib/databrowse/sites.py
@@ -73,7 +73,7 @@ def __init__(self):
73 73
         self.registry = {} # model_class -> databrowse_class
74 74
         self.root_url = None
75 75
 
76  
-    def register(self, model_or_iterable, databrowse_class=None, **options):
  76
+    def register(self, *model_list, **options):
77 77
         """
78 78
         Registers the given model(s) with the given databrowse site.
79 79
 
@@ -84,23 +84,19 @@ def register(self, model_or_iterable, databrowse_class=None, **options):
84 84
 
85 85
         If a model is already registered, this will raise AlreadyRegistered.
86 86
         """
87  
-        databrowse_class = databrowse_class or DefaultModelDatabrowse
88  
-        if issubclass(model_or_iterable, models.Model):
89  
-            model_or_iterable = [model_or_iterable]
90  
-        for model in model_or_iterable:
  87
+        databrowse_class = options.pop('databrowse_class', DefaultModelDatabrowse)
  88
+        for model in model_list:
91 89
             if model in self.registry:
92 90
                 raise AlreadyRegistered('The model %s is already registered' % model.__name__)
93 91
             self.registry[model] = databrowse_class
94 92
 
95  
-    def unregister(self, model_or_iterable):
  93
+    def unregister(self, *model_list):
96 94
         """
97 95
         Unregisters the given model(s).
98 96
 
99 97
         If a model isn't already registered, this will raise NotRegistered.
100 98
         """
101  
-        if issubclass(model_or_iterable, models.Model):
102  
-            model_or_iterable = [model_or_iterable]
103  
-        for model in model_or_iterable:
  99
+        for model in model_list:
104 100
             if model not in self.registry:
105 101
                 raise NotRegistered('The model %s is not registered' % model.__name__)
106 102
             del self.registry[model]
9  docs/ref/contrib/databrowse.txt
@@ -33,13 +33,18 @@ How to use Databrowse
33 33
 2. Register a number of models with the Databrowse site::
34 34
 
35 35
        from django.contrib import databrowse
36  
-       from myapp.models import SomeModel, SomeOtherModel
  36
+       from myapp.models import SomeModel, SomeOtherModel, YetAnotherModel
37 37
 
38 38
        databrowse.site.register(SomeModel)
39  
-       databrowse.site.register(SomeOtherModel)
  39
+       databrowse.site.register(SomeOtherModel, YetAnotherModel)
40 40
 
41 41
    Note that you should register the model *classes*, not instances.
42 42
 
  43
+   .. versionchanged:: 1.4
  44
+
  45
+   Since Django 1.4, it is possible to register several models in the same
  46
+   call to :func:`~databrowse.site.register`.
  47
+
43 48
    It doesn't matter where you put this, as long as it gets executed at some
44 49
    point. A good place for it is in your :doc:`URLconf file
45 50
    </topics/http/urls>` (``urls.py``).
5  tests/runtests.py
@@ -4,9 +4,13 @@
4 4
 import subprocess
5 5
 import sys
6 6
 import tempfile
  7
+import warnings
7 8
 
8 9
 from django import contrib
9 10
 
  11
+# databrowse is deprecated, but we still want to run its tests
  12
+warnings.filterwarnings('ignore', "The Databrowse contrib app is deprecated",
  13
+                        PendingDeprecationWarning, 'django.contrib.databrowse')
10 14
 
11 15
 CONTRIB_DIR_NAME = 'django.contrib'
12 16
 MODEL_TESTS_DIR_NAME = 'modeltests'
@@ -34,6 +38,7 @@
34 38
     'django.contrib.comments',
35 39
     'django.contrib.admin',
36 40
     'django.contrib.admindocs',
  41
+    'django.contrib.databrowse',
37 42
     'django.contrib.staticfiles',
38 43
     'django.contrib.humanize',
39 44
     'regressiontests.staticfiles_tests',

0 notes on commit 1cc8007

Please sign in to comment.
Something went wrong with that request. Please try again.