diff --git a/rowers/dataprep.py b/rowers/dataprep.py index 98a55ae2..6158431e 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -847,11 +847,7 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower', return (w.id, message) - -def handle_nonpainsled(f2, fileformat, summary=''): - oarlength = 2.89 - inboard = 0.88 - hasrecognized = False +def parsenonpainsled(fileformat,f2,summary): # handle RowPro: if (fileformat == 'rp'): row = RowProParser(f2) @@ -936,6 +932,20 @@ def handle_nonpainsled(f2, fileformat, summary=''): summary = s.summarytext except: pass + hasrecognized = True + + return row,hasrecognized,summary + +def handle_nonpainsled(f2, fileformat, summary=''): + oarlength = 2.89 + inboard = 0.88 + hasrecognized = False + + try: + row,hasrecognized,summary = parsenonpainsled(fileformat,f2,summary) + except: + pass + # Handle c2log if (fileformat == 'c2log' or fileformat == 'rowprolog'): diff --git a/rowers/mailprocessing.py b/rowers/mailprocessing.py index c25fb535..da8073fc 100644 --- a/rowers/mailprocessing.py +++ b/rowers/mailprocessing.py @@ -7,7 +7,12 @@ from rowers.tasks import ( handle_sendemail_unrecognized, handle_sendemail_unrecognizedowner ) -from django_mailbox.models import Message, MessageAttachment +from django_mailbox.models import Message, MessageAttachment,Mailbox + +workoutmailbox = Mailbox.objects.get(name='workouts') +failedmailbox = Mailbox.objects.get(name='Failed') + + from rowers.models import User, Rower, RowerForm from django.core.mail import EmailMessage @@ -148,7 +153,7 @@ def make_new_workout_from_email(rower, datafile, name, cntr=0,testing=False): dosummary = (fileformat != 'fit') if name == '': - name = 'imported through email' + name = 'Workout from Background Queue' id, message = dataprep.save_workout_database( datafilename, rower, diff --git a/rowers/management/commands/processemail.py b/rowers/management/commands/processemail.py index de9d1351..cae0ccb0 100644 --- a/rowers/management/commands/processemail.py +++ b/rowers/management/commands/processemail.py @@ -9,7 +9,7 @@ import time from time import strftime from django.core.management.base import BaseCommand -from django_mailbox.models import Message, MessageAttachment +from django_mailbox.models import Message, MessageAttachment,Mailbox from django.core.urlresolvers import reverse from django.conf import settings @@ -21,6 +21,9 @@ from rowingdata import rowingdata as rrdata import rowers.uploads as uploads from rowers.mailprocessing import make_new_workout_from_email, send_confirm +workoutmailbox = Mailbox.objects.get(name='workouts') +failedmailbox = Mailbox.objects.get(name='Failed') + # If you find a solution that does not need the two paths, please comment! sys.path.append('$path_to_root_of_project$') sys.path.append('$path_to_root_of_project$/$project_name$') @@ -104,7 +107,11 @@ class Command(BaseCommand): """Run the Email processing command """ def handle(self, *args, **options): - attachments = MessageAttachment.objects.all() + messages = Message.objects.filter(mailbox_id = workoutmailbox.id) + message_ids = [m.id for m in messages] + attachments = MessageAttachment.objects.filter( + message_id__in=message_ids + ) if 'testing' in options: testing = options['testing'] else: @@ -114,10 +121,14 @@ class Command(BaseCommand): extension = attachment.document.name[-3:].lower() try: message = Message.objects.get(id=attachment.message_id) - #if message.text: - # body = "\n".join(message.text.splitlines()) - #else: - body = message.get_body() + if message.encoded: +# if message.text: + body = "\n".join(message.text.splitlines()) + else: + body = message.get_body() + + + uploadoptions = uploads.upload_options(body) from_address = message.from_address[0].lower() @@ -162,6 +173,9 @@ class Command(BaseCommand): attachment.delete() except WindowsError: pass + except: + message.mailbox = failedmailbox + message.save() if message.attachments.exists() is False: # no attachments, so can be deleted diff --git a/rowers/templates/document_form.html b/rowers/templates/document_form.html index 2e3c9b6f..21c7d590 100644 --- a/rowers/templates/document_form.html +++ b/rowers/templates/document_form.html @@ -209,11 +209,14 @@ }, success: function(result) { console.log('got something back'); - console.log(result); + console.log(result); if (result.result == 1) { - window.location.href = result.url; - } - } + window.location.href = result.url; + } else { + console.log(result," reloading"); + location.reload(); + }; + } }); return false; }); diff --git a/rowers/testdata/emails/noname b/rowers/testdata/emails/noname new file mode 100644 index 00000000..4eb4a5b2 Binary files /dev/null and b/rowers/testdata/emails/noname differ diff --git a/rowers/tests.py b/rowers/tests.py index 8f54b43e..fb8a67fd 100644 --- a/rowers/tests.py +++ b/rowers/tests.py @@ -48,12 +48,6 @@ class DjangoTestCase(TestCase, MockTestCase): # Create your tests here. -class EmailProcessTest(TestCase): - def test_emailprocessing(self): - out = StringIO() - call_command('processemail', stdout=out) - self.assertIn('Successfully processed email attachments',out.getvalue()) - class C2Objects(DjangoTestCase): def test_strokedata(self): with open('rowers/testdata/c2stroketestdata.txt','r') as infile: @@ -336,11 +330,16 @@ class EmailTests(TestCase): nu = datetime.datetime.now() workoutsbox = Mailbox.objects.create(name='workouts') workoutsbox.save() + failbox = Mailbox.objects.create(name='Failed') + failbox.save() for filename in os.listdir('rowers/testdata/emails'): m = Message(mailbox=workoutsbox, from_header = u.email, - subject = filename) + subject = filename, + body=""" + chart time + """) m.save() a2 = 'media/mailbox_attachments/'+filename copyfile('rowers/testdata/emails/'+filename,a2) diff --git a/rowers/views.py b/rowers/views.py index f475ab3c..542c5ad0 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -8495,6 +8495,7 @@ def workout_upload_view(request, except KeyError: upload_to_tp = False + response = {} if request.method == 'POST': form = DocumentsForm(request.POST,request.FILES) optionsform = UploadOptionsForm(request.POST) diff --git a/static/img/praha.jpeg b/static/img/praha.jpeg new file mode 100644 index 00000000..c2f40b04 Binary files /dev/null and b/static/img/praha.jpeg differ