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

@@ -162,8 +162,13 @@ def prepmultipledata(ids,verbose=False):
res = list(itertools.chain.from_iterable(res.fetchall()))
conn.close()
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:
rowdata,row = getrowdata(id=id)
if verbose:
@@ -196,7 +201,8 @@ def read_cols_df_sql(ids,columns):
columns = cls,
ids = tuple(ids),
))
connection = engine.raw_connection()
df = pd.read_sql_query(query,engine)
engine.dispose()
return df

View File

@@ -157,12 +157,15 @@ class FavoriteChart(models.Model):
workouttype = models.CharField(max_length=50,choices=workouttypechoices,
default='both',
verbose_name='Workout Type')
reststrokes = models.BooleanField(default=True,verbose_name="Incl. Rest")
user = models.ForeignKey(Rower)
class FavoriteForm(ModelForm):
class Meta:
model = FavoriteChart
fields = ['xparam','yparam1','yparam2','plottype','workouttype']
fields = ['xparam','yparam1','yparam2',
'plottype','workouttype','reststrokes']
class BaseFavoriteFormSet(BaseFormSet):
def clean(self):
@@ -175,7 +178,8 @@ class BaseFavoriteFormSet(BaseFormSet):
yparam1 = form.cleaned_data['yparam1']
yparam2 = form.cleaned_data['yparam2']
plottype = form.cleaned_data['plottype']
reststrokes = form.cleaned_data['reststrokes']
if not xparam:
raise forms.ValidationError(
'Must have x parameter.',

View File

@@ -183,6 +183,11 @@
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
{% csrf_token %}
<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">
</form>
</div>

View File

@@ -218,6 +218,11 @@
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
{% csrf_token %}
<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">
</form>
</div>

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"