from django.utils import timezone
from gauth.models import Location
from review.models import Review
from .send_email import send_email
from review.review_utils import get_bad_reviews
def send_email_bad_reviews():
locations = Location.objects.all()
for location in locations:
reviews = get_bad_reviews(location.location_id, hours=6)
total_reviews = reviews.count()
if total_reviews > 0:
to = [location.recipient_email if location.recipient_email else 'bt@bytetrek.com.bd']
subject = f"A bad review has been post in {location.care_name}."
message =f'''
Hi there,
There is {total_reviews} bad reviews has been posted in {location.care_name}. Please, response them ASAP.
Regards,
Byte Trek Limited
' send_email(to_list=to, subject=subject, message=message) def weekly_report(location_id): now = timezone.now() date = now - timezone.timedelta(days=7) reviews = Review.objects.filter(location_id=location_id, create_time__gte=date)