本文整理汇总了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))
示例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,
})
示例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()
示例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)
示例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)
示例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 ]))