本文整理汇总了Python中mozillians.groups.models.Group.add_member方法的典型用法代码示例。如果您正苦于以下问题:Python Group.add_member方法的具体用法?Python Group.add_member怎么用?Python Group.add_member使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozillians.groups.models.Group
的用法示例。
在下文中一共展示了Group.add_member方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: group_add_edit
# 需要导入模块: from mozillians.groups.models import Group [as 别名]
# 或者: from mozillians.groups.models.Group import add_member [as 别名]
def group_add_edit(request, url=None):
"""
Add or edit a group. (If a url is passed in, we're editing.)
"""
profile = request.user.userprofile
if url:
# Get the group to edit
group = get_object_or_404(Group, url=url)
# Only a group curator or an admin is allowed to edit a group
is_curator = profile == group.curator
if not (is_curator or request.user.is_superuser):
messages.error(request, _('You must be a curator or an admin to edit a group'))
return redirect(reverse('groups:show_group', args=[group.url]))
else:
group = Group(curator=profile)
form_class = SuperuserGroupForm if request.user.is_superuser else GroupForm
form = form_class(request.POST or None, instance=group)
if form.is_valid():
group = form.save()
# Ensure curator is in the group when it's created
if profile == group.curator and not group.has_member(profile):
group.add_member(profile)
return redirect(reverse('groups:show_group', args=[group.url]))
context = {
'form': form,
'creating': url is None,
'group': group if url else None,
}
return render(request, 'groups/add_edit.html', context)