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


Python models.Group类代码示例

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


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

示例1: create_default_groups

def create_default_groups():
    """
    This will create the 5 default groups
    """
    for key, value in GROUPS.items():
        group = Group(name=key)

        for k, v in value.items():
            setattr(group, k, v)

        group.save()
开发者ID:hvdklauw,项目名称:flaskbb,代码行数:11,代码来源:populate.py

示例2: create_default_groups

def create_default_groups():
    """This will create the 5 default groups."""
    from flaskbb.fixtures.groups import fixture
    result = []
    for key, value in fixture.items():
        group = Group(name=key)

        for k, v in value.items():
            setattr(group, k, v)

        group.save()
        result.append(group)
    return result
开发者ID:djsilcock,项目名称:flaskbb,代码行数:13,代码来源:populate.py

示例3: create_default_groups

def create_default_groups():
    """
    This will create the 5 default groups
    """
    result = []
    for key, value in GROUPS.items():
        group = Group(name=key)

        for k, v in value.items():
            setattr(group, k, v)

        group.save()
        result.append(group)
    return result
开发者ID:hugleecool,项目名称:flaskbb,代码行数:14,代码来源:populate.py

示例4: get_all

    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,代码行数:57,代码来源:models.py

示例5: get_forums

    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,代码行数:52,代码来源:models.py

示例6: create_user

def create_user(username, password, email, groupname):
    """Creates a user.
    Returns the created user.

    :param username: The username of the user.
    :param password: The password of the user.
    :param email: The email address of the user.
    :param groupname: The name of the group to which the user
                      should belong to.
    """
    if groupname == "member":
        group = Group.get_member_group()
    else:
        group = Group.query.filter(getattr(Group, groupname) == True).first()

    user = User.create(username=username, password=password, email=email,
                       primary_group_id=group.id, activated=True)
    return user
开发者ID:djsilcock,项目名称:flaskbb,代码行数:18,代码来源:populate.py

示例7: decorated

    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,代码行数:19,代码来源:decorators.py

示例8: update_user

def update_user(username, password, email, groupname):
    """Update an existing user.
    Returns the updated user.

    :param username: The username of the user.
    :param password: The password of the user.
    :param email: The email address of the user.
    :param groupname: The name of the group to which the user
                      should belong to.
    """
    user = User.query.filter_by(username=username).first()
    if user is None:
        return None

    if groupname == "member":
        group = Group.get_member_group()
    else:
        group = Group.query.filter(getattr(Group, groupname) == True).first()

    user.password = password
    user.email = email
    user.primary_group_id = group.id
    return user.save()
开发者ID:djsilcock,项目名称:flaskbb,代码行数:23,代码来源:populate.py

示例9: save

 def save(self):
     group = Group(**self.data)
     return group.save()
开发者ID:RJacksonm1,项目名称:flaskbb,代码行数:3,代码来源:forms.py

示例10: save

 def save(self):
     data = self.data
     data.pop('submit', None)
     group = Group(**data)
     return group.save()
开发者ID:abshkd,项目名称:flaskbb,代码行数:5,代码来源:forms.py


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