views.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:munch-core 作者: crunchmail 项目源码 文件源码
def unsubscribe(request, identifier):
    is_test_mail = identifier.startswith('preview')
    if is_test_mail:
        try:
            mail = PreviewMail.objects.get(identifier=identifier)
        except PreviewMail.DoesNotExist:
            return HttpResponseNotFound()
    else:
        try:
            mail = get_mail_by_identifier(identifier)
        except ObjectDoesNotExist:
            return HttpResponseNotFound()

    context = {'mail': mail, 'is_test_mail': is_test_mail}

    if identifier.startswith('c-') and mail.message.external_optout:
        if request.method == 'GET':
            return render(
                request, 'optouts/unsubscribe_external.html', context)
        else:
            return HttpResponseNotAllowed(['GET'])
    else:
        if request.method == 'POST':
            optout_kwargs = {
                'category': mail.get_category(), 'author': mail.get_author()}
            if not is_test_mail:
                OptOut.objects.create_or_update(
                    identifier=mail.identifier,
                    address=mail.recipient,
                    origin=OptOut.BY_WEB,
                    **optout_kwargs)
            return HttpResponseRedirect(
                reverse('unsubscribed', kwargs={'identifier': identifier}))
        else:
            return render(request, 'optouts/unsubscribe.html', context)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号