本文整理汇总了Python中fas.model.Groups.apply_rules方法的典型用法代码示例。如果您正苦于以下问题:Python Groups.apply_rules方法的具体用法?Python Groups.apply_rules怎么用?Python Groups.apply_rules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fas.model.Groups
的用法示例。
在下文中一共展示了Groups.apply_rules方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from fas.model import Groups [as 别名]
# 或者: from fas.model.Groups import apply_rules [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()