1. Ian George
  2. Quiet apps

Source

Quiet apps / quiet / common / management / commands / utils.py

from django.core.management.base import BaseCommand, CommandError
from django.db.models import get_apps

class CommonCommand(BaseCommand):
    
    def get_settings_configs(self, app_list):
        from quiet.common.conf import Config

        if not app_list:
            for app in get_apps():
                #app.__name__ looks like 'app_module.models' so we remove the .model
                app_list.append(".".join(app.__name__.split('.')[0:-1]))

        app_list = [app + '.config' for app in app_list]

        print app_list

        for config_module in app_list:
            try:
                module = __import__(config_module, globals(), locals(), ['config'], -1)
            except ImportError:
                continue

            for key,value in module.__dict__.items():
                try:
                    use = issubclass(value, Config)
                except TypeError:
                    continue

                if use:
                    module = value()
                    yield (module, config_module)

    def output(self, message):
        self.stdout.write('%s\n' % message)