docs: def _make_settings(args, application, settings, STATIC_ROOT, MEDIA_ROOT):
      """
      Setup the Django settings
      :param args: docopt arguments
      :param default_settings: default Django settings
      :param settings: Django settings module
      :param STATIC_ROOT: static root directory
      :param MEDIA_ROOT: media root directory
      :return:
      """
      import dj_database_url
      from .default_settings import get_default_settings, get_boilerplates_settings
  
      try:
          extra_settings_file = args.get('--extra-settings')
          if not extra_settings_file:
              extra_settings_file = HELPER_FILE
          if extra_settings_file[-3:] != '.py':
              filename, __ = os.path.splitext(extra_settings_file)
              extra_settings_file = '{0}.py'.format(filename)
          extra_settings = load_from_file(extra_settings_file).HELPER_SETTINGS
      except (IOError, AttributeError):
          extra_settings = None
      default_name = ':memory:' if args['test'] else 'local.sqlite'
      db_url = os.environ.get('DATABASE_URL', 'sqlite://localhost/%s' % default_name)
      configs = {
          'DATABASES': {'default': dj_database_url.parse(db_url)},
          'STATIC_ROOT': STATIC_ROOT,
          'MEDIA_ROOT': MEDIA_ROOT,
          'USE_TZ': True,
          'USE_CMS': args['--cms'],
          'BASE_APPLICATION': application
      }
  
      if configs['USE_CMS'] or getattr(extra_settings, 'USE_CMS', False):
          CMS_APPS = [
              'cms',
              'menus',
              'sekizai',
          ]
          CMS_APP_STYLE = [
              'djangocms_admin_style'
          ]
          CMS_PROCESSORS = [
              'cms.context_processors.cms_settings',
              'sekizai.context_processors.sekizai',
          ]
          CMS_MIDDLEWARE = [
              'cms.middleware.language.LanguageCookieMiddleware',
              'cms.middleware.user.CurrentUserMiddleware',
              'cms.middleware.page.CurrentPageMiddleware',
              'cms.middleware.toolbar.ToolbarMiddleware',
          ]
          if not CMS_31 and args['server']:
              CMS_MIDDLEWARE.append('cms.middleware.utils.ApphookReloadMiddleware')
          URLCONF = 'djangocms_helper.urls'
      else:
          CMS_APPS = []
          CMS_APP_STYLE = []
          CMS_MIDDLEWARE = []
          CMS_PROCESSORS = []
          URLCONF = 'djangocms_helper.urls'
  
      default_settings = get_default_settings(
          CMS_APPS, CMS_PROCESSORS, CMS_MIDDLEWARE, CMS_APP_STYLE, URLCONF, application
      )
      migrate = args.get('--migrate') or not args.get('--no-migrate')
      default_settings.update(configs)
  
      if extra_settings:
          apps = extra_settings.pop('INSTALLED_APPS', [])
          apps_top = extra_settings.pop('TOP_INSTALLED_APPS', [])
          template_processors = extra_settings.pop('TEMPLATE_CONTEXT_PROCESSORS', [])
          template_loaders = extra_settings.pop('TEMPLATE_LOADERS', [])
          template_dirs = extra_settings.pop('TEMPLATE_DIRS', [])
          middleware = extra_settings.pop('MIDDLEWARE_CLASSES', [])
          middleware_top = extra_settings.pop('TOP_MIDDLEWARE_CLASSES', [])
          default_settings.update(extra_settings)
          for app in apps_top:
              default_settings['INSTALLED_APPS'].insert(0, app)
          default_settings['INSTALLED_APPS'].extend(apps)
          default_settings['TEMPLATE_CONTEXT_PROCESSORS'].extend(template_processors)
          default_settings['TEMPLATE_LOADERS'].extend(template_loaders)
          if 'TEMPLATE_DIRS' not in default_settings:
              default_settings['TEMPLATE_DIRS'] = []
          default_settings['TEMPLATE_DIRS'].extend(template_dirs)
          default_settings['MIDDLEWARE_CLASSES'].extend(middleware)
          for middleware in middleware_top:
              default_settings['MIDDLEWARE_CLASSES'].insert(0, middleware)
  
      if 'cms' in default_settings['INSTALLED_APPS']:
          if 'treebeard' not in default_settings['INSTALLED_APPS']:
              default_settings['INSTALLED_APPS'].append('treebeard')
      if ('filer' in default_settings['INSTALLED_APPS'] and
              'mptt' not in default_settings['INSTALLED_APPS']):
          default_settings['INSTALLED_APPS'].append('mptt')
      if ('filer' in default_settings['INSTALLED_APPS'] and
              'easy_thumbnails' not in default_settings['INSTALLED_APPS']):
          default_settings['INSTALLED_APPS'].append('easy_thumbnails')
  
      if args['--boilerplate']:
          boilerplate_settings = get_boilerplates_settings()
  
          # Do not override helper settings with defaults.
          if 'ALDRYN_BOILERPLATE_NAME' in default_settings.keys():
              del boilerplate_settings['ALDRYN_BOILERPLATE_NAME']
  
          default_settings = extend_settings(
              default_settings, boilerplate_settings, 'STATICFILES_FINDERS',
              'django.contrib.staticfiles.finders.AppDirectoriesFinder'
          )
          del boilerplate_settings['STATICFILES_FINDERS']
  
          default_settings = extend_settings(
              default_settings, boilerplate_settings, 'TEMPLATE_LOADERS',
              'django.template.loaders.app_directories.Loader'
          )
          del boilerplate_settings['TEMPLATE_LOADERS']
  
          for setting in ('INSTALLED_APPS', 'TEMPLATE_CONTEXT_PROCESSORS'):
              default_settings[setting].extend(boilerplate_settings[setting])
              del boilerplate_settings[setting]
          default_settings.update(boilerplate_settings)
  
      default_settings['TEMPLATES'] = [
          {'NAME': 'django',
           'BACKEND': 'django.template.backends.django.DjangoTemplates',
           'OPTIONS': {
               'context_processors': [
                   template_processor.replace('django.core', 'django.template')
                   for template_processor in default_settings.pop('TEMPLATE_CONTEXT_PROCESSORS')
               ],
               'loaders': default_settings.pop('TEMPLATE_LOADERS')
           }}
      ]
      if 'TEMPLATE_DIRS' in default_settings:
          default_settings['TEMPLATES'][0]['DIRS'] = default_settings.pop('TEMPLATE_DIRS')
  
      # Support for custom user models
      if 'AUTH_USER_MODEL' in os.environ:
          custom_user_app = os.environ['AUTH_USER_MODEL'].rpartition('.')[0]
          custom_user_model = '.'.join(os.environ['AUTH_USER_MODEL'].split('.')[-2:])
          default_settings['INSTALLED_APPS'].insert(
              default_settings['INSTALLED_APPS'].index('cms'),
              custom_user_app
          )
          default_settings['AUTH_USER_MODEL'] = custom_user_model
  
      if args['test']:
          default_settings['SESSION_ENGINE'] = 'django.contrib.sessions.backends.cache'
      if application not in default_settings['INSTALLED_APPS']:
          default_settings['INSTALLED_APPS'].append(application)
  
      if not migrate:
          default_settings['MIGRATION_MODULES'] = DisableMigrations()
  
      if 'MIDDLEWARE' not in default_settings:
          default_settings['MIDDLEWARE'] = default_settings['MIDDLEWARE_CLASSES']
          del default_settings['MIDDLEWARE_CLASSES']
  
      _reset_django(settings)
      settings.configure(**default_settings)
      django.setup()
      reload_urls(settings, cms_apps=False)
      return settings