Beispiel #1
0
    def IsTypeAllowed(self, type, user=None):
        """
        Check if *type* is allowed to be created in this container based on
        configuration.subtypes.::
        
            type = the type to be checked
            user = the currently active user
            returns True/False
        
        *type* can be passed as
        
        - type id string
        - configuration object
        - type object instance
        """
        if type is None:
            return False
        subtypes = self.configuration.subtypes
        if subtypes == AllTypesAllowed:
            return True
        if not subtypes:
            return False

        if isinstance(type, basestring):
            if type in subtypes:
                return True
            # dotted python to obj configuration
            type = self.app.GetObjectConf(type)
            if type is None:
                return False
            # create type from configuration
            type = self._GetVirtualObj(type)
            if type is None:
                return False

        if isinstance(type, baseConf):
            if type.id in subtypes:
                return True
            # create type from configuration
            type = self._GetVirtualObj(type)
            if type is None:
                return False

        if not IObject.providedBy(type) and not IConf.providedBy(type):
            return False
        # loop subtypes
        for iface in subtypes:
            if isinstance(iface, basestring):
                iface = ResolveName(iface, raiseExcp=False)
                if not iface:
                    continue
            try:
                # may not be interface class
                if iface.providedBy(type):
                    return True
            except:
                pass
        return False
Beispiel #2
0
    def IsTypeAllowed(self, type, user=None):
        """
        Check if *type* is allowed to be created in this container based on
        configuration.subtypes.::
        
            type = the type to be checked
            user = the currently active user
            returns True/False
        
        *type* can be passed as
        
        - type id string
        - configuration object
        - type object instance
        """
        if type is None:
            return False
        subtypes = self.configuration.subtypes
        if subtypes == AllTypesAllowed:
            return True
        if not subtypes:
            return False

        if isinstance(type, basestring):
            if type in subtypes:
                return True
            # dotted python to obj configuration
            type = self.app.GetObjectConf(type)
            if type is None:
                return False
            # create type from configuration
            type = self._GetVirtualObj(type)
            if type is None:
                return False

        if isinstance(type, baseConf):
            if type.id in subtypes:
                return True
            # create type from configuration
            type = self._GetVirtualObj(type)
            if type is None:
                return False

        if not IObject.providedBy(type) and not IConf.providedBy(type):
            return False
        # loop subtypes
        for iface in subtypes:
            if isinstance(iface, basestring):
                iface = ResolveName(iface, raiseExcp=False)
                if not iface:
                    continue
            try:
                # may not be interface class
                if iface.providedBy(type):
                    return True
            except:
                pass
        return False
Beispiel #3
0
 def LoadStoredValues(self):
     """
     Load values
     
     Event: - dataloaded()
     """
     values = self.app.LoadSysValue(self.storagekey)
     if values:
         values = LoadJSONConf(values, default=Conf)
         if isinstance(values, dict) or IConf.providedBy(values):
             data, meta, files = self.SplitData(values)
             self.data.update(data)
             self.meta.update(meta)
             if not hasattr(self, "files"):
                 self.files = {}
             self.files.update(files)
     self.Signal("dataloaded")
Beispiel #4
0
 def LoadStoredValues(self):
     """
     Load values
     
     Event: - dataloaded()
     """
     values = self.app.LoadSysValue(self.storagekey)
     if values:
         values = LoadJSONConf(values, default=Conf)
         if isinstance(values, dict) or IConf.providedBy(values):
             data, meta, files = self.SplitData(values)
             self.data.update(data)
             self.meta.update(meta)
             if not hasattr(self, "files"):
                 self.files = {}
             self.files.update(files)
     self.Signal("dataloaded")
Beispiel #5
0
def ResolveConfiguration(conf, base=None):
    """
    Lookup configuration object by dotted python name. Returns interface and configuration object.
    Extends pyramid.DottedNameResolver with .json file support for configuration objects.
    
    Supports the following cases:
    
    - Path and file name to .json file. requires `type` set to one of the 
      configuration types: 
      *AppConf, FieldConf, DatabaseConf, RootConf, ObjectConf, ViewModuleConf, ViewConf, ToolConf, 
      GroupConf, CategoryConf*
    - Dotted python name for configuration object including attribute name of configuration instance.
    - Dotted python name for object. Uses the convention to load the configuration from the 
      'configuration' attribute of the referenced object.
    - Configuration instance. Will just return it.
    
    returns Interface, configuration
    """
    # string instance
    if isinstance(conf, basestring):
        if not base:
            base = caller_package()
        # json file
        if conf.find(".json")!= -1:
            path = ResolveAsset(conf, base)
            s = LoadFromFile(path.abspath())
            conf = json.loads(s)
        # resolve attribute name
        elif conf:
            c = ResolveName(conf, base=base)
            if hasattr(c, "configuration"):
                conf = c.configuration
            else:
                conf = c

    # dict instance
    if isinstance(conf, dict):
        # load by interface
        if not "type" in conf:
            raise TypeError, "Configuration type not defined"
        c = ResolveName(conf["type"], base="nive")
        del conf["type"]
        conf = c(**conf)

    # module and not configuration
    if not IConf.providedBy(conf):
        if hasattr(conf, "configuration"):
            conf = conf.configuration
        
    # object instance
    if IAppConf.providedBy(conf): return IAppConf, conf
    if IDatabaseConf.providedBy(conf): return IDatabaseConf, conf
    if IFieldConf.providedBy(conf): return IFieldConf, conf
    if IRootConf.providedBy(conf): return IRootConf, conf
    if IObjectConf.providedBy(conf): return IObjectConf, conf
    if IViewModuleConf.providedBy(conf): return IViewModuleConf, conf
    if IViewConf.providedBy(conf): return IViewConf, conf
    if IToolConf.providedBy(conf): return IToolConf, conf
    if IPortalConf.providedBy(conf): return IPortalConf, conf
    if IGroupConf.providedBy(conf): return IGroupConf, conf
    if ICategoryConf.providedBy(conf): return ICategoryConf, conf
    if IModuleConf.providedBy(conf): return IModuleConf, conf
    if IWidgetConf.providedBy(conf): return IWidgetConf, conf
    if IWfProcessConf.providedBy(conf): return IWfProcessConf, conf
    if IWfStateConf.providedBy(conf): return IWfStateConf, conf
    if IWfTransitionConf.providedBy(conf): return IWfTransitionConf, conf
    if IConf.providedBy(conf): return IConf, conf
    return None, conf