示例#1
0
    def recu_query(cls):
        """
        Init select condition of index.

        :return: the query of db.session.
        """
        recursive_t = db.session.query(
            Index.parent.label("pid"),
            Index.id.label("cid"),
            func.cast(Index.id, db.Text).label("path"),
            Index.index_name.label("name"),
            literal_column("1", db.Integer).label("lev")).filter(
            Index.parent == 0,
            Index.is_delete == False). \
            cte(name="recursive_t", recursive=True)

        rec_alias = aliased(recursive_t, name="rec")
        test_alias = aliased(Index, name="t")
        recursive_t = recursive_t.union_all(
            db.session.query(
                test_alias.parent, test_alias.id,
                rec_alias.c.path + '/' + func.cast(test_alias.id, db.Text),
                rec_alias.c.name + '/' + test_alias.index_name,
                rec_alias.c.lev + 1).filter(
                    test_alias.parent == rec_alias.c.cid,
                    test_alias.is_delete == False))

        return recursive_t
示例#2
0
    def recs_query(cls, pid=0):
        """
        Init select condition of index.

        :return: the query of db.session.
        """
        recursive_t = db.session.query(
            Index.parent.label("pid"),
            Index.id.label("cid"),
            func.cast(Index.id, db.Text).label("path"),
            Index.index_name.label("name"),
            # add by ryuu at 1108 start
            Index.index_name_english.label("name_en"),
            # add by ryuu at 1108 end
            literal_column("1", db.Integer).label("lev")).filter(
            Index.parent == pid). \
            cte(name="recursive_t", recursive=True)

        rec_alias = aliased(recursive_t, name="rec")
        test_alias = aliased(Index, name="t")
        recursive_t = recursive_t.union_all(
            db.session.query(
                test_alias.parent,
                test_alias.id,
                rec_alias.c.path + '/' + func.cast(test_alias.id, db.Text),
                rec_alias.c.name + '/' + test_alias.index_name,
                # add by ryuu at 1108 start
                rec_alias.c.name_en + '/' + test_alias.index_name_english,
                # add by ryuu at 1108 end
                rec_alias.c.lev +
                1).filter(test_alias.parent == rec_alias.c.cid))

        return recursive_t
示例#3
0
文件: api.py 项目: weko3-dev35/weko
    def recs_query(cls, pid=0):
        """
        Init select condition of index.

        :return: the query of db.session.
        """
        # !!! Important !!!
        # If add/delete columns in here,
        # please add/delete columns in Indexes.delete function, too.
        recursive_t = db.session.query(
            Index.parent.label("pid"),
            Index.id.label("cid"),
            func.cast(Index.id, db.Text).label("path"),
            Index.index_name.label("name"),
            # add by ryuu at 1108 start
            Index.index_name_english.label("name_en"),
            # add by ryuu at 1108 end
            literal_column("1", db.Integer).label("lev"),
            Index.public_state.label("public_state"),
            Index.public_date.label("public_date"),
            Index.comment.label("comment"),
            Index.browsing_role.label("browsing_role"),
            Index.browsing_group.label("browsing_group")
        ).filter(Index.parent == pid). \
            cte(name="recursive_t", recursive=True)

        rec_alias = aliased(recursive_t, name="rec")
        test_alias = aliased(Index, name="t")
        recursive_t = recursive_t.union_all(
            db.session.query(
                test_alias.parent,
                test_alias.id,
                rec_alias.c.path + '/' + func.cast(test_alias.id, db.Text),
                rec_alias.c.name + '/' + test_alias.index_name,
                # add by ryuu at 1108 start
                rec_alias.c.name_en + '/' + test_alias.index_name_english,
                # add by ryuu at 1108 end
                rec_alias.c.lev + 1,
                test_alias.public_state,
                test_alias.public_date,
                test_alias.comment,
                test_alias.browsing_role,
                test_alias.browsing_group).filter(
                    test_alias.parent == rec_alias.c.cid))

        return recursive_t
示例#4
0
    def recs_root_tree_query(
        cls,
        pid=0,
    ):
        """
        Init select condition of index.

        :return: the query of db.session.
        """
        lang = current_i18n.language
        if lang == 'ja':
            recursive_t = db.session.query(
                Index.parent.label("pid"), Index.id.label("cid"),
                func.cast(Index.id, db.Text).label("path"),
                func.coalesce(Index.index_name,
                              Index.index_name_english).label("name"),
                Index.position, Index.public_state, Index.public_date,
                Index.browsing_role, Index.contribute_role,
                Index.browsing_group, Index.contribute_group, Index.more_check,
                Index.display_no, Index.coverpage_state,
                Index.recursive_coverpage_check,
                literal_column("1", db.Integer).label("lev")).filter(
                    Index.id == pid).cte(name="recursive_t", recursive=True)

            rec_alias = aliased(recursive_t, name="rec")
            test_alias = aliased(Index, name="t")
            recursive_t = recursive_t.union_all(
                db.session.query(
                    test_alias.parent, test_alias.id,
                    rec_alias.c.path + '/' + func.cast(test_alias.id, db.Text),
                    func.coalesce(test_alias.index_name,
                                  test_alias.index_name_english),
                    test_alias.position, test_alias.public_state,
                    test_alias.public_date, test_alias.browsing_role,
                    test_alias.contribute_role, test_alias.browsing_group,
                    test_alias.contribute_group, test_alias.more_check,
                    test_alias.display_no, test_alias.coverpage_state,
                    test_alias.recursive_coverpage_check, rec_alias.c.lev +
                    1).filter(test_alias.parent == rec_alias.c.cid))
        else:
            recursive_t = db.session.query(
                Index.parent.label("pid"),
                Index.id.label("cid"),
                func.cast(Index.id, db.Text).label("path"),
                Index.index_name_english.label("name"),
                Index.position,
                Index.public_state,
                Index.public_date,
                Index.browsing_role,
                Index.contribute_role,
                Index.browsing_group,
                Index.contribute_group,
                Index.more_check,
                Index.display_no,
                Index.coverpage_state,
                Index.recursive_coverpage_check,
                literal_column("1", db.Integer).label("lev")).filter(
                Index.id == pid). \
                cte(name="recursive_t", recursive=True)

            rec_alias = aliased(recursive_t, name="rec")
            test_alias = aliased(Index, name="t")
            recursive_t = recursive_t.union_all(
                db.session.query(
                    test_alias.parent, test_alias.id,
                    rec_alias.c.path + '/' + func.cast(test_alias.id, db.Text),
                    test_alias.index_name_english, test_alias.position,
                    test_alias.public_state, test_alias.public_date,
                    test_alias.browsing_role, test_alias.contribute_role,
                    test_alias.browsing_group, test_alias.contribute_group,
                    test_alias.more_check, test_alias.display_no,
                    test_alias.coverpage_state,
                    test_alias.recursive_coverpage_check, rec_alias.c.lev +
                    1).filter(test_alias.parent == rec_alias.c.cid))

        return recursive_t