Commits

Anonymous committed 3affe04

adapted to django-autoload

Comments (0)

Files changed (2)

search/__init__.py

 from search.core import default_splitter, site_language, SearchManager, \
     install_index_model
+from autoload import autodiscover as auto_discover
 
 def autodiscover():
-    """
-    Automatically add managers from search_indexes modules.
-    """
-    import imp
-    from django.conf import settings
-    from django.utils.importlib import import_module
-
-    for app in settings.INSTALLED_APPS:
-        # For each app, we need to look for an search_indexes.py inside that app's
-        # package. We can't use os.path here -- recall that modules may be
-        # imported different ways (think zip files) -- so we need to get
-        # the app's __path__ and look for search_indexes.py on that path.
-
-        # Step 1: find out the app's __path__ Import errors here will (and
-        # should) bubble up, but a missing __path__ (which is legal, but weird)
-        # fails silently -- apps that do weird things with __path__ might
-        # need to roll their own index registration.
-        try:
-            app_path = import_module(app).__path__
-        except AttributeError:
-            continue
-
-        # Step 2: use imp.find_module to find the app's search_indexes.py. For some
-        # reason imp.find_module raises ImportError if the app can't be found
-        # but doesn't actually try to import the module. So skip this app if
-        # its search_indexes.py doesn't exist
-        try:
-            imp.find_module('search_indexes', app_path)
-        except ImportError:
-            continue
-
-        # Step 3: import the app's search_index file. If this has errors we want them
-        # to bubble up.
-        import_module("%s.search_indexes" % app)
+    auto_discover('search_indexes')
 
 def register(model, fields_to_index, search_index='search_index',
     indexer=None, splitter=default_splitter, relation_index=True, integrate='*',
             Indexed(extra_data=extra_data, one=u'one%d' % i, two='two%d' % i).save()
 
         for i in range(3):
-            Indexed(extra_data=extra_data, one=(None, u'ÜÄÖ-+!#><|', 'blub')[i],
+            Indexed(extra_data=extra_data, one=(None, u'ÜÄÖ-+!#><|', 'blub')[i],
                     check=bool(i%2), value=u'value%d test-word' % i).save()
 
         for i in range(3):
         self.assertEqual(len(Indexed.value_index.search('value0').filter(
             check=False)), 1)
         self.assertEqual(len(Indexed.value_index.search('value1').filter(
-            check=True, one=u'ÜÄÖ-+!#><|')), 1)
+            check=True, one=u'ÜÄÖ-+!#><|')), 1)
         self.assertEqual(len(Indexed.value_index.search('value2').filter(
             check__exact=False, one='blub')), 1)
 
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.