added reststrokes to favoritechart settings
This commit is contained in:
@@ -162,8 +162,13 @@ def prepmultipledata(ids,verbose=False):
|
|||||||
res = list(itertools.chain.from_iterable(res.fetchall()))
|
res = list(itertools.chain.from_iterable(res.fetchall()))
|
||||||
conn.close()
|
conn.close()
|
||||||
engine.dispose()
|
engine.dispose()
|
||||||
|
|
||||||
res = list(set(ids)-set(res))
|
try:
|
||||||
|
ids2 = [int(id) for id in ids]
|
||||||
|
except ValueError:
|
||||||
|
ids2 = ids
|
||||||
|
|
||||||
|
res = list(set(ids2)-set(res))
|
||||||
for id in res:
|
for id in res:
|
||||||
rowdata,row = getrowdata(id=id)
|
rowdata,row = getrowdata(id=id)
|
||||||
if verbose:
|
if verbose:
|
||||||
@@ -196,7 +201,8 @@ def read_cols_df_sql(ids,columns):
|
|||||||
columns = cls,
|
columns = cls,
|
||||||
ids = tuple(ids),
|
ids = tuple(ids),
|
||||||
))
|
))
|
||||||
|
|
||||||
|
connection = engine.raw_connection()
|
||||||
df = pd.read_sql_query(query,engine)
|
df = pd.read_sql_query(query,engine)
|
||||||
engine.dispose()
|
engine.dispose()
|
||||||
return df
|
return df
|
||||||
|
|||||||
@@ -157,12 +157,15 @@ class FavoriteChart(models.Model):
|
|||||||
workouttype = models.CharField(max_length=50,choices=workouttypechoices,
|
workouttype = models.CharField(max_length=50,choices=workouttypechoices,
|
||||||
default='both',
|
default='both',
|
||||||
verbose_name='Workout Type')
|
verbose_name='Workout Type')
|
||||||
|
reststrokes = models.BooleanField(default=True,verbose_name="Incl. Rest")
|
||||||
user = models.ForeignKey(Rower)
|
user = models.ForeignKey(Rower)
|
||||||
|
|
||||||
|
|
||||||
class FavoriteForm(ModelForm):
|
class FavoriteForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = FavoriteChart
|
model = FavoriteChart
|
||||||
fields = ['xparam','yparam1','yparam2','plottype','workouttype']
|
fields = ['xparam','yparam1','yparam2',
|
||||||
|
'plottype','workouttype','reststrokes']
|
||||||
|
|
||||||
class BaseFavoriteFormSet(BaseFormSet):
|
class BaseFavoriteFormSet(BaseFormSet):
|
||||||
def clean(self):
|
def clean(self):
|
||||||
@@ -175,7 +178,8 @@ class BaseFavoriteFormSet(BaseFormSet):
|
|||||||
yparam1 = form.cleaned_data['yparam1']
|
yparam1 = form.cleaned_data['yparam1']
|
||||||
yparam2 = form.cleaned_data['yparam2']
|
yparam2 = form.cleaned_data['yparam2']
|
||||||
plottype = form.cleaned_data['plottype']
|
plottype = form.cleaned_data['plottype']
|
||||||
|
reststrokes = form.cleaned_data['reststrokes']
|
||||||
|
|
||||||
if not xparam:
|
if not xparam:
|
||||||
raise forms.ValidationError(
|
raise forms.ValidationError(
|
||||||
'Must have x parameter.',
|
'Must have x parameter.',
|
||||||
|
|||||||
@@ -183,6 +183,11 @@
|
|||||||
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
|
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input class="grid_2 alpha button blue small" type="hidden" name="savefavorite" value="True">
|
<input class="grid_2 alpha button blue small" type="hidden" name="savefavorite" value="True">
|
||||||
|
{% if workstrokesonly %}
|
||||||
|
<input type="hidden" name="workstrokesonlysave" value="False">
|
||||||
|
{% else %}
|
||||||
|
<input type="hidden" name="workstrokesonlysave" value="True">
|
||||||
|
{% endif %}
|
||||||
<input class="grid_2 alpha button blue small" value="Make Favorite" type="Submit">
|
<input class="grid_2 alpha button blue small" value="Make Favorite" type="Submit">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -218,6 +218,11 @@
|
|||||||
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
|
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input class="grid_2 alpha button blue small" type="hidden" name="savefavorite" value="True">
|
<input class="grid_2 alpha button blue small" type="hidden" name="savefavorite" value="True">
|
||||||
|
{% if workstrokesonly %}
|
||||||
|
<input type="hidden" name="workstrokesonlysave" value="False">
|
||||||
|
{% else %}
|
||||||
|
<input type="hidden" name="workstrokesonlysave" value="True">
|
||||||
|
{% endif %}
|
||||||
<input class="grid_2 alpha button blue small" value="Make Favorite" type="Submit">
|
<input class="grid_2 alpha button blue small" value="Make Favorite" type="Submit">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2577,11 +2577,6 @@ def workout_comparison_view2(request,id1=0,id2=0,xparam='distance',
|
|||||||
|
|
||||||
|
|
||||||
def workout_flexchart3_view(request,*args,**kwargs):
|
def workout_flexchart3_view(request,*args,**kwargs):
|
||||||
# xparam='distance',yparam1='pace',
|
|
||||||
# yparam2='hr',plottype='line',
|
|
||||||
# promember=0):
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
id = kwargs['id']
|
id = kwargs['id']
|
||||||
@@ -2620,7 +2615,14 @@ def workout_flexchart3_view(request,*args,**kwargs):
|
|||||||
favorites = FavoriteChart.objects.filter(user=r,
|
favorites = FavoriteChart.objects.filter(user=r,
|
||||||
workouttype__in=[workouttype,'both']).order_by("id")
|
workouttype__in=[workouttype,'both']).order_by("id")
|
||||||
maxfav = len(favorites)-1
|
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:
|
if 'xparam' in kwargs:
|
||||||
xparam = kwargs['xparam']
|
xparam = kwargs['xparam']
|
||||||
else:
|
else:
|
||||||
@@ -2657,10 +2659,21 @@ def workout_flexchart3_view(request,*args,**kwargs):
|
|||||||
else:
|
else:
|
||||||
plottype = 'line'
|
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:
|
if request.method == 'POST' and 'savefavorite' in request.POST:
|
||||||
|
workstrokesonly = request.POST['workstrokesonlysave']
|
||||||
|
reststrokes = not workstrokesonly
|
||||||
f = FavoriteChart(user=r,xparam=xparam,
|
f = FavoriteChart(user=r,xparam=xparam,
|
||||||
yparam1=yparam1,yparam2=yparam2,
|
yparam1=yparam1,yparam2=yparam2,
|
||||||
plottype=plottype,workouttype=workouttype)
|
plottype=plottype,workouttype=workouttype,
|
||||||
|
reststrokes=reststrokes)
|
||||||
f.save()
|
f.save()
|
||||||
if request.method == 'POST' and 'workstrokesonly' in request.POST:
|
if request.method == 'POST' and 'workstrokesonly' in request.POST:
|
||||||
workstrokesonly = request.POST['workstrokesonly']
|
workstrokesonly = request.POST['workstrokesonly']
|
||||||
@@ -2668,8 +2681,6 @@ def workout_flexchart3_view(request,*args,**kwargs):
|
|||||||
workstrokesonly = True
|
workstrokesonly = True
|
||||||
else:
|
else:
|
||||||
workstrokesonly = False
|
workstrokesonly = False
|
||||||
else:
|
|
||||||
workstrokesonly = False
|
|
||||||
|
|
||||||
# create interactive plot
|
# create interactive plot
|
||||||
res = interactive_flex_chart2(id,xparam=xparam,yparam1=yparam1,
|
res = interactive_flex_chart2(id,xparam=xparam,yparam1=yparam1,
|
||||||
@@ -4508,13 +4519,18 @@ def rower_favoritecharts_view(request):
|
|||||||
successmessage = ''
|
successmessage = ''
|
||||||
r = Rower.objects.get(user=request.user)
|
r = Rower.objects.get(user=request.user)
|
||||||
favorites = FavoriteChart.objects.filter(user=r).order_by('id')
|
favorites = FavoriteChart.objects.filter(user=r).order_by('id')
|
||||||
|
aantal = len(favorites)
|
||||||
favorites_data = [{'yparam1':f.yparam1,
|
favorites_data = [{'yparam1':f.yparam1,
|
||||||
'yparam2':f.yparam2,
|
'yparam2':f.yparam2,
|
||||||
'xparam':f.xparam,
|
'xparam':f.xparam,
|
||||||
'plottype':f.plottype,
|
'plottype':f.plottype,
|
||||||
'workouttype':f.workouttype}
|
'workouttype':f.workouttype,
|
||||||
|
'reststrokes':f.reststrokes}
|
||||||
for f in favorites]
|
for f in favorites]
|
||||||
FavoriteChartFormSet = formset_factory(FavoriteForm,formset=BaseFavoriteFormSet,extra=0)
|
FavoriteChartFormSet = formset_factory(FavoriteForm,formset=BaseFavoriteFormSet,extra=0)
|
||||||
|
if aantal==0:
|
||||||
|
FavoriteChartFormSet = formset_factory(FavoriteForm,formset=BaseFavoriteFormSet,extra=1)
|
||||||
|
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
favorites_formset = FavoriteChartFormSet(request.POST)
|
favorites_formset = FavoriteChartFormSet(request.POST)
|
||||||
@@ -4527,18 +4543,26 @@ def rower_favoritecharts_view(request):
|
|||||||
xparam = favorites_form.cleaned_data.get('xparam')
|
xparam = favorites_form.cleaned_data.get('xparam')
|
||||||
plottype = favorites_form.cleaned_data.get('plottype')
|
plottype = favorites_form.cleaned_data.get('plottype')
|
||||||
workouttype = favorites_form.cleaned_data.get('workouttype')
|
workouttype = favorites_form.cleaned_data.get('workouttype')
|
||||||
|
reststrokes = favorites_form.cleaned_data.get('reststrokes')
|
||||||
new_instances.append(FavoriteChart(user=r,
|
new_instances.append(FavoriteChart(user=r,
|
||||||
yparam1=yparam1,
|
yparam1=yparam1,
|
||||||
yparam2=yparam2,
|
yparam2=yparam2,
|
||||||
xparam=xparam,
|
xparam=xparam,
|
||||||
plottype=plottype,
|
plottype=plottype,
|
||||||
workouttype=workouttype))
|
workouttype=workouttype,
|
||||||
|
reststrokes=reststrokes))
|
||||||
try:
|
try:
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
FavoriteChart.objects.filter(user=r).delete()
|
FavoriteChart.objects.filter(user=r).delete()
|
||||||
FavoriteChart.objects.bulk_create(new_instances)
|
FavoriteChart.objects.bulk_create(new_instances)
|
||||||
successmessage = "You have updated your favorites"
|
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:
|
except IntegrityError:
|
||||||
message = "something went wrong"
|
message = "something went wrong"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user