def send_newsletter(post_id): post = Post.objects.get(pk=post_id) if not post.notified: print("send_newsletter activated") site = Site.objects.all()[0] newsletter = Newsletter.objects.all()[0] submission = Submission() message = Message() article = Article() article.url = "http://{}{}".format(site.domain, post.get_absolute_url()) article.title = post.title article.sortorder = 0 message.title = post.title message.newsletter = newsletter message.slug = post.slug message.save() message.articles.add(article, bulk=False) message.save() article.save() submission.newsletter = newsletter submission.message = message submission.save() for s in newsletter.get_subscriptions(): submission.subscriptions.add(s) submission.save() submission.submit() Submission.submit_queue() post.notified = True post.save() print("send_newsletter submitted")
def newsletter_send(request, object_id): import os path = PROJECT_ROOT + "/core/scripts/sendmail_v0.1.py" newsletter = get_object_or_404(Newsletter,id=object_id) os.system('python %s -n %s'%(path,str(object_id))) from newsletter.models import Submission sub = Submission(newsletter=newsletter) sub.save() return render_to_response('newsletter/newsletter_content.html', {'newsletter' : newsletter}, context_instance=RequestContext(request))