Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.12 KB | None | 0 0
  1. """
  2. mysite/                 <-- project directory
  3. |-- core/                        <-- app directory
  4. |    |-- management/
  5.           +--__init__.py
  6. |    |    +-- commands/
  7.                +-- __init__.py
  8. |    |         +-- sendreport
  9. """
  10.  
  11.  
  12.  
  13. from django.core.management.base import BaseCommand
  14. from django.utils import timezone
  15. from django.contrib import messages
  16. from django.template.loader import get_template
  17. from django.utils import timezone
  18. from datetime import datetime
  19. from django.conf import settings
  20. import smtplib
  21. from email.mime.text import MIMEText
  22. from email.mime.multipart import MIMEMultipart
  23. from django.core.mail import EmailMultiAlternatives
  24. from models import Cart
  25.  
  26.  
  27. class Command(BaseCommand):
  28.     help = 'Daily report '
  29.  
  30.     def handle(self, *args, **kwargs):
  31.         time = timezone.now().strftime('%X')
  32.         date = datetime.now()
  33.         cart = Cart.objects.filter(date=datetime.now())
  34.         total_price = 0
  35.         cart1 =
  36.   Cart.objects.filter(date=datetime.now(), paid=True)
  37.      
  38.         total_cart = Cart.objects.filter(date=datetime.now(), paid=True).count()
  39.         for i in cart1:
  40.             total_price = total_price+i.price
  41.             subject = "Daily Sales"
  42.             from_email = settings.EMAIL_HOST_USER
  43.             # Now we get the list of emails in a list
  44.             form.
  45.             to_email = ['gospeltruth18@gmail.com']
  46.             #Opening a file in python, with closes the
  47.             file when its done running
  48.             with open(settings.BASE_DIR +
  49.            "/templates/account/change_password_email.txt") as
  50.            sign_up_email_txt_file:
  51.            sign_up_message = sign_up_email_txt_file.read()
  52.            message = EmailMultiAlternatives(subject=subject, body=sign_up_message,from_email=from_email, to=to_email )
  53.            html_template =
  54.  get_template("Administrator/dailyreport.html").render({'qs':cart1, 'total_cart':total_cart, 'total_price':total_price, 'date':date})
  55.            message.attach_alternative(html_template, "text/html")
  56.            message.send()
  57.        self.stdout.write("report sent successful" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement