当前位置: 首页>>代码示例>>Python>>正文


Python Group.get_guest_group方法代码示例

本文整理汇总了Python中flaskbb.user.models.Group.get_guest_group方法的典型用法代码示例。如果您正苦于以下问题:Python Group.get_guest_group方法的具体用法?Python Group.get_guest_group怎么用?Python Group.get_guest_group使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flaskbb.user.models.Group的用法示例。


在下文中一共展示了Group.get_guest_group方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_all

# 需要导入模块: from flaskbb.user.models import Group [as 别名]
# 或者: from flaskbb.user.models.Group import get_guest_group [as 别名]
    def get_all(cls, user):
        """Get all categories with all associated forums.
        It returns a list with tuples. Those tuples are containing the category
        and their associated forums (whose are stored in a list).

        For example::

            [(<Category 1>, [(<Forum 2>, <ForumsRead>), (<Forum 1>, None)]),
             (<Category 2>, [(<Forum 3>, None), (<Forum 4>, None)])]

        :param user: The user object is needed to check if we also need their
                     forumsread object.
        """
        # import Group model locally to avoid cicular imports
        from flaskbb.user.models import Group
        if user.is_authenticated():
            # get list of user group ids
            user_groups = [gr.id for gr in user.groups]
            # filter forums by user groups
            user_forums = Forum.query.filter(Forum.groups.any(
                Group.id.in_(user_groups))
            ).subquery()
            forum_alias = aliased(Forum, user_forums)
            # get all
            forums = cls.query.join(
                forum_alias,
                cls.id == forum_alias.category_id
            ).outerjoin(
                ForumsRead,
                db.and_(
                    ForumsRead.forum_id == forum_alias.id,
                    ForumsRead.user_id == user.id
                )
            ).add_entity(
                forum_alias
            ).add_entity(
                ForumsRead
            ).order_by(
                Category.position, Category.id,  forum_alias.position
            ).all()
        else:
            guest_group = Group.get_guest_group()
            # filter forums by guest groups
            guest_forums = Forum.query.filter(
                Forum.groups.any(Group.id==guest_group.id)
            ).subquery()
            forum_alias = aliased(Forum, guest_forums)
            forums = cls.query.join(
                forum_alias,
                cls.id == forum_alias.category_id
            ).add_entity(
                forum_alias
            ).order_by(
                Category.position, Category.id, forum_alias.position
            ).all()

        return get_categories_and_forums(forums, user)
开发者ID:hifans,项目名称:flaskbb,代码行数:59,代码来源:models.py

示例2: get_forums

# 需要导入模块: from flaskbb.user.models import Group [as 别名]
# 或者: from flaskbb.user.models.Group import get_guest_group [as 别名]
    def get_forums(cls, category_id, user):
        """Get the forums for the category.
        It returns a tuple with the category and the forums with their
        forumsread object are stored in a list.

        A return value can look like this for a category with two forums::

            (<Category 1>, [(<Forum 1>, None), (<Forum 2>, None)])

        :param category_id: The category id
        :param user: The user object is needed to check if we also need their
                     forumsread object.
        """
        from flaskbb.user.models import Group
        if user.is_authenticated:
            # get list of user group ids
            user_groups = [gr.id for gr in user.groups]
            # filter forums by user groups
            user_forums = Forum.query.\
                filter(Forum.groups.any(Group.id.in_(user_groups))).\
                subquery()

            forum_alias = aliased(Forum, user_forums)
            forums = cls.query.\
                filter(cls.id == category_id).\
                join(forum_alias, cls.id == forum_alias.category_id).\
                outerjoin(ForumsRead,
                          db.and_(ForumsRead.forum_id == forum_alias.id,
                                  ForumsRead.user_id == user.id)).\
                add_entity(forum_alias).\
                add_entity(ForumsRead).\
                order_by(forum_alias.position).\
                all()
        else:
            guest_group = Group.get_guest_group()
            # filter forums by guest groups
            guest_forums = Forum.query.\
                filter(Forum.groups.any(Group.id == guest_group.id)).\
                subquery()

            forum_alias = aliased(Forum, guest_forums)
            forums = cls.query.\
                filter(cls.id == category_id).\
                join(forum_alias, cls.id == forum_alias.category_id).\
                add_entity(forum_alias).\
                order_by(forum_alias.position).\
                all()

        if not forums:
            abort(404)

        return get_forums(forums, user)
开发者ID:djsilcock,项目名称:flaskbb,代码行数:54,代码来源:models.py

示例3: decorated

# 需要导入模块: from flaskbb.user.models import Group [as 别名]
# 或者: from flaskbb.user.models.Group import get_guest_group [as 别名]
    def decorated(*args, **kwargs):
        forum_id = kwargs['forum_id'] if 'forum_id' in kwargs else args[1]
        from flaskbb.forum.models import Forum
        from flaskbb.user.models import Group

        # get list of user group ids
        if current_user.is_authenticated():
            user_groups = [gr.id for gr in current_user.groups]
        else:
            user_groups = [Group.get_guest_group().id]

        user_forums = Forum.query.filter(
            Forum.id == forum_id, Forum.groups.any(Group.id.in_(user_groups))
        ).all()

        if len(user_forums) < 1:
            abort(403)

        return func(*args, **kwargs)
开发者ID:abshkd,项目名称:flaskbb,代码行数:21,代码来源:decorators.py


注:本文中的flaskbb.user.models.Group.get_guest_group方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。