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


Python Groups.joinmsg方法代码示例

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


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

示例1: create

# 需要导入模块: from fas.model import Groups [as 别名]
# 或者: from fas.model.Groups import joinmsg [as 别名]
    def create(self, name, display_name, owner, group_type, invite_only=0,
               needs_sponsor=0, user_can_remove=1, prerequisite='', 
               joinmsg='', apply_rules='None'):
        '''Create a group'''

        groupname = name
        person = People.by_username(turbogears.identity.current.user_name)
        person_owner = People.by_username(owner)

        if not can_create_group(person):
            turbogears.flash(_('Only FAS administrators can create groups.'))
            turbogears.redirect('/')
        try:
            owner = People.by_username(owner)
            group = Groups()
            group.name = name
            group.display_name = display_name
            group.owner_id = person_owner.id
            group.group_type = group_type
            group.needs_sponsor = bool(needs_sponsor)
            if invite_only:
                group.invite_only = True
            else:
                group.invite_only = False
            group.user_can_remove = bool(user_can_remove)
            if prerequisite:
                prerequisite = Groups.by_name(prerequisite)
                group.prerequisite = prerequisite
            group.joinmsg = joinmsg
            group.apply_rules = apply_rules
            # Log group creation
            Log(author_id=person.id, description='%s created group %s' %
                (person.username, group.name))
            session.flush()
        except TypeError:
            turbogears.flash(_("The group: '%s' could not be created.") % groupname)
            return dict()
        else:
            try:
                owner.apply(group, person) # Apply...
                session.flush()
                owner.sponsor(group, person)
                owner.upgrade(group, person)
                owner.upgrade(group, person)
            except KeyError:
                turbogears.flash(_("The group: '%(group)s' has been created, but '%(user)s' could not be added as a group administrator.") % {'group': group.name, 'user': owner.username})
            else:
                fas.fedmsgshim.send_message(topic="group.create", msg={
                    'agent': { 'username': person.username, },
                    'group': { 'name': group.name, },
                })
                turbogears.flash(_("The group: '%s' has been created.") % group.name)
            turbogears.redirect('/group/view/%s' % group.name)
            return dict()
开发者ID:chepioq,项目名称:fas,代码行数:56,代码来源:group.py


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