Ticket #8245: 8245.diff

File 8245.diff, 1.7 KB (added by Gary Wilson, 16 years ago)
  • django/contrib/admin/__init__.py

     
    22from django.contrib.admin.options import StackedInline, TabularInline
    33from django.contrib.admin.sites import AdminSite, site
    44
     5LOADING_FLAG = '_admin_autodiscover_loading'
     6
    57def autodiscover():
    68    """
    7     Auto-discover INSTALLED_APPS admin.py modules and fail silently when 
     9    Auto-discover INSTALLED_APPS admin.py modules and fail silently when
    810    not present. This forces an import on them to register any admin bits they
    911    may want.
    1012    """
     
    2123        # should) bubble up, but a missing __path__ (which is legal, but weird)
    2224        # fails silently -- apps that do weird things with __path__ might
    2325        # need to roll their own admin registration.
     26        app_mod = __import__(app, {}, {}, [app.split('.')[-1]])
     27        # Bail out if this app didn't finish loading from a previous call so
     28        # that we avoid masking the real exception with an AlreadyRegistered
     29        # exception.
     30        if getattr(app_mod, LOADING_FLAG, False):
     31            continue
     32        # Set a flag to designate that this app is loading.
     33        setattr(app_mod, LOADING_FLAG, True)
    2434        try:
    25             app_path = __import__(app, {}, {}, [app.split('.')[-1]]).__path__
     35            app_path = app_mod.__path__
    2636        except AttributeError:
    2737            continue
    2838
     
    3848        # Step 3: import the app's admin file. If this has errors we want them
    3949        # to bubble up.
    4050        __import__("%s.admin" % app)
     51        # Import was successful, remove loading flag.
     52        delattr(app_mod, LOADING_FLAG)
Back to Top