Private
Public Access
1
0

added reststrokes to favoritechart settings

This commit is contained in:
Sander Roosendaal
2016-12-08 11:50:58 +01:00
parent 92cb0ca0cb
commit 7dfff7e3df
5 changed files with 60 additions and 16 deletions

View File

@@ -2577,11 +2577,6 @@ def workout_comparison_view2(request,id1=0,id2=0,xparam='distance',
def workout_flexchart3_view(request,*args,**kwargs):
# xparam='distance',yparam1='pace',
# yparam2='hr',plottype='line',
# promember=0):
try:
id = kwargs['id']
@@ -2620,7 +2615,14 @@ def workout_flexchart3_view(request,*args,**kwargs):
favorites = FavoriteChart.objects.filter(user=r,
workouttype__in=[workouttype,'both']).order_by("id")
maxfav = len(favorites)-1
# check if favoritenr is not out of range
if favorites:
try:
t = favorites[favoritenr].xparam
except IndexError:
favoritenr=0
if 'xparam' in kwargs:
xparam = kwargs['xparam']
else:
@@ -2657,10 +2659,21 @@ def workout_flexchart3_view(request,*args,**kwargs):
else:
plottype = 'line'
if 'workstrokesonly' in kwargs:
workstrokesonly = kwargs['workstrokesonly']
else:
if favorites:
workstrokesonly = not favorites[favoritenr].reststrokes
else:
workstrokesonly = False
if request.method == 'POST' and 'savefavorite' in request.POST:
workstrokesonly = request.POST['workstrokesonlysave']
reststrokes = not workstrokesonly
f = FavoriteChart(user=r,xparam=xparam,
yparam1=yparam1,yparam2=yparam2,
plottype=plottype,workouttype=workouttype)
plottype=plottype,workouttype=workouttype,
reststrokes=reststrokes)
f.save()
if request.method == 'POST' and 'workstrokesonly' in request.POST:
workstrokesonly = request.POST['workstrokesonly']
@@ -2668,8 +2681,6 @@ def workout_flexchart3_view(request,*args,**kwargs):
workstrokesonly = True
else:
workstrokesonly = False
else:
workstrokesonly = False
# create interactive plot
res = interactive_flex_chart2(id,xparam=xparam,yparam1=yparam1,
@@ -4508,13 +4519,18 @@ def rower_favoritecharts_view(request):
successmessage = ''
r = Rower.objects.get(user=request.user)
favorites = FavoriteChart.objects.filter(user=r).order_by('id')
aantal = len(favorites)
favorites_data = [{'yparam1':f.yparam1,
'yparam2':f.yparam2,
'xparam':f.xparam,
'plottype':f.plottype,
'workouttype':f.workouttype}
'workouttype':f.workouttype,
'reststrokes':f.reststrokes}
for f in favorites]
FavoriteChartFormSet = formset_factory(FavoriteForm,formset=BaseFavoriteFormSet,extra=0)
if aantal==0:
FavoriteChartFormSet = formset_factory(FavoriteForm,formset=BaseFavoriteFormSet,extra=1)
if request.method == 'POST':
favorites_formset = FavoriteChartFormSet(request.POST)
@@ -4527,18 +4543,26 @@ def rower_favoritecharts_view(request):
xparam = favorites_form.cleaned_data.get('xparam')
plottype = favorites_form.cleaned_data.get('plottype')
workouttype = favorites_form.cleaned_data.get('workouttype')
reststrokes = favorites_form.cleaned_data.get('reststrokes')
new_instances.append(FavoriteChart(user=r,
yparam1=yparam1,
yparam2=yparam2,
xparam=xparam,
plottype=plottype,
workouttype=workouttype))
workouttype=workouttype,
reststrokes=reststrokes))
try:
with transaction.atomic():
FavoriteChart.objects.filter(user=r).delete()
FavoriteChart.objects.bulk_create(new_instances)
successmessage = "You have updated your favorites"
FavoriteChartFormSet=formset_factory(FavoriteForm,formset=BaseFavoriteFormSet)
print new_instances
print "aap",len(new_instances)
if len(new_instances)==0:
FavoriteChartFormSet=formset_factory(FavoriteForm,formset=BaseFavoriteFormSet,extra=1)
favorites_formset = FavoriteChartFormSet()
except IntegrityError:
message = "something went wrong"