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


Python GroupMembership.subscribe_to_newsletter方法代码示例

本文整理汇总了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'))
开发者ID:jiwonlee777,项目名称:tendenci,代码行数:33,代码来源:views.py


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