예제 #1
0
파일: search.py 프로젝트: comlorda/nive
    def _GetFieldDefinitions(self, fields, pool_type=None):
        f = []
        for fld in fields:
            if IFieldConf.providedBy(fld):
                f.append(fld)
                continue
            if not isinstance(fld, basestring):
                continue
            if fld in ("__preview__", ):
                continue
            # skip custom flds
            if fld[0] == "+":
                continue
            # Aggregate functions, custom flds
            if fld[0] == "-":
                f.append(
                    FieldConf(**{
                        "id": fld,
                        "name": fld,
                        "datatype": "string"
                    }))
                continue

            fl = self.app.GetFld(fld, pool_type)
            if fl:
                f.append(fl)
        return f
예제 #2
0
 def GetMetaFld(self, fldID):
     """
     Get meta field configuration
     
     returns configuration or None
     """
     if IFieldConf.providedBy(fldID):
         f = filter(lambda d: d["id"] == fldID.id, self.configuration.meta)
         if f:
             return fldID
     else:
         f = filter(lambda d: d["id"] == fldID, self.configuration.meta)
         if f:
             return f[0]
     return None
예제 #3
0
 def GetMetaFld(self, fldID):
     """
     Get meta field configuration
     
     returns configuration or None
     """
     if IFieldConf.providedBy(fldID):
         f = filter(lambda d: d["id"] == fldID.id, self.configuration.meta)
         if f:
             return fldID
     else:
         f = filter(lambda d: d["id"] == fldID, self.configuration.meta)
         if f:
             return f[0]
     return None
예제 #4
0
 def GetObjectFld(self, fldID, typeID):
     """
     Returns object field configuration.
     
     returns configuration or None
     """
     fields = self.GetAllObjectFlds(typeID)
     if not fields:
         return None
     if IFieldConf.providedBy(fldID):
         f = filter(lambda d: d["id"] == fldID.id, fields)
         if f:
             return fldID
     else:
         f = filter(lambda d: d["id"] == fldID, fields)
         if f:
             return f[0]
     return None
예제 #5
0
 def GetObjectFld(self, fldID, typeID):
     """
     Returns object field configuration.
     
     returns configuration or None
     """
     fields = self.GetAllObjectFlds(typeID)
     if not fields:
         return None
     if IFieldConf.providedBy(fldID):
         f = filter(lambda d: d["id"] == fldID.id, fields)
         if f:
             return fldID
     else:
         f = filter(lambda d: d["id"] == fldID, fields)
         if f:
             return f[0]
     return None
예제 #6
0
파일: objects.py 프로젝트: comlorda/nive
    def GetFieldConf(self, fldId):
        """
        Get the FieldConf for the field with id = fldId. Looks up data, file and meta 
        fields.

        If `fldId` is a Field Configuration (``nive.definitions.FieldConf``) the functions
        checks if the field id is defined for the object.

        returns FieldConf or None
        """
        if IFieldConf.providedBy(fldId):
            f = filter(lambda d: d["id"] == fldId.id, self.configuration.data)
            if f:
                return fldId
        else:
            f = filter(lambda d: d["id"] == fldId, self.configuration.data)
            if f:
                return f[0]
        return self.app.GetMetaFld(fldId)
예제 #7
0
파일: search.py 프로젝트: comlorda/nive
    def _GetFieldDefinitions(self, fields, pool_type = None):
        f = []
        for fld in fields:
            if IFieldConf.providedBy(fld):
                f.append(fld)
                continue
            if not isinstance(fld, basestring):
                continue
            if fld in ("__preview__",):
                continue
            # skip custom flds
            if fld[0] == "+":
                continue
            # Aggregate functions, custom flds
            if fld[0] == "-":
                f.append(FieldConf(**{"id": fld, "name": fld, "datatype": "string"}))
                continue

            fl = self.app.GetFld(fld, pool_type)
            if fl:
                f.append(fl)
        return f
예제 #8
0
파일: helper.py 프로젝트: nive-cms/nive
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