diff --git a/rowers/c2stuff.py b/rowers/c2stuff.py index aa29acb3..9cd176d1 100644 --- a/rowers/c2stuff.py +++ b/rowers/c2stuff.py @@ -449,6 +449,7 @@ def get_username(access_token): try: res = me_json['data']['username'] + id = me_json['data']['id'] except KeyError: res = None @@ -482,7 +483,7 @@ def process_callback(request): access_token = get_token(code) - username = get_username(access_token) + username,id = get_username(access_token) return HttpResponse("got a user name: %s" % username) diff --git a/rowers/stravastuff.py b/rowers/stravastuff.py index 144787f2..b0bf84e4 100644 --- a/rowers/stravastuff.py +++ b/rowers/stravastuff.py @@ -234,7 +234,7 @@ def handle_stravaexport(f2,workoutname,stravatoken,description=''): act = client.upload_activity(f2,'tcx',name=workoutname) try: - res = act.wait(poll_interval=5.0) + res = act.wait(poll_interval=5.0,timeout=30) message = 'Workout successfully synchronized to Strava' except: res = 0 @@ -246,6 +246,7 @@ def handle_stravaexport(f2,workoutname,stravatoken,description=''): act = client.update_activity(res.id,activity_type='Rowing',description=description) else: message = 'Strava upload timed out.' + return (0,message) return (res.id,message) diff --git a/rowers/templates/export.html b/rowers/templates/export.html index 910cbd10..b2cf83e9 100644 --- a/rowers/templates/export.html +++ b/rowers/templates/export.html @@ -6,88 +6,91 @@ {% block content %}
+ + +

Export Workout

+
+

+ Edit Workout +

+
+
+

+ Advanced Edit +

+ +
+ +
+

+ Click on the icon to upload this workout to your site of choice. A checkmark indicates that the workout has already been uploaded. If the button is grayed out, click it to authorize the connection to that site. Use TCX or CSV export to email a TCX or CSV file of your workout to yourself. +

+ +
-

Export Workout

- -
-

- Edit Workout -

-
-
-

- Advanced Edit -

- -
- -
-

-Click on the icon to upload this workout to your site of choice. A checkmark indicates that the workout has already been uploaded. If the button is grayed out, click it to authorize the connection to that site. Use TCX or CSV export to email a TCX or CSV file of your workout to yourself. -

- + {% if workout.uploadedtoc2 == 0 %} + {% if user.rower.c2token == None or user.rower.c2token == '' %} +
+ + C2 icon +
+ {% else %} +
+ Concept2 icon +
+ {% endif %} + {% else %} +
+ + Concept2 icon
- -{% if workout.uploadedtoc2 == 0 %} - {% if user.rower.c2token == None or user.rower.c2token == '' %} -
- - C2 icon -
- {% else %} -
- Concept2 icon -
- {% endif %} -{% else %} -
- Concept2 icon -
{% endif %} {% if workout.uploadedtostrava == 0 %} - {% if user.rower.stravatoken == None or user.rower.stravatoken == '' %} -
- - Strava icon -
- {% else %} -
- Strava icon -
- {% endif %} +{% if user.rower.stravatoken == None or user.rower.stravatoken == '' %} +
+ + Strava icon +
{% else %} -
- Concept2 icon -
+
+ Strava icon +
+{% endif %} +{% else %} +
+ + Concept2 icon +
{% endif %} {% if workout.uploadedtosporttracks == 0 %} - {% if user.rower.sporttrackstoken == None or user.rower.sporttrackstoken == '' %} -
- - SportTracks icon -
- {% else %} -
- - SportTracks icon -
- {% endif %} +{% if user.rower.sporttrackstoken == None or user.rower.sporttrackstoken == '' %} +
+ + SportTracks icon +
{% else %} -
- Concept2 icon -
+
+ + SportTracks icon +
{% endif %} -
- - TCX Export -
+{% else %} +
+ + Concept2 icon +
+{% endif %} +
+ + TCX Export +
-
- - CSV Export -
+
+ + CSV Export +
@@ -100,16 +103,16 @@ You only need to do this once. After that, the site will have access until you revoke the authorization for the "rowingdata" app.

-

connect with strava

+

connect with strava

-

connect with Concept2

+

connect with Concept2

-

connect with SportTracks

+

connect with SportTracks

@@ -117,4 +120,4 @@ revoke the authorization for the "rowingdata" app.

-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/rowers/views.py b/rowers/views.py index c264a9f3..42431190 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -810,7 +810,10 @@ def workout_strava_upload_view(request,id=0): message = mes w.uploadedtostrava = -1 w.save() - os.remove(tcxfile) + try: + os.remove(tcxfile) + except WindowsError: + pass url = reverse(workout_export_view, kwargs = { 'id':str(w.id), @@ -3423,6 +3426,16 @@ def workout_export_view(request,id=0, message="", successmessage=""): except Workout.DoesNotExist: raise Http404("Workout doesn't exist") + try: + thetoken = c2_open(request.user) + except C2NoTokenError: + thetoken = 0 + + if (checkworkoutuser(request.user,row)) and thetoken: + c2userid = c2stuff.get_userid(thetoken) + else: + c2userid = 0 + form = WorkoutForm(instance=row) g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime") # check if user is owner of this workout @@ -3439,6 +3452,7 @@ def workout_export_view(request,id=0, message="", successmessage=""): {'workout':row, 'message':message, 'successmessage':successmessage, + 'c2userid':c2userid, }) # list of comments to a workout