本文整理汇总了Python中tendenci.apps.user_groups.models.GroupMembership.subscribe_to_newsletter方法的典型用法代码示例。如果您正苦于以下问题:Python GroupMembership.subscribe_to_newsletter方法的具体用法?Python GroupMembership.subscribe_to_newsletter怎么用?Python GroupMembership.subscribe_to_newsletter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tendenci.apps.user_groups.models.GroupMembership
的用法示例。
在下文中一共展示了GroupMembership.subscribe_to_newsletter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: group_membership_self_add
# 需要导入模块: from tendenci.apps.user_groups.models import GroupMembership [as 别名]
# 或者: from tendenci.apps.user_groups.models.GroupMembership import subscribe_to_newsletter [as 别名]
def group_membership_self_add(request, slug, user_id):
group = get_object_or_404(Group, slug=slug)
user = get_object_or_404(User, pk=user_id)
if not has_view_perm(request.user,'user_groups.view_group', group) and not group.allow_self_add:
raise Http403
group_membership = GroupMembership.objects.filter(member=user, group=group)
if not group_membership:
group_membership = GroupMembership()
group_membership.group = group
group_membership.member = user
group_membership.creator_id = user.id
group_membership.creator_username = user.username
group_membership.owner_id = user.id
group_membership.owner_username = user.username
group_membership.save()
EventLog.objects.log(instance=group_membership)
if group_membership.is_newsletter_subscribed:
group_membership.subscribe_to_newsletter()
messages.add_message(request, messages.SUCCESS, _('Successfully added yourself to group %(grp)s' % {'grp':group}))
else:
messages.add_message(request, messages.INFO, _('You are already in the group %(grp)s' % {'grp': group}))
return HttpResponseRedirect(reverse('group.search'))