background_job.py 978 B

12345678910111213141516171819202122232425
  1. import requests
  2. from django.conf import settings
  3. from gauth.models import Location
  4. from analytics.send_email import send_email
  5. to = getattr(settings, 'ADMIN_MAINTAINER_EMAILS')
  6. host_url = getattr(settings, 'HOST_URI')
  7. def send_email_weekly_summary():
  8. locations = Location.objects.all()
  9. # locations = Location.objects.filter(location_id='14748677429039074158')
  10. for location in locations:
  11. to.append(location.recipient_email) if location.recipient_email else None
  12. subject = f"Weekly report for {location.care_name}."
  13. url = f'{host_url}/analytics/weekly-report/{location.location_id}'
  14. message_body = requests.get(url).text
  15. message_body += '<br><p>Regards,</p><p>SignatureCare Review Team</p>'
  16. send_email(to_list=to, subject=subject, message=message_body)
  17. if location.recipient_email in to:
  18. to.remove(location.recipient_email)
  19. def background_task_7_days_interval():
  20. send_email_weekly_summary()