adds testing of email
This commit is contained in:
@@ -39,14 +39,14 @@ def rdata(file_obj, rower=rrower()):
|
||||
|
||||
return result
|
||||
|
||||
def processattachment(rower, fileobj, title, uploadoptions):
|
||||
def processattachment(rower, fileobj, title, uploadoptions,testing=False):
|
||||
try:
|
||||
filename = fileobj.name
|
||||
except AttributeError:
|
||||
filename = fileobj[6:]
|
||||
|
||||
workoutid = [
|
||||
make_new_workout_from_email(rower, filename, title)
|
||||
make_new_workout_from_email(rower, filename, title,testing=testing)
|
||||
]
|
||||
if workoutid[0]:
|
||||
link = settings.SITE_URL+reverse(
|
||||
@@ -72,7 +72,7 @@ def processattachment(rower, fileobj, title, uploadoptions):
|
||||
imagename=imagename
|
||||
)
|
||||
try:
|
||||
if workoutid:
|
||||
if workoutid and not testing:
|
||||
email_sent = send_confirm(
|
||||
rower.user, title, link,
|
||||
uploadoptions
|
||||
@@ -80,12 +80,13 @@ def processattachment(rower, fileobj, title, uploadoptions):
|
||||
time.sleep(10)
|
||||
except:
|
||||
try:
|
||||
time.sleep(10)
|
||||
if workoutid:
|
||||
email_sent = send_confirm(
|
||||
rower.user, title, link,
|
||||
uploadoptions
|
||||
)
|
||||
if not testing:
|
||||
time.sleep(10)
|
||||
if workoutid:
|
||||
email_sent = send_confirm(
|
||||
rower.user, title, link,
|
||||
uploadoptions
|
||||
)
|
||||
except:
|
||||
pass
|
||||
|
||||
@@ -95,6 +96,10 @@ class Command(BaseCommand):
|
||||
"""Run the Email processing command """
|
||||
def handle(self, *args, **options):
|
||||
attachments = MessageAttachment.objects.all()
|
||||
if 'testing' in options:
|
||||
testing = options['testing']
|
||||
else:
|
||||
testing = False
|
||||
cntr = 0
|
||||
for attachment in attachments:
|
||||
extension = attachment.document.name[-3:].lower()
|
||||
@@ -118,12 +123,14 @@ class Command(BaseCommand):
|
||||
datafile = zip_file.extract(filename, path='media/')
|
||||
title = os.path.basename(datafile)
|
||||
workoutid = processattachment(
|
||||
rower, datafile, title, uploadoptions
|
||||
rower, datafile, title, uploadoptions,
|
||||
testing=testing
|
||||
)
|
||||
else:
|
||||
# move attachment and make workout
|
||||
workoutid = processattachment(
|
||||
rower, attachment.document, name, uploadoptions
|
||||
rower, attachment.document, name, uploadoptions,
|
||||
testing=testing
|
||||
)
|
||||
|
||||
# We're done with the attachment. It can be deleted
|
||||
@@ -132,7 +139,8 @@ class Command(BaseCommand):
|
||||
except IOError:
|
||||
pass
|
||||
except WindowsError:
|
||||
time.sleep(2)
|
||||
if not testing:
|
||||
time.sleep(2)
|
||||
try:
|
||||
attachment.delete()
|
||||
except WindowsError:
|
||||
|
||||
Reference in New Issue
Block a user