Mercurial > public > sg101
comparison news/views.py @ 892:79a71b9d0a2a
Use Reply-To header when sending mail from other users.
See issue #81.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 16 Feb 2015 20:30:48 -0600 |
parents | ff645a692791 |
children | 19b86e684cc2 |
comparison
equal
deleted
inserted
replaced
891:24fc302f9076 | 892:79a71b9d0a2a |
---|---|
1 """ | 1 """ |
2 Views for the News application. | 2 Views for the News application. |
3 """ | 3 """ |
4 | 4 |
5 import datetime | 5 import datetime |
6 from django.conf import settings | |
6 from django.shortcuts import render_to_response | 7 from django.shortcuts import render_to_response |
7 from django.template import RequestContext | 8 from django.template import RequestContext |
8 from django.template.loader import render_to_string | 9 from django.template.loader import render_to_string |
9 from django.http import HttpResponseRedirect | 10 from django.http import HttpResponseRedirect |
10 from django.contrib.auth.decorators import login_required | 11 from django.contrib.auth.decorators import login_required |
199 def email_story(request, story_id): | 200 def email_story(request, story_id): |
200 story = get_object_or_404(Story, pk=story_id) | 201 story = get_object_or_404(Story, pk=story_id) |
201 if request.method == 'POST': | 202 if request.method == 'POST': |
202 send_form = SendStoryForm(request.POST) | 203 send_form = SendStoryForm(request.POST) |
203 if send_form.is_valid(): | 204 if send_form.is_valid(): |
205 site = Site.objects.get_current() | |
204 to_name = send_form.name() | 206 to_name = send_form.name() |
205 to_email = send_form.email() | 207 to_email = send_form.email() |
206 from_name = get_full_name(request.user) | 208 from_name = get_full_name(request.user) |
207 from_email = request.user.email | 209 from_email = settings.GPP_NO_REPLY_EMAIL + '@' + site.domain |
208 site = Site.objects.get_current() | |
209 | 210 |
210 msg = render_to_string('news/send_story_email.txt', | 211 msg = render_to_string('news/send_story_email.txt', |
211 { | 212 { |
212 'to_name': to_name, | 213 'to_name': to_name, |
213 'sender_name': from_name, | 214 'sender_name': from_name, |
216 'story_title': story.title, | 217 'story_title': story.title, |
217 'story_link': story.get_absolute_url(), | 218 'story_link': story.get_absolute_url(), |
218 }) | 219 }) |
219 | 220 |
220 subject = 'Interesting Story at ' + site.name | 221 subject = 'Interesting Story at ' + site.name |
221 send_mail(subject, msg, from_email, [to_email]) | 222 send_mail(subject, msg, from_email, [to_email], reply_to=request.user.email) |
222 return HttpResponseRedirect(reverse('news.views.email_thanks')) | 223 return HttpResponseRedirect(reverse('news.views.email_thanks')) |
223 else: | 224 else: |
224 send_form = SendStoryForm() | 225 send_form = SendStoryForm() |
225 | 226 |
226 return render_to_response('news/send_story.html', { | 227 return render_to_response('news/send_story.html', { |