Exemple #1
0
    def get_components(self, table, names=None):
        """
            Finds components of a table

            @param table: the table or table name
            @param names: a list of components names to limit the search to,
                          None or empty list for all available components
        """

        db = current.db

        hooks = Storage()
        single = False
        if hasattr(table, "_tablename"):
            tablename = table._tablename
        else:
            tablename = table
            self.load(tablename)
            if tablename not in db:
                # Primary table not defined
                return None
            table = db[tablename]
        if isinstance(names, str):
            single = True
            names = [names]
        h = self.components.get(tablename, None)
        if h:
            self.__get_hooks(hooks, h, names=names)
        if not single or single and not len(hooks):
            supertables = self.get_config(tablename, "super_entity")
            if supertables:
                if not isinstance(supertables, (list, tuple)):
                    supertables = [supertables]
                for s in supertables:
                    h = self.components.get(s._tablename, None)
                    if h:
                        self.__get_hooks(hooks, h, names=names, supertable=s)

        components = Storage()
        for alias in hooks:
            hook = hooks[alias]
            self.load(hook.tablename)
            if hook.tablename not in db:
                continue
            if hook.linktable:
                self.load(hook.linktable)
                if hook.linktable not in db:
                    continue
            component = Storage(values=hook.values,
                                multiple=hook.multiple)
            component.tablename = hook.tablename
            component.table = db[hook.tablename]
            prefix, name = hook.tablename.split("_", 1)
            component.prefix = prefix
            component.name = name
            component.alias = alias
            if hook.supertable is not None:
                joinby = hook.supertable._id.name
            else:
                joinby = hook.fkey
            if hook.pkey is None:
                if hook.supertable is not None:
                    component.pkey = joinby
                else:
                    component.pkey = table._id.name
            else:
                component.pkey = hook.pkey
            if hook.linktable is not None:
                if hook.actuate:
                    component.actuate = hook.actuate
                else:
                    component.actuate = "link"
                component.linktable = db[hook.linktable]
                if hook.fkey is None:
                    component.fkey = component.table._id.name
                else:
                    component.fkey = hook.fkey
                component.lkey = hook.lkey
                component.rkey = hook.rkey
                component.autocomplete = hook.autocomplete
                component.autodelete = hook.autodelete
            else:
                component.linktable = None
                component.fkey = hook.fkey
                component.lkey = component.rkey = None
                component.actuate = None
                component.autocomplete = None
                component.autodelete = None
            components.update({alias:component})
        return components
Exemple #2
0
    def get_components(cls, table, names=None):
        """
            Finds components of a table

            @param table: the table or table name
            @param names: a list of components names to limit the search to,
                          None or empty list for all available components
        """

        components = current.model.components

        load = cls.table
        get_hooks = cls.__get_hooks

        hooks = Storage()
        single = False
        if type(table) is Table:
            tablename = table._tablename
        else:
            tablename = table
            table = load(tablename)
            if table is None:
                # Primary table not defined
                return None
        if isinstance(names, str):
            single = True
            names = [names]
        h = components.get(tablename, None)
        if h:
            get_hooks(hooks, h, names=names)
        if not single or single and not len(hooks):
            supertables = cls.get_config(tablename, "super_entity")
            if supertables:
                if not isinstance(supertables, (list, tuple)):
                    supertables = [supertables]
                for s in supertables:
                    if isinstance(s, str):
                        s = load(s)
                    if s is None:
                        continue
                    h = components.get(s._tablename, None)
                    if h:
                        get_hooks(hooks, h, names=names, supertable=s)

        components = Storage()
        for alias in hooks:

            hook = hooks[alias]
            tn = hook.tablename
            lt = hook.linktable

            ctable = load(tn)
            if ctable is None:
                continue

            if lt:
                ltable = load(lt)
                if ltable is None:
                    continue
            else:
                ltable = None

            prefix, name = tn.split("_", 1)
            component = Storage(values=hook.values,
                                multiple=hook.multiple,
                                tablename=tn,
                                table=ctable,
                                prefix=prefix,
                                name=name,
                                alias=alias)

            if hook.supertable is not None:
                joinby = hook.supertable._id.name
            else:
                joinby = hook.fkey

            if hook.pkey is None:
                if hook.supertable is not None:
                    component.pkey = joinby
                else:
                    component.pkey = table._id.name
            else:
                component.pkey = hook.pkey

            if ltable is not None:

                if hook.actuate:
                    component.actuate = hook.actuate
                else:
                    component.actuate = "link"
                component.linktable = ltable

                if hook.fkey is None:
                    component.fkey = ctable._id.name
                else:
                    component.fkey = hook.fkey

                component.lkey = hook.lkey
                component.rkey = hook.rkey
                component.autocomplete = hook.autocomplete
                component.autodelete = hook.autodelete

            else:
                component.linktable = None
                component.fkey = hook.fkey
                component.lkey = component.rkey = None
                component.actuate = None
                component.autocomplete = None
                component.autodelete = None

            if hook.filterby is not None:
                component.filterby = hook.filterby

            if hook.filterfor is not None:
                component.filterfor = hook.filterfor

            components[alias] = component
        return components
Exemple #3
0
    def get_components(self, table, names=None):
        """
            Finds components of a table

            @param table: the table or table name
            @param names: a list of components names to limit the search to,
                          None or empty list for all available components
        """

        db = current.db

        hooks = Storage()
        single = False
        if hasattr(table, "_tablename"):
            tablename = table._tablename
        else:
            tablename = table
            self.load(tablename)
            if tablename not in db:
                # Primary table not defined
                return None
            table = db[tablename]
        if isinstance(names, str):
            single = True
            names = [names]
        h = self.components.get(tablename, None)
        if h:
            self.__get_hooks(hooks, h, names=names)
        if not single or single and not len(hooks):
            supertables = self.get_config(tablename, "super_entity")
            if supertables:
                if not isinstance(supertables, (list, tuple)):
                    supertables = [supertables]
                for s in supertables:
                    h = self.components.get(s._tablename, None)
                    if h:
                        self.__get_hooks(hooks, h, names=names, supertable=s)

        components = Storage()
        for alias in hooks:
            hook = hooks[alias]
            self.load(hook.tablename)
            if hook.tablename not in db:
                continue
            if hook.linktable:
                self.load(hook.linktable)
                if hook.linktable not in db:
                    continue
            component = Storage(values=hook.values, multiple=hook.multiple)
            component.tablename = hook.tablename
            component.table = db[hook.tablename]
            prefix, name = hook.tablename.split("_", 1)
            component.prefix = prefix
            component.name = name
            component.alias = alias
            if hook.supertable is not None:
                joinby = hook.supertable._id.name
            else:
                joinby = hook.fkey
            if hook.pkey is None:
                if hook.supertable is not None:
                    component.pkey = joinby
                else:
                    component.pkey = table._id.name
            else:
                component.pkey = hook.pkey
            if hook.linktable is not None:
                if hook.actuate:
                    component.actuate = hook.actuate
                else:
                    component.actuate = "link"
                component.linktable = db[hook.linktable]
                if hook.fkey is None:
                    component.fkey = component.table._id.name
                else:
                    component.fkey = hook.fkey
                component.lkey = hook.lkey
                component.rkey = hook.rkey
                component.autocomplete = hook.autocomplete
                component.autodelete = hook.autodelete
            else:
                component.linktable = None
                component.fkey = hook.fkey
                component.lkey = component.rkey = None
                component.actuate = None
                component.autocomplete = None
                component.autodelete = None
            components.update({alias: component})
        return components