added export as ride
This commit is contained in:
@@ -157,6 +157,38 @@ class Rower(models.Model):
|
||||
('hwt','heavy-weight'),
|
||||
('lwt','light-weight'),
|
||||
)
|
||||
|
||||
stravatypes = (
|
||||
('Ride','Ride'),
|
||||
('Kitesurf','Kitesurf'),
|
||||
('Run','Run'),
|
||||
('NordicSki','NordicSki'),
|
||||
('Swim','Swim'),
|
||||
('RockClimbing','RockClimbing'),
|
||||
('Hike','Hike'),
|
||||
('RollerSki','RollerSki'),
|
||||
('Walk','Walk'),
|
||||
('Rowing','Rowing'),
|
||||
('AlpineSki','AlpineSki'),
|
||||
('Snowboard','Snowboard'),
|
||||
('BackcountrySki','BackcountrySki'),
|
||||
('Snowshoe','Snowshoe'),
|
||||
('Canoeing','Canoeing'),
|
||||
('StairStepper','StairStepper'),
|
||||
('Crossfit','Crossfit'),
|
||||
('StandUpPaddling','StandUpPaddling'),
|
||||
('EBikeRide','EBikeRide'),
|
||||
('Surfing','Surfing'),
|
||||
('Elliptical','Elliptical'),
|
||||
('VirtualRide','VirtualRide'),
|
||||
('IceSkate','IceSkate'),
|
||||
('WeightTraining','WeightTraining'),
|
||||
('InlineSkate','InlineSkate'),
|
||||
('Windsurf','Windsurf'),
|
||||
('Kayaking','Kayaking'),
|
||||
('Workout','Workout'),
|
||||
('Yoga','Yoga'),
|
||||
)
|
||||
user = models.OneToOneField(User)
|
||||
|
||||
# Heart Rate Zone data
|
||||
@@ -215,6 +247,10 @@ class Rower(models.Model):
|
||||
blank=True,null=True)
|
||||
|
||||
stravatoken = models.CharField(default='',max_length=200,blank=True,null=True)
|
||||
stravaexportas = models.CharField(default="Rowing",
|
||||
max_length=30,
|
||||
choices=stravatypes,
|
||||
verbose_name="Export Workouts to Strava as")
|
||||
|
||||
runkeepertoken = models.CharField(default='',max_length=200,
|
||||
blank=True,null=True)
|
||||
@@ -558,6 +594,11 @@ class AdvancedWorkoutForm(ModelForm):
|
||||
model = Workout
|
||||
fields = ['boattype','weightvalue']
|
||||
|
||||
class RowerExportForm(ModelForm):
|
||||
class Meta:
|
||||
model = Rower
|
||||
fields = ['stravaexportas']
|
||||
|
||||
# Simple form to set rower's Functional Threshold Power
|
||||
class RowerPowerForm(ModelForm):
|
||||
class Meta:
|
||||
|
||||
@@ -276,7 +276,8 @@ def createstravaworkoutdata(w,dozip=True):
|
||||
|
||||
# Upload the TCX file to Strava and set the workout activity type
|
||||
# to rowing on Strava
|
||||
def handle_stravaexport(f2,workoutname,stravatoken,description=''):
|
||||
def handle_stravaexport(f2,workoutname,stravatoken,description='',
|
||||
activity_type='Rowing'):
|
||||
# w = Workout.objects.get(id=workoutid)
|
||||
client = stravalib.Client(access_token=stravatoken)
|
||||
|
||||
@@ -291,7 +292,7 @@ def handle_stravaexport(f2,workoutname,stravatoken,description=''):
|
||||
|
||||
# description doesn't work yet. Have to wait for stravalib to update
|
||||
if res:
|
||||
act = client.update_activity(res.id,activity_type='Rowing',description=description,device_name='Rowsandall.com')
|
||||
act = client.update_activity(res.id,activity_type=activity_type,description=description,device_name='Rowsandall.com')
|
||||
else:
|
||||
message = 'Strava activity update timed out.'
|
||||
return (0,message)
|
||||
|
||||
@@ -188,6 +188,15 @@
|
||||
<p><a href="/rowers/me/tpauthorize/"><img src="/static/img/TP_logo_horz_2_color.png" alt="connect with TrainingPeaks" width="150"></a></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid_6 alpha">
|
||||
<p>
|
||||
<h2>Export Settings</h2>
|
||||
<div class="grid_2 suffix_4 alpha">
|
||||
<a class="button gray small" href="/rowers/me/exportsettings">Manage Export Settings</a>
|
||||
</div>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
31
rowers/templates/rower_exportsettings.html
Normal file
31
rowers/templates/rower_exportsettings.html
Normal file
@@ -0,0 +1,31 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Change Rower Export Settings{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="grid_12 alpha">
|
||||
<div class="grid_6 suffix_6 alpha">
|
||||
<p>
|
||||
<h2>Export Settings</h2>
|
||||
{% if form.errors %}
|
||||
<p style="color: red;">
|
||||
Please correct the error{{ form.errors|pluralize }} below.
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
<form enctype="multipart/form-data" action="" method="post">
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
{% csrf_token %}
|
||||
<div class="grid_2 prefix_2 suffix_2">
|
||||
<input class="button green" type="submit" value="Save">
|
||||
</form>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
{% endblock %}
|
||||
@@ -169,6 +169,18 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid_12 alpha">
|
||||
<div class="grid_6 suffix_6 alpha">
|
||||
<p>
|
||||
<h2>Export Settings</h2>
|
||||
<div class="grid_2 suffix_4 alpha">
|
||||
<a class="button gray small" href="/rowers/me/exportsettings">Manage Export Settings</a>
|
||||
</div>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="grid_12 alpha">
|
||||
<div class="grid_6 suffix_6 alpha">
|
||||
|
||||
@@ -252,6 +252,7 @@ urlpatterns = [
|
||||
url(r'^user-multiflex/$',views.multiflex_view),
|
||||
url(r'^user-multiflex$',views.multiflex_view),
|
||||
url(r'^me/teams/$',views.rower_teams_view),
|
||||
url(r'^me/exportsettings/$',views.rower_exportsettings_view),
|
||||
url(r'^team/(?P<id>\d+)/$',views.team_view),
|
||||
url(r'^team/(?P<id>\d+)/memberstats$',views.team_members_stats_view),
|
||||
url(r'^team/(?P<id>\d+)/edit$',views.team_edit_view),
|
||||
|
||||
@@ -43,7 +43,7 @@ from rowers.models import (
|
||||
RowerPowerForm,RowerForm,GraphImage,AdvancedWorkoutForm,
|
||||
RowerPowerZonesForm,AccountRowerForm,UserForm,StrokeData,
|
||||
Team,TeamForm,TeamInviteForm,TeamInvite,TeamRequest,
|
||||
WorkoutComment,WorkoutCommentForm
|
||||
WorkoutComment,WorkoutCommentForm,RowerExportForm,
|
||||
)
|
||||
from rowers.models import FavoriteForm,BaseFavoriteFormSet,SiteAnnouncement
|
||||
from django.forms.formsets import formset_factory
|
||||
@@ -1351,9 +1351,11 @@ 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 = r.stravaexportas
|
||||
res,mes = stravastuff.handle_stravaexport(f,w.name,
|
||||
r.stravatoken,
|
||||
description=newnotes)
|
||||
description=newnotes,
|
||||
activity_type=activity_type)
|
||||
if res==0:
|
||||
messages.error(request,mes)
|
||||
w.uploadedtostrava = -1
|
||||
@@ -8463,6 +8465,24 @@ def rower_favoritecharts_view(request):
|
||||
|
||||
return render(request,'favoritecharts.html',context)
|
||||
|
||||
# page where user sets his export settings
|
||||
@login_required()
|
||||
def rower_exportsettings_view(request):
|
||||
r = getrower(request.user)
|
||||
if request.method == 'POST':
|
||||
form = RowerExportForm(request.POST)
|
||||
if form.is_valid():
|
||||
stravaexportas = form.cleaned_data['stravaexportas']
|
||||
r.stravaexportas = stravaexportas
|
||||
r.save()
|
||||
else:
|
||||
form = RowerExportForm(instance=r)
|
||||
return render(request, 'rower_exportsettings.html',
|
||||
{'form':form,
|
||||
'rower':r,
|
||||
})
|
||||
|
||||
|
||||
# Page where user can set his details
|
||||
# Add email address to form so user can change his email address
|
||||
@login_required()
|
||||
|
||||
Reference in New Issue
Block a user