Пример #1
0
def register_type_impl(
    config, cls, tinfo, name, fieldset,
    permission = ptah.NOT_ALLOWED, fieldNames=None, **kw):

    # generate schema
    if fieldset is None:
        fieldset = ptah.generate_fieldset(
            cls, fieldNames=fieldNames, namesFilter=names_filter)
        log.info("Generating fieldset for %s content type.", cls)

    if 'global_allow' not in kw and not issubclass(cls, Content):
        kw['global_allow'] = False

    tinfo.__dict__.update(kw)

    if fieldset is not None:
        tinfo.fieldset = fieldset

    tinfo.cls = cls
    tinfo.permission = permission

    config.get_cfg_storage(TYPES_DIR_ID)[tinfo.__uri__] = tinfo

    # sql query for content resolver
    cls.__uri_sql_get__ = ptah.QueryFreezer(
        lambda: Session.query(cls)
        .filter(cls.__uri__ == sqla.sql.bindparam('uri')))

    # build cms actions
    build_class_actions(cls)
Пример #2
0
    def __call__(self, request=None):
        root = self._sql_get_root.first(name=self.name, type=self.tinfo.__uri__)
        if root is None:
            root = self.tinfo.create(title=self.title)
            root.__name_id__ = self.name
            root.__path__ = '/%s/'%root.__uri__
            Session.add(root)
            Session.flush()

        root.__root_path__ = self.path
        root.__parent__ = policy = self.policy(request)
        root.__default_root__ = self.default_root

        set_policy(policy)

        if request is not None:
            request.root = root
        return root
Пример #3
0
    def create(self, parent=None):
        blob = Blob(__parent__=parent)
        Session.add(blob)
        Session.flush()

        return blob
Пример #4
0
                if isinstance(tinfo, basestring):
                    tinfo = Types.get('cms+type:%s'%tinfo)

                if tinfo and tinfo.isAllowed(container):
                    types.append(tinfo)
        else:
            for tinfo in Types.values():
                if tinfo.global_allow and tinfo.isAllowed(container):
                    types.append(tinfo)

        return types


# we have to generate seperate sql query for each type
_sql_get = ptah.QueryFreezer(
    lambda: Session.query(Content)
    .filter(Content.__uri__ == sqla.sql.bindparam('uri')))


def Type(name, title=None, fieldset=None, **kw):
    """ Declare new type. This function has to be called within a content
    class declaration.

    .. code-block:: python

        class MyContent(ptah.cms.Content):

            __type__ = Type('My content')

    """
    info = config.DirectiveInfo(allowed_scope=('class',))
Пример #5
0
    def __call__(self, request, queries=_path_queries):
        environ = request.environ
        context = root = self.root

        if root.__default_root__ and 'bfg.routes.route' in environ:
            return ResourceTreeTraverser(root)(request)

        path = '/%s/'%'/'.join(traversal_path(environ.get('PATH_INFO','/')))

        vroot_tuple = ()

        l_path = len(root.__root_path__)

        # build paths for all parents in content hierarchy
        idx = 0
        paths = {}
        current = root.__path__
        for sec in path[l_path:].split('/'):
            if sec:
                current = '%s%s/'%(current, sec)
                paths[str(idx)] = current
                idx += 1

        if idx:
            if idx not in queries:
                bindparams = [sql.bindparam(str(p)) for p in range(idx)]

                queries[idx] = ptah.QueryFreezer(
                    lambda: Session.query(Content)\
                        .filter(Content.__path__.in_(bindparams))
                        .order_by(sql.desc(Content.__path__)))

            parents = queries[idx].all(**paths)
        else:
            parents = []

        if parents:
            # set __parent__
            parents[-1].__parent__ = root
            for idx in range(len(parents)-1):
                parents[idx].__parent__ = parents[idx+1]

            context = parents[0]
            node = context.__path__[len(root.__path__):]
            leaf = path[l_path+len(node):].split('/')
            leaf, subpath = leaf[0], leaf[1:]

            return {'context': context,
                    'view_name': leaf,
                    'subpath': subpath,
                    'traversed': traversal_path(node),
                    'virtual_root': root,
                    'virtual_root_path': vroot_tuple,
                    'root': root}
        else:
            vpath_tuple = ()

            leaf = path[l_path:].split('/')
            leaf, subpath = leaf[0], leaf[1:]

            return {'context': context,
                    'view_name': leaf,
                    'subpath': subpath,
                    'traversed': vpath_tuple,
                    'virtual_root': root,
                    'virtual_root_path': (),
                    'root': root}
Пример #6
0
    def __call__(self, request, queries=_path_queries):
        environ = request.environ
        context = root = self.root

        if root.__default_root__ and "bfg.routes.route" in environ:
            return ResourceTreeTraverser(root)(request)

        path = "/%s/" % "/".join(traversal_path(environ.get("PATH_INFO", "/")))

        vroot_tuple = ()
        vpath = path
        vroot_idx = -1

        l_path = len(root.__root_path__)

        # build paths for all parents in content hierarchy
        idx = 0
        paths = {}
        current = root.__path__
        for sec in path[l_path:].split("/"):
            if sec:
                current = "%s%s/" % (current, sec)
                paths[str(idx)] = current
                idx += 1

        if idx:
            if idx not in queries:
                bindparams = [sql.bindparam(str(p)) for p in range(idx)]

                queries[idx] = ptah.QueryFreezer(
                    lambda: Session.query(Content)
                    .filter(Content.__path__.in_(bindparams))
                    .order_by(sql.desc(Content.__path__))
                )

            parents = queries[idx].all(**paths)
        else:
            parents = []

        if parents:
            # set __parent__
            parents[-1].__parent__ = root
            for idx in range(len(parents) - 1):
                parents[idx].__parent__ = parents[idx + 1]

            context = parents[0]
            node = context.__path__[len(root.__path__) :]
            leaf = path[l_path + len(node) :].split("/")
            leaf, subpath = leaf[0], leaf[1:]

            return {
                "context": context,
                "view_name": leaf,
                "subpath": subpath,
                "traversed": traversal_path(node),
                "virtual_root": root,
                "virtual_root_path": vroot_tuple,
                "root": root,
            }
        else:
            vpath_tuple = ()

            leaf = path[l_path:].split("/")
            leaf, subpath = leaf[0], leaf[1:]

            return {
                "context": context,
                "view_name": leaf,
                "subpath": subpath,
                "traversed": vpath_tuple,
                "virtual_root": root,
                "virtual_root_path": (),
                "root": root,
            }