diff --git a/rowers/management/commands/processemail.py b/rowers/management/commands/processemail.py index 2fc1724f..2f6e6de2 100644 --- a/rowers/management/commands/processemail.py +++ b/rowers/management/commands/processemail.py @@ -55,47 +55,44 @@ class Command(BaseCommand): name = m.subject cntr += 1 # get a list of users - theusers = User.objects.filter(email=from_address) - for u in theusers: - try: - rr = Rower.objects.get(user=u.id) - if extension == 'zip': - z = zipfile.ZipFile(a.document) - for f in z.namelist(): - f2 = z.extract(f,path='media/') - try: - wid = [ - make_new_workout_from_email(rr,f2[6:],name) - ] - res += wid - link = 'http://rowsandall.com/rowers/workout/'+str(wid)+'/edit' - dd = send_confirm(u,name,link) - except: - pass - else: - # move attachment and make workout - try: - wid = [ - make_new_workout_from_email(rr, - a.document, - name) + # theusers = User.objects.filter(email=from_address) + ther = [ + r for r in Rower.objects.all() if r.user.email.lower() == from_address + ] + for rr in ther: + if extension == 'zip': + z = zipfile.ZipFile(a.document) + for f in z.namelist(): + f2 = z.extract(f,path='media/') + try: + wid = [ + make_new_workout_from_email(rr,f2[6:],name) ] res += wid - link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit' - - except: - # replace with code to process error - res += ['fail: '+name] - donotdelete = 1 - try: + link = 'http://rowsandall.com/rowers/workout/'+str(wid)+'/edit' dd = send_confirm(u,name,link) except: pass + else: + # move attachment and make workout + try: + wid = [ + make_new_workout_from_email(rr, + a.document, + name) + ] + res += wid + link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit' + + except: + # replace with code to process error + res += ['fail: '+name] + donotdelete = 1 + try: + dd = send_confirm(u,name,link) + except: + pass - except Rower.DoesNotExist: - pass - - # remove attachment if donotdelete == 0: a.delete() diff --git a/rowers/models.py b/rowers/models.py index 068e875c..755b3ede 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -211,6 +211,9 @@ class Rower(models.Model): def __str__(self): return self.user.username + def clean_email(self): + return self.user.email.lower() + # Saving a chart as a favorite chart class FavoriteChart(models.Model): y1params = (