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


Python Subscription.update_subscription方法代码示例

本文整理汇总了Python中subscription.models.Subscription.update_subscription方法的典型用法代码示例。如果您正苦于以下问题:Python Subscription.update_subscription方法的具体用法?Python Subscription.update_subscription怎么用?Python Subscription.update_subscription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在subscription.models.Subscription的用法示例。


在下文中一共展示了Subscription.update_subscription方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from subscription.models import Subscription [as 别名]
# 或者: from subscription.models.Subscription import update_subscription [as 别名]
    def post(self, request, *args, **kwargs):

        list_id = kwargs.get('list_id', None)
        email = request.POST.get('email', None)
        name = request.POST.get('name', None)
        action = request.POST.get('action', None)
        channel = request.POST.get('channel', 'general')

        valid = True
        message = ''

        if not (action and list_id):
            valid = False
            message = _(u'Incomplete form')

        try:
            validate_email(email)
        except forms.ValidationError as e:
            valid = False
            message = u'Invalid e-mail address'


        if valid:

            newsletter = Newsletter.objects.get(id=list_id)
            subscription = Subscription.objects.filter(newsletter=newsletter, email=email.strip())

            if action == 'subscribe':

                if subscription.exists() and not subscription[0].opted_out:
                    message = u'You are already subscribed to this newsletter'
                elif subscription.exists():
                    subscription[0].opted_out = None
                    subscription[0].save()
                    subscription[0].subscribe()
                    message = u'Subscription updated'
                else:
                    subscription = Subscription(
                        newsletter=newsletter,
                        email=email,
                        name=name,
                        language=get_language()[0:2],
                        channel=channel
                    )
                    subscription.save()
                    subscription.update_subscription()
                    message = u'You\'ve successfully signed-up for the newsletter. Soon you will receive an email to confirm your subscription.'

            if action == 'unsubscribe':
                if subscription.exists():
                    subscription[0].opted_out = False
                    subscription[0].save()
                    subscription[0].unsubscribe()

        return self.render_json_response(
            {
                'success': valid,
                'message': message,
            })
开发者ID:hzlf,项目名称:openbroadcast.ch,代码行数:61,代码来源:views.py


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