Example #1
0
def _dependencies(app_name):
    """
        Returns the module names of the apps that *app_name* claims to depend
        upon, or an empty list if it has no dependencies (ie, the app does not
        export an iterable REQUIRED_APPS).

        Raises DependencyImportError (which is a subclass of ImportError, to be
        handled easily) if *app_name* does not exist. Any exception raised from
        within the module during import is allowed to propagate, to avoid
        masking errors which are unrelated to dependency management.

          # this module has no dependencies
          >>> _dependencies("depends")
          []

          # temporarily add a REQUIRED_APPS constant to this
          # module, so we can test that this function finds it
          >>> mod = sys.modules["depends"]
          >>> mod.REQUIRED_APPS = ["a", "b", "c"]
          
          # look for the dependencies
          >>> _dependencies("depends")
          ['a', 'b', 'c']

          # clean up the namespace
          del mod.REQUIRED_APPS
    """

    # try to import the app
    module = try_import(app_name)
    if module is None:
        raise (DependencyImportError("No module named %s" % (app_name)))

    # return the required apps unchecked, since this
    # function will probably be re-called for each of
    # them, which will import their module (aboe)
    if hasattr(module, "REQUIRED_APPS"):
        return module.REQUIRED_APPS

    # default to no dependencies
    return []
Example #2
0
    (r'', include('program.urls')),
    (r'', include('phone.urls')),
    (r'user_registration', include("user_registration.urls"))
)

# magic static media server (idea + implementation lifted from rapidsms)
for module_name in settings.INSTALLED_APPS:

    # leave django contrib apps alone. (many of them include urlpatterns
    # which shouldn't be auto-mapped.) this is a hack, but i like the
    # automatic per-app mapping enough to keep it. (for now.)
    if module_name.startswith("django."):
        continue

    # attempt to import this app's urls
    module = try_import("%s.urls" % (module_name))
    if not hasattr(module, "urlpatterns"): continue

    
    # if the MEDIA_URL does not contain a hostname (ie, it's just an
    # http path), and we are running in DEBUG mode, we will also serve
    # the media for this app via this development server. in production,
    # these files should be served directly
    if settings.DEBUG:
        if not settings.MEDIA_URL.startswith("http://"):
            media_prefix = settings.MEDIA_URL.strip("/")
            module_suffix = module_name.split(".")[-1]

            # does urls.py have a sibling "static" dir? (media is always
            # served from "static", regardless of what MEDIA_URL says)
            module_path = os.path.dirname(module.__file__)