|
@@ -1,13 +1,12 @@
|
|
import random
|
|
import random
|
|
from time import sleep
|
|
from time import sleep
|
|
from django.utils import timezone
|
|
from django.utils import timezone
|
|
-from gauth.models import Location
|
|
|
|
-from django.conf import settings
|
|
|
|
-from analytics.send_email import send_email
|
|
|
|
|
|
+from gauth.models import Location, LocationManager
|
|
|
|
+from analytics.background_job import send_email
|
|
from .models import Review, CustomReply, Reply
|
|
from .models import Review, CustomReply, Reply
|
|
from nlu_job.nlu_utils import is_a_name
|
|
from nlu_job.nlu_utils import is_a_name
|
|
from review.review_utils import reply_review
|
|
from review.review_utils import reply_review
|
|
-from review.review_utils import populate_reviews, get_bad_reviews, fetch_batch_of_reviews
|
|
|
|
|
|
+from review.review_utils import get_bad_reviews, fetch_batch_of_reviews
|
|
|
|
|
|
from nameparser import HumanName
|
|
from nameparser import HumanName
|
|
|
|
|
|
@@ -62,21 +61,17 @@ def reply_uncommented_reviews():
|
|
def send_email_bad_reviews():
|
|
def send_email_bad_reviews():
|
|
locations = Location.objects.all()
|
|
locations = Location.objects.all()
|
|
for location in locations:
|
|
for location in locations:
|
|
- to = settings.ADMIN_MAINTAINER_EMAILS
|
|
|
|
reviews = get_bad_reviews(location.location_id, hours=1)
|
|
reviews = get_bad_reviews(location.location_id, hours=1)
|
|
total_reviews = reviews.count()
|
|
total_reviews = reviews.count()
|
|
if total_reviews > 0:
|
|
if total_reviews > 0:
|
|
- # Add location mainteiner email if it has an email
|
|
|
|
- to.append(location.recipient_email) if location.recipient_email else None
|
|
|
|
|
|
+ to = list(LocationManager.objects.filter(location_id=location.location_id).values_list('email', flat=True))
|
|
|
|
|
|
subject = f"A negative Google 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>'''
|
|
|
|
|
|
+ message = '<p>Hi there, </p><p>'
|
|
if total_reviews > 1:
|
|
if total_reviews > 1:
|
|
tt = f'{total_reviews} negative Google reviews have'
|
|
tt = f'{total_reviews} negative Google reviews have'
|
|
else:
|
|
else:
|
|
- tt = f'A negative Google review has '
|
|
|
|
|
|
+ tt = 'A negative Google review has '
|
|
message += tt + f'been posted in {location.care_name}.</p>'
|
|
message += tt + f'been posted in {location.care_name}.</p>'
|
|
for r in reviews:
|
|
for r in reviews:
|
|
link = f'<p>Link: {r.location.review_site_url}</p>'
|
|
link = f'<p>Link: {r.location.review_site_url}</p>'
|
|
@@ -86,9 +81,7 @@ def send_email_bad_reviews():
|
|
message += name + rating + comment + link
|
|
message += name + rating + comment + link
|
|
message += '<p>Regards,</p><p>SignatureCare Review Team.</p>'
|
|
message += '<p>Regards,</p><p>SignatureCare Review Team.</p>'
|
|
|
|
|
|
- send_email(to_list=to, subject=subject, message=message)
|
|
|
|
- if location.recipient_email in to:
|
|
|
|
- to.remove(location.recipient_email)
|
|
|
|
|
|
+ send_email(subject=subject, message_body=message, to_list=to)
|
|
|
|
|
|
|
|
|
|
def background_task_every_hour():
|
|
def background_task_every_hour():
|