0

Django-mediagenerator has been pretty helpful so far, but thing that has been bothering me is that all MEDIA_BUNDLES are defined in settings.py. I would like to be able to define media bundles inside individual application folders.

How can media bundles be separated by application, instead of all being centralized in settings.py?

NT3RP
  • 15,262
  • 9
  • 61
  • 97

1 Answers1

0

The only way I've found to do this is to do it yourself. I ended up writing a small file in same folder as my settings file:

from settings import MEDIA_BUNDLES, INSTALLED_APPS

BUNDLE_NAME = 'MEDIA_BUNDLES'  # Name of bundles tuple
BUNDLE_FILE = 'media'          # Name of python file

for app_name in INSTALLED_APPS:
    if app_name.startswith('apps'):
        try:
            path = '{app}.{media}'.format(app=app_name, media=BUNDLE_FILE)
            app  = __import__(path, None, None, [BUNDLE_NAME])

            bundles       = getattr(app, BUNDLE_NAME)
            MEDIA_BUNDLES = MEDIA_BUNDLES + bundles
        except Exception, e:
            print e
NT3RP
  • 15,262
  • 9
  • 61
  • 97