本文整理汇总了Python中models.Subscription.valid_emails方法的典型用法代码示例。如果您正苦于以下问题:Python Subscription.valid_emails方法的具体用法?Python Subscription.valid_emails怎么用?Python Subscription.valid_emails使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Subscription
的用法示例。
在下文中一共展示了Subscription.valid_emails方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import valid_emails [as 别名]
def post(request):
if not request.user.is_superuser:
raise Http404
if request.GET and request.GET.get('sent'):
return render_to_response(request, 'subscribe/message.html', {'message': u'%s писем отправлено.' % request.GET.get('sent')})
form = PostForm(request.POST)
if request.POST and form.is_valid():
log = logging.getLogger('django.email')
subject, content = form.cleaned_data['message'].split("\n", 1)
subject = subject.strip()
count = 0
fails = 0
for s in Subscription.valid_emails():
try:
unsubscribe = u"\n\nЧтобы отписаться от рассылки, перейдите по ссылке\n\nhttp://%s/subscribe/cancel?email=%s&code=%s"\
% (settings.DOMAIN, s.email, s.delete_code)
send_mail(subject, content + unsubscribe, settings.DEFAULT_FROM_EMAIL, [s.email])
count += 1
except Exception, e:
log.error("Cannot send mail: %s", e)
fails += 1
log.info("%s emails sended, %s failed", count, fails)
return HttpResponseRedirect(reverse('post') + '?sent=%s' % count)