diff --git a/rowers/dataprep.py b/rowers/dataprep.py index 62ff6923..98a55ae2 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -8,6 +8,8 @@ from rowingdata import rowingdata as rrdata from rowingdata import rower as rrower +from shutil import copyfile + from rowingdata import get_file_type, get_empower_rigging from rowers.tasks import handle_sendemail_unrecognized @@ -17,6 +19,7 @@ from pandas import DataFrame, Series from django.utils import timezone from django.utils.timezone import get_current_timezone +from django_mailbox.models import Message,Mailbox,MessageAttachment from time import strftime import arrow @@ -26,7 +29,7 @@ from rowingdata import ( TCXParser, RowProParser, ErgDataParser, CoxMateParser, BoatCoachParser, RowPerfectParser, BoatCoachAdvancedParser, - MysteryParser, BoatCoachOTWParser, + MysteryParser, BoatCoachOTWParser,QuiskeParser, painsledDesktopParser, speedcoachParser, ErgStickParser, SpeedCoach2Parser, FITParser, fitsummarydata, make_cumvalues,cumcpdata, @@ -863,6 +866,11 @@ def handle_nonpainsled(f2, fileformat, summary=''): row = MysteryParser(f2) hasrecognized = True + # handle Quiske + if (fileformat == 'quiske'): + row = QuiskeParser(f2) + hasrecognized = True + # handle RowPerfect if (fileformat == 'rowperfect3'): row = RowPerfectParser(f2) @@ -975,14 +983,24 @@ def new_workout_from_file(r, f2, inboard = 0.88 if len(fileformat) == 3 and fileformat[0] == 'zip': f_to_be_deleted = f2 - title = os.path.basename(f2) - res = myqueue( - queuelow, - handle_zip_file, - r.user.email, - title, - f2 - ) + workoutsbox = Mailbox.objects.filter(name='workouts')[0] + msg = Message(mailbox=workoutsbox, + from_header=r.user.email, + subject = title) + msg.save() + f3 = 'media/mailbox_attachments/'+f2[6:] + copyfile(f2,f3) + f3 = f3[6:] + a = MessageAttachment(message=msg,document=f3) + a.save() + +# res = myqueue( +# queuelow, +# handle_zip_file, +# r.user.email, +# title, +# f2 +# ) return -1, message, f2 diff --git a/rowers/management/commands/processemail.py b/rowers/management/commands/processemail.py index 996d6bbc..d35156fe 100644 --- a/rowers/management/commands/processemail.py +++ b/rowers/management/commands/processemail.py @@ -93,6 +93,15 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False): return workoutid class Command(BaseCommand): + def add_arguments(self, parser): + parser.add_argument( + '--testing', + action='store_true', + dest='testing', + default=False, + help="Run in testing mode, don't send emails", + ) + """Run the Email processing command """ def handle(self, *args, **options): attachments = MessageAttachment.objects.all() @@ -105,7 +114,11 @@ class Command(BaseCommand): extension = attachment.document.name[-3:].lower() try: message = Message.objects.get(id=attachment.message_id) - body = "\n".join(message.text.splitlines()) + if message.text: + body = "\n".join(message.text.splitlines()) + else: + body = message.body + uploadoptions = uploads.upload_options(body) from_address = message.from_address[0].lower() name = message.subject @@ -119,9 +132,13 @@ class Command(BaseCommand): for rower in rowers: if extension == 'zip': zip_file = zipfile.ZipFile(attachment.document) - for filename in zip_file.namelist(): + for id,filename in enumerate(zip_file.namelist()): datafile = zip_file.extract(filename, path='media/') - title = os.path.basename(datafile) + if id>0: + title = name+' ('+str(id+1)+')' + else: + title = name + workoutid = processattachment( rower, datafile, title, uploadoptions, testing=testing diff --git a/rowers/models.py b/rowers/models.py index ef3d25e0..ab94a5d7 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -2,6 +2,8 @@ from __future__ import unicode_literals from django.db import models from django.contrib.auth.models import User +from django.core.validators import validate_email +from django.core.exceptions import ValidationError from django import forms from django.forms import ModelForm from django.dispatch import receiver @@ -941,15 +943,50 @@ class AccountRowerForm(ModelForm): 'defaulttimezone','showfavoritechartnotes', 'defaultlandingpage'] + def clean_email(self): + email = self.cleaned_data.get('email') + + try: + validate_email(email) + except ValidationError: + raise forms.ValidationError( + 'Please enter a valid email address') + + try: + match = User.objects.get(email__iexact=email) + if self.instance.user == match: + return email + except User.DoesNotExist: + return email + + raise forms.ValidationError('This email address is not allowed') + + + class UserForm(ModelForm): class Meta: model = User fields = ['first_name','last_name','email'] + def clean_email(self): + email = self.cleaned_data.get('email') - def clean(self): - cleaned_data = super(UserForm, self).clean() + try: + validate_email(email) + except ValidationError: + raise forms.ValidationError( + 'Please enter a valid email address') + + try: + match = User.objects.get(email__iexact=email) + if self.instance == match: + return email + except User.DoesNotExist: + return email + raise forms.ValidationError('This email address is not allowed') + + # Form to set rower's Heart Rate zones, including test routines # to enable consistency class RowerForm(ModelForm): diff --git a/rowers/templates/document_form.html b/rowers/templates/document_form.html index 7ad85c58..23888508 100644 --- a/rowers/templates/document_form.html +++ b/rowers/templates/document_form.html @@ -15,7 +15,10 @@ {% endblock %} - {% block content %} +{% block content %} +
Drag and drop files here
+