Pārlūkot izejas kodu

Change negative review notifier email body and subject

Mohidul Islam 4 gadi atpakaļ
vecāks
revīzija
f4472071aa
2 mainītis faili ar 13 papildinājumiem un 11 dzēšanām
  1. 1 1
      analytics/send_email.py
  2. 12 10
      review/background_job.py

+ 1 - 1
analytics/send_email.py

@@ -2,7 +2,7 @@ import requests
 from django.core.mail import EmailMessage
 
 
-def send_email(to_list, subject, message, sender="Byte Trek Ltd. <noreply@bytetrek.com.bd>"):
+def send_email(to_list, subject, message, sender='"Review Monitor" from Byte Trek Ltd. <noreply@bytetrek.com.bd>'):
     msg = EmailMessage(subject, message, sender, to_list)
     msg.content_subtype = "html"  # Main content is now text/html
     return msg.send()

+ 12 - 10
review/background_job.py

@@ -62,31 +62,33 @@ def reply_uncommented_reviews():
 def send_email_bad_reviews():
     locations = Location.objects.all()
     for location in locations:
+        to = settings.ADMIN_MAINTEINER_EMAILS
         reviews = get_bad_reviews(location.location_id, hours=1)
         total_reviews = reviews.count()
         if total_reviews > 0:
-            to = settings.ADMIN_MAINTEINER_EMAILS
             # Add location mainteiner email if it has an email
             to.append(location.recipient_email) if location.recipient_email else None
 
-            subject = f"A negative review has been post in {location.care_name}."
+            subject = f"A negative Google review has been post in {location.care_name}."
             message = f'''
             <p>Hi there, </p>
-            <p>There '''
+            <p>'''
             if total_reviews > 1:
-                tt = f'are {total_reviews} negative reviews has'
+                tt = f'{total_reviews} negative Google reviews have'
             else:
-                tt = f'is a negative review has '
+                tt = f'A negative Google review has '
             message += tt + f'been posted in {location.care_name}.</p>'
             for r in reviews:
-                # link = r.location.review_site_url + '?reviewId='+r.review_id
+                link = f'<p>Link: {r.location.review_site_url}</p>'
                 name = f'<p><b>Reviewer Name:</b> {r.reviewer_name}</p>'
-                rating = f'<p><b>Rating:</b> {str(r.star_rating)} star rating.</p>'
-                comment = f'<p><b>Comment: </b>{r.comment}</p>'
-                message += name + rating + comment
-            message += '<p>Regards,</p><p>Byte Trek Team</p>'
+                rating = f'<p style="color: red"><b>Rating:</b> {str(r.star_rating)} star rating.</p>'
+                comment = f'<p><b>Comment: </b>{r.comment if r.comment else "No comment"}</p>'
+                message += name + rating + comment + link
+            message += '<p>Regards,</p><p>Byte Trek Ltd.</p>'
 
             send_email(to_list=to, subject=subject, message=message)
+            if location.recipient_email in to:
+                to.remove(location.recipient_email)
 
 
 def background_task_6_hours_interval():