Commits

Anonymous committed 16f6827 Merge

Comments (0)

Files changed (5)

+[patterns]
+**.txt = native
+**.pyva = native
+**.py = native
+**.c = native
+**.cpp = native
+**.cu = native
+**.h = native
+**.hpp = native
+**.tmpl = native
+**.html = native
+**.htm = native
+**.js = native
+**.manifest = native
+**.yaml = native

dbindexer/__init__.py

-from django.conf import settings
-from django.utils.importlib import import_module
-
-_MODULE_NAMES = getattr(settings, 'DB_INDEX_MODULES', ())
-
 def autodiscover():
     """
     Automatically loads database index definitions from db_indexes modules in
     installed apps.
     """
-    import imp
+    from django.conf import settings
+    from django.utils.importlib import import_module
+    from django.utils.module_loading import module_has_submodule
+
+    for app in settings.INSTALLED_APPS:
+        mod = import_module(app)
+        # Attempt to import the app's admin module.
+        try:
+            import_module('%s.dbindexes' % app)
+        except:
+            # Decide whether to bubble up this error. If the app just
+            # doesn't have an admin module, we can ignore the error
+            # attempting to import it, otherwise we want it to bubble up.
+            if module_has_submodule(mod, 'dbindexes'):
+                raise
+
+def load_indexes():
     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('dbindexes', 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.dbindexes" % app)
-
-def load_indexes():
-    for name in _MODULE_NAMES:
-        try:
-            import_module(name)
-        except ImportError:
-            pass
+    for name in getattr(settings, 'DB_INDEX_MODULES', ()):
+        import_module(name)

dbindexer/compiler.py

 from resolver import resolver
+from django.utils.importlib import import_module
 
 def __repr__(self):
     return '<%s, %s, %s, %s>' % (self.alias, self.col, self.field.name,

dbindexer/middleware.py

+from . import models
+
+class DBIndexerMiddleware(object):
+    """Empty because the import above already does everything for us"""
+    pass

dbindexer/models.py

+# Load the siteconf module
+from django.conf import settings
+from django.utils.importlib import import_module
+SITECONF_MODULE = getattr(settings, 'DBINDEXER_SITECONF', settings.ROOT_URLCONF)
+import_module(SITECONF_MODULE)