Пример #1
0
 def setUp(self):
     md = 'djpcms.middleware.error.LoggingMiddleware'
     self.LOGGING = getattr(settings, 'LOGGING', None)
     settings.LOGGING = self.config()
     self.MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES
     if django.get_version() < '1.3':
         if md not in settings.MIDDLEWARE_CLASSES:
             settings.MIDDLEWARE_CLASSES += md,
     djpcms.init_logging(clear_all = True)
Пример #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)
Пример #3
0
def setup_logging(verbosity, settings):
    LOGGING = settings.LOGGING
    LOGGING['loggers'] = {}
    root = {}
    LOGGING['root'] = root
    level = LOGGING_MAP.get(verbosity,None)
    if level is None:
        root['handlers'] = ['silent']
    else:
        root['handlers'] = ['console']
        root['level'] = level
    djpcms.init_logging(True)
Пример #4
0
 def tearDown(self):
     djpcms.init_logging(clear_all = True)        
     if self.LOGGING:
         settings.LOGGING = self.LOGGING
     settings.MIDDLEWARE_CLASSES = self.MIDDLEWARE_CLASSES