From d6c971711f5b95119ee4a868559ba0256e95c937 Mon Sep 17 00:00:00 2001 From: Jayaram Pai Date: Thu, 19 Jun 2014 12:06:18 +0530 Subject: added unanswered question notification - beta --- website/urls.py | 1 + website/views.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'website') diff --git a/website/urls.py b/website/urls.py index 5d7a654..d05a5f0 100644 --- a/website/urls.py +++ b/website/urls.py @@ -17,6 +17,7 @@ urlpatterns = patterns('', url(r'^user/(?P\d+)/answers/$', 'website.views.user_answers', name='user_answers'), url(r'^clear-notifications/$', 'website.views.clear_notifications', name='clear_notifications'), url(r'^search/$', 'website.views.search', name='search'), + url(r'^unanswered-notification/$', 'website.views.unanswered_notification', name='unanswered_notification'), # Ajax helpers url(r'^ajax-tutorials/$', 'website.views.ajax_tutorials', name='ajax_tutorials'), diff --git a/website/views.py b/website/views.py index 01f07ed..5a6dd58 100644 --- a/website/views.py +++ b/website/views.py @@ -513,9 +513,37 @@ def forums_mail(to = '', subject='', message=''): # Start of email send email = EmailMultiAlternatives( subject,'', 'forums', - [to], + to.split(','), headers={"Content-type":"text/html;charset=iso-8859-1"} ) email.attach_alternative(message, "text/html") email.send(fail_silently=True) # End of email send + +# daily notifications for unanswered questions. +def unanswered_notification(request): + questions = Question.objects.all() + total_count = 0 + message = """ + The following questions are left unanswered. + Please take a look at them.

+ """ + for question in questions: + if not question.answer_set.count(): + total_count += 1 + message += """ + #{0}
+ Title: {1}
+ Category: {2}
+ Link: {3}
+
+ """.format( + total_count, + question.title, + question.category, + 'http://forums.spoken-tutorial.org/question/' + str(question.id) + ) + to = "rush2jrp@gmail.com, jayaram@iitb.ac.in" + subject = "Unanswered questions in the forums." + forums_mail(to, subject, message) + return HttpResponse(message) -- cgit