code merge strava import all
This commit is contained in:
@@ -9694,37 +9694,12 @@ def workout_getsporttracksworkout_all(request):
|
||||
# Imports all new workouts from SportTracks
|
||||
@login_required()
|
||||
def workout_getstravaworkout_all(request):
|
||||
res = stravastuff.get_strava_workout_list(request.user)
|
||||
if (res.status_code == 200):
|
||||
r = getrower(request.user)
|
||||
stravaids = [int(item['id']) for item in res.json()]
|
||||
knownstravaids = uniqify([
|
||||
w.uploadedtostrava for w in Workout.objects.filter(user=r)
|
||||
])
|
||||
newids = [stravaid for stravaid in stravaids if not stravaid in knownstravaids]
|
||||
|
||||
for stravaid in newids:
|
||||
res = stravastuff.get_workout(request.user,stravaid)
|
||||
strokedata = res[1]
|
||||
data = res[0]
|
||||
|
||||
if data:
|
||||
id,message = add_workout_from_strokedata(
|
||||
request.user,stravaid,data,strokedata,
|
||||
source='strava',
|
||||
workoutsource='strava')
|
||||
|
||||
if id==0:
|
||||
messages.error(request,message)
|
||||
|
||||
else:
|
||||
messages.info(request,"imported Strava workout "+str(stravaid))
|
||||
w = Workout.objects.get(id=id)
|
||||
w.uploadedtostrava=stravaid
|
||||
w.save()
|
||||
|
||||
else:
|
||||
messages.error(request,"Couldn't import Strava workout "+str(stravaid))
|
||||
r = getrower(request.user)
|
||||
res = stravastuff.get_strava_workouts(r)
|
||||
if res == 1:
|
||||
messages.info(request,"Your workouts are being imported and should appear on the site in the next 15 minutes")
|
||||
else:
|
||||
messages.error(request,"Couldn't import Strava workout "+str(stravaid))
|
||||
|
||||
url = reverse(workouts_view)
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
Reference in New Issue
Block a user