From 0b1cc2403fee041509da267f9c981a0db2e0bde8 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Tue, 9 Feb 2021 19:05:57 +0100 Subject: [PATCH 1/4] fix subscription cancel webhook --- rowers/braintreestuff.py | 2 ++ rowers/forms.py | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/rowers/braintreestuff.py b/rowers/braintreestuff.py index 3bc7546b..043542b9 100644 --- a/rowers/braintreestuff.py +++ b/rowers/braintreestuff.py @@ -68,6 +68,8 @@ def process_webhook(notification): subscription = notification.subscription rs = Rower.objects.filter(subscription_id=subscription.id) if rs.count() == 0: + with open('braintreewebhooks.log','a') as f: + f.write('Could not find rowers with subscription ID '+subscription.id+'\n') return 0 r = rs[0] result,mesg,errormsg = cancel_subscription(r,subscription.id) diff --git a/rowers/forms.py b/rowers/forms.py index 326b78c0..f2ad4f96 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -1076,7 +1076,6 @@ class CourseSelectForm(forms.Form): manager = kwargs.pop('manager',None) super(CourseSelectForm,self).__init__(*args,**kwargs) if course is not None: - print('aap',course) d_min = 0.5*course.distance d_max = 2*course.distance country = course.country From 8ed7eae26e655ae3cd6adae2fceced9f75f9531a Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 10 Feb 2021 07:59:40 +0100 Subject: [PATCH 2/4] fix #604 --- rowers/views/importviews.py | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/rowers/views/importviews.py b/rowers/views/importviews.py index 4d098659..9cdaa889 100644 --- a/rowers/views/importviews.py +++ b/rowers/views/importviews.py @@ -1669,26 +1669,14 @@ def workout_getc2workout_all(request,page=1,message=""): except NoTokenError: return HttpResponseRedirect("/rowers/me/c2authorize/") - res = c2stuff.get_c2_workout_list(request.user,page=page) + r = getrequestrower(request) - if (res.status_code != 200): - message = "Something went wrong in workout_c2import_view (C2 token refresh)" - messages.error(request,message) + result = c2stuff.get_c2_workouts(r,do_async=True) + + if result: + messages.info(request,'Your C2 workouts will be imported in the coming few minutes') else: - r = getrower(request.user) - c2ids = [item['id'] for item in res.json()['data']] - alldata = {} - for item in res.json()['data']: - alldata[item['id']] = item - - knownc2ids = uniqify([ - w.uploadedtoc2 for w in Workout.objects.filter(user=r) - ]) - newids = [c2id for c2id in c2ids if not c2id in knownc2ids] - - for c2id in newids: - workoutid = c2stuff.create_async_workout(alldata, - request.user,c2id) + messages.error(request,'Your C2 workouts import failed') url = reverse('workouts_view') return HttpResponseRedirect(url) From 103a946fe7c0726eecbe2a2a0e7dd4de15977c46 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 10 Feb 2021 08:03:43 +0100 Subject: [PATCH 3/4] c2list checking for tombstones --- rowers/views/importviews.py | 13 +++++++++++++ rowers/views/statements.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/rowers/views/importviews.py b/rowers/views/importviews.py index 9cdaa889..999ca471 100644 --- a/rowers/views/importviews.py +++ b/rowers/views/importviews.py @@ -1706,6 +1706,19 @@ def workout_c2import_view(request,page=1,userid=0,message=""): knownc2ids = uniqify([ w.uploadedtoc2 for w in Workout.objects.filter(user=r) ]) + tombstones = [ + t.uploadedtoc2 for t in TombStone.objects.filter(user=r) + ] + parkedids = [] + try: + with open('c2blocked.json','r') as c2blocked: + jsondata = json.load(c2blocked) + parkedids = jsondata['ids'] + except FileNotFoundError: + pass + + knownc2ids = uniqify(knownc2ids+tombstones+parkedids) + newids = [c2id for c2id in c2ids if not c2id in knownc2ids] for item in res.json()['data']: d = item['distance'] diff --git a/rowers/views/statements.py b/rowers/views/statements.py index 4570f56f..233d6abb 100644 --- a/rowers/views/statements.py +++ b/rowers/views/statements.py @@ -118,7 +118,7 @@ from rowers.models import ( PlannedSessionComment,CoachRequest,CoachOffer, VideoAnalysis,ShareKey, StandardCollection,CourseStandard, - VirtualRaceFollower, + VirtualRaceFollower,TombStone ) from rowers.models import ( RowerPowerForm,RowerHRZonesForm,RowerForm,RowerCPForm,GraphImage,AdvancedWorkoutForm, From bc0d34e78c63bf0c5b53c60faee2c5d11be8d800 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 10 Feb 2021 20:17:48 +0100 Subject: [PATCH 4/4] add match option to stravaexportas --- rowers/models.py | 5 +++-- rowers/stravastuff.py | 17 +++++++++++++++-- rowers/views/importviews.py | 6 ++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/rowers/models.py b/rowers/models.py index c75106ce..d240abe3 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -748,6 +748,7 @@ class CoachingGroup(models.Model): class Rower(models.Model): adaptivetypes = mytypes.adaptivetypes stravatypes = ( + ('match','Variable - try to match the type'), ('Ride','Ride'), ('Kitesurf','Kitesurf'), ('Run','Run'), @@ -965,7 +966,7 @@ class Rower(models.Model): stravatokenexpirydate = models.DateTimeField(blank=True,null=True) stravarefreshtoken = models.CharField(default='',max_length=1000, blank=True,null=True) - stravaexportas = models.CharField(default="Rowing", + stravaexportas = models.CharField(default="match", max_length=30, choices=stravatypes, verbose_name="Export Workouts to Strava as") @@ -2292,7 +2293,7 @@ class PlannedSession(models.Model): if self.sessionvalue <= 0: self.sessionvalue = 1 - + manager = self.manager if self.sessiontype not in ['race','indoorrace']: if not can_add_session(self.manager): diff --git a/rowers/stravastuff.py b/rowers/stravastuff.py index 83681b0e..7c01a4a5 100644 --- a/rowers/stravastuff.py +++ b/rowers/stravastuff.py @@ -752,23 +752,36 @@ def workout_strava_upload(user,w, quick=False,asynchron=True): tcxfile, tcxmesg = createstravaworkoutdata(w) if not tcxfile: return "Failed to create workout data",0 + activity_type = r.stravaexportas + if r.stravaexportas == 'match': + try: + activity_type = mytypes.stravamapping[w.workouttype] + except KeyError: + activity_type = 'Rowing' job = myqueue(queue, handle_strava_sync, r.stravatoken, w.id, - tcxfile,w.name,r.stravaexportas, + tcxfile,w.name,activity_type, w.notes ) return "Asynchronous sync",-1 try: tcxfile,tcxmesg = createstravaworkoutdata(w) if tcxfile: + activity_type = r.stravaexportas + if r.stravaexportas == 'match': + try: + activity_type = mytypes.stravamapping[w.workouttype] + except KeyError: + activity_type = 'Rowing' + print(w.workouttype,activity_type) with open(tcxfile,'rb') as f: res,mes = handle_stravaexport( f,w.name, r.stravatoken, description=w.notes+'\n from '+w.workoutsource+' via rowsandall.com', - activity_type=r.stravaexportas,quick=quick,asynchron=asynchron) + activity_type=activity_type,quick=quick,asynchron=asynchron) if res==0: message = mes w.uploadedtostrava = -1 diff --git a/rowers/views/importviews.py b/rowers/views/importviews.py index 999ca471..ec0d912b 100644 --- a/rowers/views/importviews.py +++ b/rowers/views/importviews.py @@ -93,8 +93,14 @@ def workout_strava_upload_view(request,id=0): newnotes = w.notes+'\n from '+w.workoutsource+' via rowsandall.com' except TypeError: newnotes = 'from '+w.workoutsource+' via rowsandall.com' + activity_type = 'Ride' if w.workouttype in mytypes.rowtypes: activity_type = r.stravaexportas + if activity_type == 'match': + try: + activity_type = mytypes.stravamapping[w.workouttype] + except KeyError: + activity_type = 'Ride' else: try: activity_type = mytypes.stravamapping[w.workouttype]