本文整理汇总了Python中tendenci.apps.emails.models.Email.is_blocked方法的典型用法代码示例。如果您正苦于以下问题:Python Email.is_blocked方法的具体用法?Python Email.is_blocked怎么用?Python Email.is_blocked使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tendenci.apps.emails.models.Email
的用法示例。
在下文中一共展示了Email.is_blocked方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: form_detail
# 需要导入模块: from tendenci.apps.emails.models import Email [as 别名]
# 或者: from tendenci.apps.emails.models.Email import is_blocked [as 别名]
def form_detail(request, slug, template="forms/form_detail.html"):
"""
Display a built form and handle submission.
"""
published = Form.objects.published(for_user=request.user)
form = get_object_or_404(published, slug=slug)
if not has_view_perm(request.user,'forms.view_form',form):
raise Http403
# If form has a recurring payment, make sure the user is logged in
if form.recurring_payment:
[email_field] = form.fields.filter(field_type__iexact='EmailVerificationField')[:1] or [None]
if request.user.is_anonymous and not email_field:
# anonymous user - if we don't have the email field, redirect to login
response = redirect('auth_login')
response['Location'] += '?next=%s' % form.get_absolute_url()
return response
if request.user.is_superuser and not email_field:
messages.add_message(request, messages.WARNING,
'Please edit the form to include an email field ' +
'as it is required for setting up a recurring ' +
'payment for anonymous users.')
form_for_form = FormForForm(form, request.user, request.POST or None, request.FILES or None)
if form.custom_payment and not form.recurring_payment:
billing_form = BillingForm(request.POST or None)
if request.user.is_authenticated:
billing_form.initial = {
'first_name':request.user.first_name,
'last_name':request.user.last_name,
'email':request.user.email}
else:
billing_form = None
for field in form_for_form.fields:
field_default = request.GET.get(field, None)
if field_default:
form_for_form.fields[field].initial = field_default
if request.method == "POST":
if form_for_form.is_valid() and (not billing_form or billing_form.is_valid()):
entry = form_for_form.save()
entry.entry_path = request.POST.get("entry_path", "")
if request.user.is_anonymous:
if entry.get_email_address():
emailfield = entry.get_email_address()
firstnamefield = entry.get_first_name()
lastnamefield = entry.get_last_name()
phonefield = entry.get_phone_number()
password = ''
for i in range(0, 10):
password += random.choice(string.ascii_lowercase + string.ascii_uppercase)
user_list = User.objects.filter(email=emailfield).order_by('-last_login')
if user_list:
anonymous_creator = user_list[0]
else:
anonymous_creator = User(username=emailfield[:30], email=emailfield,
first_name=firstnamefield, last_name=lastnamefield)
anonymous_creator.set_password(password)
anonymous_creator.is_active = False
anonymous_creator.save()
anonymous_profile = Profile(user=anonymous_creator, owner=anonymous_creator,
creator=anonymous_creator, phone=phonefield)
anonymous_profile.save()
entry.creator = anonymous_creator
else:
entry.creator = request.user
entry.save()
entry.set_group_subscribers()
# Email
subject = generate_email_subject(form, entry)
email_headers = {} # content type specified below
if form.email_from:
email_headers.update({'Reply-To':form.email_from})
# Email to submitter
# fields aren't included in submitter body to prevent spam
submitter_body = generate_submitter_email_body(entry, form_for_form)
email_from = form.email_from or settings.DEFAULT_FROM_EMAIL
email_to = form_for_form.email_to()
is_spam = Email.is_blocked(email_to)
if is_spam:
# log the spam
description = "Email \"{0}\" blocked because it is listed in email_blocks.".format(email_to)
EventLog.objects.log(instance=form, description=description)
if form.completion_url:
return HttpResponseRedirect(form.completion_url)
return redirect("form_sent", form.slug)
email = Email()
email.subject = subject
email.reply_to = form.email_from
if email_to and form.send_email and form.email_text:
# Send message to the person who submitted the form.
email.recipient = email_to
#.........这里部分代码省略.........