Beispiel #1
0
 def __get_settings(self):
     if not self._settings:
         if not self._default_settings:
             self._default_settings = get_settings()
         return self._default_settings
     else:
         return self._settings
Beispiel #2
0
 def make(self, name, settings = None, route = None, clearlog = True, **kwargs):
     '''Initialise DjpCms from a directory or a file'''
     import djpcms
     #
     # if not a directory it may be a file
     if os.path.isdir(name):
         appdir = name
     elif os.path.isfile(name):
         appdir = os.path.split(os.path.realpath(name))[0]
     else:
         try:
             mod = import_module(name)
             appdir = mod.__path__[0]
         except ImportError:
             raise ValueError('Could not find directory or file {0}'.format(name))
     path = os.path.realpath(appdir)
     base,name = os.path.split(path)
     if base not in sys.path:
         sys.path.insert(0, base)
     
     # Import settings
     settings = settings or 'settings'
     if '.' in settings:
         settings_module_name = settings
         os.environ['DJANGO_SETTINGS_MODULE'] = settings
     else:
         sett = '{0}.py'.format(os.path.join(path,settings))
         if os.path.isfile(sett):
             spath, settings = os.path.split(settings)
             settings_module_name = '{0}.{1}'.format(name,settings)
             os.environ['DJANGO_SETTINGS_MODULE'] = settings_module_name
         else:
             settings_module_name = None
     
     # IMPORTANT! NEED TO IMPORT HERE TO PREVENT DJANGO TO IMPORT FIRST
     settings = get_settings(settings_module_name,
                             SITE_DIRECTORY = path,
                             SITE_MODULE = name,
                             **kwargs)
     
     # If no settings available get the current one
     if self._settings is None:
         self._settings = settings
     
     # Add template media directory to template directories
     path = os.path.join(djpcms.__path__[0],'media','djpcms')
     if path not in settings.TEMPLATE_DIRS:
         settings.TEMPLATE_DIRS += path,
     
     djpcms.init_logging(clearlog)
     self.logger = logging.getLogger('ApplicationSites')
     
     return self._create_site(route,settings)