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


Python Subscription.save方法代码示例

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


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

示例1: inscricao

# 需要导入模块: from subscription.models import Subscription [as 别名]
# 或者: from subscription.models.Subscription import save [as 别名]
def inscricao(request):
    if request.method == 'POST':
        form = SubscriptionForm(request.POST)
        if form.is_valid():
            subscription = Subscription()
            subscription.nome = form.cleaned_data['nome']
            subscription.cpf = form.cleaned_data['cpf']
            subscription.email = form.cleaned_data['email']
            subscription.fone = form.cleaned_data['fone']
            subscription.save()
            try:
                send_mail(
                    subject = u'Inscrição no EventeX',
                    message = u'Obrigado por se inscrever no EventeX!',
                    from_email = '[email protected]',
                    recipient_list = [request.POST['email']],
                )
            except:
                pass
            return sucesso(request, subscription.pk)
#            messages = (u'Inscrição realizada com sucesso;', u'Aguarde até que sua solicitação de cadastro seja aprovada')
#            return render_to_response('index.html',{'messages':messages, 'subscription': subscription.pk}, context_instance=RequestContext(request))
    else:
        form = SubscriptionForm(initial={
                 'nome':'Entre com o seu nome',
                 'cpf':'Digite o seu CPF sem pontos',
                 'email': 'Informe o seu email',
                 'fone' :  'Qual seu telefone de contato?',
        })
    return render_to_response('subscription/subscription_form.html',{'form': form, 'title' : u'Preencha Sua Inscrição'}, context_instance=RequestContext(request))
开发者ID:iorgama,项目名称:eventex,代码行数:32,代码来源:views.py

示例2: post

# 需要导入模块: from subscription.models import Subscription [as 别名]
# 或者: from subscription.models.Subscription import save [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

示例3: setUp

# 需要导入模块: from subscription.models import Subscription [as 别名]
# 或者: from subscription.models.Subscription import save [as 别名]
    def setUp(self):
        subscriber = Subscription(
            name='Joao Paulo Dubas',
            cpf='12345678901',
            email='[email protected]',
            phone='11-12345678'
        )

        subscriber.save()
开发者ID:joaodubas,项目名称:wttd4,代码行数:11,代码来源:tests_models.py

示例4: test_send_email_after_save_form

# 需要导入模块: from subscription.models import Subscription [as 别名]
# 或者: from subscription.models.Subscription import save [as 别名]
    def test_send_email_after_save_form(self):
        self.assertEqual(len(mail.outbox), 0)

        subscriber = Subscription(
            name='Joao Paulo Dubas',
            cpf='12345678901',
            email='[email protected]',
            phone='11-12345678'
        )
        subscriber.save()

        self.assertEqual(len(mail.outbox), 1)
开发者ID:joaodubas,项目名称:wttd4,代码行数:14,代码来源:tests_models.py

示例5: test_save_subscription

# 需要导入模块: from subscription.models import Subscription [as 别名]
# 或者: from subscription.models.Subscription import save [as 别名]
    def test_save_subscription(self):
        subscriber = Subscription(
            name='Joao Paulo Dubas',
            cpf='12345678901',
            email='[email protected]',
            phone='11-12345678'
        )

        subscriber.save()

        self.assertEqual(subscriber.pk, 1)
        self.assertEqual(subscriber.created_at.date(), date.today())
        self.assertFalse(subscriber.paid)
开发者ID:joaodubas,项目名称:wttd4,代码行数:15,代码来源:tests_models.py

示例6: create

# 需要导入模块: from subscription.models import Subscription [as 别名]
# 或者: from subscription.models.Subscription import save [as 别名]
def create(request):
    form = SubscriptionForm(request.POST)

    if not form.is_valid():
        context = RequestContext(request, {'form': form})
        return render_to_response('subscription/new.html', context)
    
    s = Subscription()
    s.name = form.cleaned_data['name']
    s.cpf = form.cleaned_data['cpf']
    s.email = form.cleaned_data['email']
    s.phone = form.cleaned_data['phone']
    s.save()

    # notifica o cadastro
    send_subscription_email(s)
    return HttpResponseRedirect(reverse('subscription:success', args=[ s.pk ]))
开发者ID:anaclaudia,项目名称:eventex,代码行数:19,代码来源:views.py


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