@@ -227,31 +227,37 @@ def question_answer(request):
227227 notification .qid = qid
228228 notification .aid = answer .id
229229 notification .save ()
230-
231230 user = User .objects .get (id = question .uid )
232- # Sending email when an answer is posted
233- subject = 'Question has been answered'
234- message = """
235- Dear {0}<br><br>
236- Your question titled <b>"{1}"</b> has been answered.<br>
237- Link: {2}<br><br>
238- Regards,<br>
239- Spoken Tutorial Forums
240- """ .format (
241- user .username ,
242- question .title ,
243- 'http://forums.spoken-tutorial.org/question/' + str (question .id ) + "#answer" + str (answer .id )
244- )
245-
246- email = EmailMultiAlternatives (
247- subject , '' , 'forums' ,
248- [user .email ],
249- headers = {"Content-type" : "text/html;charset=iso-8859-1" }
250- )
251-
252- email .attach_alternative (message , "text/html" )
253- email .send (fail_silently = True )
254- # End of email send
231+
232+ # Sending email when an answer is posted and user answering the question has verified role in spoken
233+ try :
234+ ans_user = User .objects .get (id = answer .uid )
235+ user_has_role = has_role (ans_user )
236+ if user_has_role :
237+ subject = 'Question has been answered'
238+ message = """
239+ Dear {0}<br><br>
240+ Your question titled <b>"{1}"</b> has been answered.<br>
241+ Link: {2}<br><br>
242+ Regards,<br>
243+ Spoken Tutorial Forums
244+ """ .format (
245+ user .username ,
246+ question .title ,
247+ 'http://forums.spoken-tutorial.org/question/' + str (question .id ) + "#answer" + str (answer .id )
248+ )
249+
250+ email = EmailMultiAlternatives (
251+ subject , '' , 'forums' ,
252+ [user .email ],
253+ headers = {"Content-type" : "text/html;charset=iso-8859-1" }
254+ )
255+
256+ email .attach_alternative (message , "text/html" )
257+ email .send (fail_silently = True )
258+ # End of email send
259+ except User .DoesNotExist as e :
260+ pass
255261 return HttpResponseRedirect ('/question/' + str (qid ) + "#answer" + str (answer .id ))
256262 return HttpResponseRedirect ('/' )
257263
@@ -452,24 +458,26 @@ def new_question(request):
452458 question .status = 2 # mark as spam by default for non verified users
453459
454460 question .save ()
455- subject = 'New Forum Question'
456- message = f"""
457- The following new question has been posted in the Spoken Tutorial Forum: <br>
458- Title: <b>{ question .title } </b><br>
459- Category: <b>{ question .category } </b><br>
460- Tutorial: <b>{ question .tutorial } </b><br>
461- Link: <a href="http://forums.spoken-tutorial.org/question/{ question .id } ">
462- http://forums.spoken-tutorial.org/question/{ question .id }
463- </a><br>
464- Question: <b>{ question .body } </b><br>
465- """
466- email = EmailMultiAlternatives (
467- subject , '' , 'forums' ,
468- ['team@spoken-tutorial.org' , 'team@fossee.in' ],
469- headers = {"Content-type" : "text/html;charset=iso-8859-1" }
470- )
471- email .attach_alternative (message , "text/html" )
472- email .send (fail_silently = True )
461+ #send update mail only for verified users, to avoid spam mail
462+ if user_has_role :
463+ subject = 'New Forum Question'
464+ message = f"""
465+ The following new question has been posted in the Spoken Tutorial Forum: <br>
466+ Title: <b>{ question .title } </b><br>
467+ Category: <b>{ question .category } </b><br>
468+ Tutorial: <b>{ question .tutorial } </b><br>
469+ Link: <a href="http://forums.spoken-tutorial.org/question/{ question .id } ">
470+ http://forums.spoken-tutorial.org/question/{ question .id }
471+ </a><br>
472+ Question: <b>{ question .body } </b><br>
473+ """
474+ email = EmailMultiAlternatives (
475+ subject , '' , 'forums' ,
476+ ['team@spoken-tutorial.org' , 'team@fossee.in' ],
477+ headers = {"Content-type" : "text/html;charset=iso-8859-1" }
478+ )
479+ email .attach_alternative (message , "text/html" )
480+ email .send (fail_silently = True )
473481 return HttpResponseRedirect ('/' )
474482
475483 # If form not valid -> re-render with errors
@@ -829,7 +837,7 @@ def forums_mail(to='', subject='', message=''):
829837
830838
831839def unanswered_notification (request ):
832- questions = Question .objects .all ( )
840+ questions = Question .objects .filter ( status = 1 )
833841 total_count = 0
834842 message = """
835843 The following questions are left unanswered.
0 commit comments