Last active
December 15, 2017 21:08
-
-
Save bencleary/1da04f1e16dbf5b740ed138a3337cc0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.management.base import BaseCommand, CommandError | |
from crunchy_waffles_app.models import * | |
class Command(BaseCommand): | |
help = 'Runs through email queue and sends emails' | |
def add_arguments(self, parser): | |
parser.add_argument('--id') | |
def handle(self, *args, **options): | |
if options['id']: | |
self.send_email(email) | |
email.delete() | |
else: | |
emails = EmailQueue.EmailManager.emails() | |
for email in emails: | |
self.send_email(email) | |
email.delete() | |
def send_email(self, email): | |
try: | |
# send logic would allow for success or fail result, for this example just print out to console | |
print("Email sent to - {0}".format(email.auction.owner.email)) | |
except: | |
raise CommandError("Email could not send for reason XYZ") | |
def update_bid_row(self, bid): | |
bid.email_sent = True | |
bid.email_sent_time = timezone.now() | |
bid.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment