Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Sending html/text emails based on user input. Just need to add some v…

…alidation and potential cleanups. The form is kinda ugly.
  • Loading branch information...
commit da7e36db2ef92a42a7870fa4e8578d2eaa9d2726 1 parent 079e0b0
@samuelclay authored
View
25 apps/reader/views.py
@@ -4,6 +4,7 @@
from django.shortcuts import render_to_response, get_object_or_404
from django.contrib.auth.decorators import login_required
from django.template import RequestContext
+from django.template.loader import render_to_string
from django.db import IntegrityError
from django.views.decorators.cache import never_cache
from django.core.urlresolvers import reverse
@@ -13,6 +14,8 @@
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, Http404
from django.conf import settings
from django.core.mail import mail_admins
+from django.core.validators import email_re
+from django.core.mail import EmailMultiAlternatives
from collections import defaultdict
from operator import itemgetter
from mongoengine.queryset import OperationError
@@ -960,13 +963,25 @@ def mark_story_as_unstarred(request):
@json.json_view
def send_story_email(request):
code = 1
+ message = 'OK'
story_id = request.POST['story_id']
feed_id = request.POST['feed_id']
to_address = request.POST['to']
from_name = request.POST['from']
comments = request.POST['comments']
-
- story = MStory.objects(story_feed_id=feed_id, story_guid=story_id)[0]
- print story
-
- return {'code': code}
+ from_email = 'share@newsblur.com'
+
+ if not email_re.match(to_address):
+ code = -1
+ message = 'You need to send the email to a valid email address.'
+ else:
+ story = MStory.objects(story_feed_id=feed_id, story_guid=story_id)[0]
+ feed = Feed.objects.get(pk=story.story_feed_id)
+ text = render_to_string('mail/email_story_text.xhtml', locals())
+ html = render_to_string('mail/email_story_html.xhtml', locals())
+ subject = "%s is sharing a story with you: \"%s\"" % (from_name, story.story_title)
+ msg = EmailMultiAlternatives(subject, text, from_email, [to_address])
+ msg.attach_alternative(html, "text/html")
+ msg.send()
+
+ return {'code': code, 'message': message}
View
1  media/js/newsblur/modal.js
@@ -40,6 +40,7 @@ NEWSBLUR.Modal.prototype = {
},
close: function() {
+ $('.NB-modal-loading', this.$modal).removeClass('NB-active');
$.modal.close();
}
View
6 media/js/newsblur/reader_send_email.js
@@ -26,6 +26,7 @@ NEWSBLUR.ReaderSendEmail.prototype = _.extend({}, NEWSBLUR.Modal.prototype, {
var self = this;
this.$modal = $.make('div', { className: 'NB-modal-email NB-modal' }, [
+ $.make('span', { className: 'NB-modal-loading NB-spinner'}),
$.make('h2', { className: 'NB-modal-title' }, 'Send Story by Email'),
$.make('h2', { className: 'NB-modal-subtitle' }, [
$.make('div', { className: 'NB-modal-email-story-title' }, this.story.story_title),
@@ -60,12 +61,14 @@ NEWSBLUR.ReaderSendEmail.prototype = _.extend({}, NEWSBLUR.Modal.prototype, {
},
save: function(e) {
+ var self = this;
var from = $('input[name=from]', this.$modal).val();
var to = $('input[name=to]', this.$modal).val();
var comments = $('textarea', this.$modal).val();
var $save = $('input[type=submit]', this.$modal);
$save.addClass('NB-disabled').val('Sending...');
+ $('.NB-modal-loading', this.$modal).addClass('NB-active');
this.model.send_story_email({
story_id : this.story_id,
@@ -74,7 +77,8 @@ NEWSBLUR.ReaderSendEmail.prototype = _.extend({}, NEWSBLUR.Modal.prototype, {
to : to,
comments : comments
}, this.close, function(error) {
- $save.removeClass('NB-disabled').val('Send Email');
+ $('.NB-modal-loading', self.$modal).removeClass('NB-active');
+ $save.removeClass('NB-disabled').val('Send this story');
});
},
View
2  templates/base.html
@@ -30,7 +30,7 @@
'hide_read_feeds' : 0,
'show_tooltips' : 1,
'feed_order' : 'ALPHABETICAL',
- 'hide_story_changes' : 0,
+ 'hide_story_changes' : 1,
'feed_view_single_story' : 0,
'view_settings' : {},
'collapsed_folders' : [],
View
18 templates/mail/email_story_html.xhtml
@@ -0,0 +1,18 @@
+<p>{{ from_name }} is sharing a story with you entitled "{{ story.story_title }}". This story is from {{ feed.feed_title }}.</p>
+
+{% if comments %}
+<p>{{ from_name }} writes:<br />
+"{{ comments }}"</p>
+{% endif %}
+
+<p>--</p>
+
+<h2>{{ story.story_title }}</h2>
+
+<a href="{{ story.story_permalink }}">{{ story.story_permalink }}</a>
+
+<p>{{ story.story_content }}</p>
+
+<p>--</p>
+
+<p>Sent from NewsBlur - <a href="http://www.newsblur.com">www.newsblur.com</a> - a visual feed reader with intelligence.</p>
View
18 templates/mail/email_story_text.xhtml
@@ -0,0 +1,18 @@
+{{ from_name }} is sharing a story with you entitled "{{ story.story_title }}". This story is from {{ feed.feed_title }}.
+
+{% if comments %}
+{{ from_name }} writes:
+"{{ comments }}"
+{% endif %}
+
+--
+
+{{ story.story_title }}
+
+{{ story.story_permalink }}
+
+{{ story.story_content }}
+
+--
+
+Sent from NewsBlur - www.newsblur.com - a visual feed reader with intelligence.
Please sign in to comment.
Something went wrong with that request. Please try again.