Skip to content

Instantly share code, notes, and snippets.

@augustogoulart
Created May 4, 2017 20:36
Show Gist options
  • Save augustogoulart/a86d05cf8c689dbb843c167b68f176d0 to your computer and use it in GitHub Desktop.
Save augustogoulart/a86d05cf8c689dbb843c167b68f176d0 to your computer and use it in GitHub Desktop.
Send the actual page's link by email
def post_share(request, post_id):
post = get_object_or_404(Post, id=post_id, status='published')
sent = False
if request.method == 'POST':
form = EmailPostForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
post_url = request.build_absolute_uri(post.get_absolute_url())
subject = '{} ({}) recommends you reading "{}"'.format(cd['name'], cd['email'], post.title)
message = 'Read "{}" at {}\n\n{}\'s comments: {}'.format(post.title, post_url, cd['name'], cd['comments'])
send_mail(subject, message, '[email protected]', [cd['to']])
sent = True
else:
form = EmailPostForm()
return render(request, 'core/share.html', {'post': post, 'form': form, 'sent': sent})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment