Private
Public Access
1
0

adding grid user settings

This commit is contained in:
Sander Roosendaal
2020-05-03 11:11:18 +02:00
parent eaace7c426
commit 0f3d697057
7 changed files with 67 additions and 18 deletions

View File

@@ -697,6 +697,14 @@ class Rower(models.Model):
('Workout','Workout'),
('Yoga','Yoga'),
)
gridtypes = (
('none',None),
('both','both'),
('x','x'),
('y','y'),
)
user = models.OneToOneField(User,on_delete=models.CASCADE)
#billing details
@@ -880,6 +888,10 @@ class Rower(models.Model):
showfavoritechartnotes = models.BooleanField(default=True,
verbose_name='Show Notes for Favorite Charts')
# Static chart settings
staticgrids = models.CharField(default=None,choices=gridtypes,null=True,max_length=50,
verbose_name='Chart Grid')
def __str__(self):
return self.user.first_name+' '+self.user.last_name
@@ -3438,7 +3450,15 @@ class AccountRowerForm(ModelForm):
if 'coach' not in self.instance.rowerplan:
self.fields.pop('offercoaching')
# Form to set static chart settings
class StaticChartRowerForm(ModelForm):
class Meta:
model = Rower
fields = ['staticgrids']
def __init__(self, *args, **kwargs):
super(StaticChartRowerForm, self).__init__(*args, **kwargs)
self.fields['staticgrids'].required = False
class UserForm(ModelForm):

View File

@@ -1902,34 +1902,34 @@ def handle_makeplot(f1, f2, t, hrdata, plotnr, imagename,
row.df = df
nr_rows = len(row.df)
if (plotnr == 1):
fig1 = row.get_timeplot_erg(t)
fig1 = row.get_timeplot_erg(t,**kwargs)
elif (plotnr == 2):
fig1 = row.get_metersplot_erg(t)
fig1 = row.get_metersplot_erg(t,**kwargs)
elif (plotnr == 3):
t += ' - Heart Rate Distribution'
fig1 = row.get_piechart(t)
fig1 = row.get_piechart(t,**kwargs)
elif (plotnr == 4):
if haspower:
fig1 = row.get_timeplot_otwempower(t)
fig1 = row.get_timeplot_otwempower(t,**kwargs)
else:
fig1 = row.get_timeplot_otw(t)
fig1 = row.get_timeplot_otw(t,**kwargs)
elif (plotnr == 5):
if haspower:
fig1 = row.get_metersplot_otwempower(t)
fig1 = row.get_metersplot_otwempower(t,**kwargs)
else:
fig1 = row.get_metersplot_otw(t)
fig1 = row.get_metersplot_otw(t,**kwargs)
elif (plotnr == 6):
t += ' - Heart Rate Distribution'
fig1 = row.get_piechart(t)
fig1 = row.get_piechart(t,**kwargs)
elif (plotnr == 7) or (plotnr == 10):
fig1 = row.get_metersplot_erg2(t)
fig1 = row.get_metersplot_erg2(t,**kwargs)
elif (plotnr == 8) or (plotnr == 11):
fig1 = row.get_timeplot_erg2(t)
fig1 = row.get_timeplot_erg2(t,**kwargs)
elif (plotnr == 9) or (plotnr == 12):
fig1 = row.get_time_otwpower(t)
fig1 = row.get_time_otwpower(t,**kwargs)
elif (plotnr == 13) or (plotnr == 16):
t += ' - Power Distribution'
fig1 = row.get_power_piechart(t)
fig1 = row.get_power_piechart(t,**kwargs)
if fig1 is None:
return 0

View File

@@ -1,8 +1,21 @@
{% extends "newbase.html" %}
{% block title %}Change Favorite Charts{% endblock %}
{% block title %}Change Charts Settings {% endblock %}
{% block main %}
<h1>Static Charts Settings of {{ rower.user.first_name }} {{ rower.user.last_name }}</h1>
<p>
<form method="post">
{% csrf_token %}
<table with=100%>
{{ staticchartform.as_table }}
</table>
<input type="submit" value="Save" class="button"/>
</form>
</p>
<h1>Change Favorite Charts of {{ rower.user.first_name }} {{ rower.user.last_name }}</h1>
<form method="post">
@@ -10,7 +23,7 @@
{% csrf_token %}
<li class="grid_4">
<div class="fav-form-header">
<p><input type="submit" value="Update Favorites" class="button green small"/></p>
<p><input type="submit" value="Update Favorites" class="button"/></p>
</div>
{{ favorites_formset.management_form }}
</li>

View File

@@ -19,7 +19,7 @@
</li>
<li id="manage-favs">
<a href="/rowers/me/favoritecharts/">
<i class="fas fa-chart-area fa-fw"></i>&nbsp;Favorite Charts
<i class="fas fa-chart-area fa-fw"></i>&nbsp;Charts Settings
</a>
</li>
<li id="manage-workflow">

View File

@@ -441,6 +441,13 @@ def make_plot(r,w,f1,f2,plottype,title,imagename='',plotnr=0):
'pieplot':3,
}
axis = r.staticgrids
if axis == None:
gridtrue = False
axis = 'both'
else:
gridtrue = True
if plotnr == 0:
plotnr = plotnrs[plottype]
@@ -450,7 +457,7 @@ def make_plot(r,w,f1,f2,plottype,title,imagename='',plotnr=0):
job = myqueue(queuehigh,handle_makeplot,f1,f2,
title,hrpwrdata,
plotnr,imagename)
plotnr,imagename,gridtrue=gridtrue,axis=axis)
try:
width,height = Image.open(fullpathimagename).size

View File

@@ -127,7 +127,7 @@ from rowers.models import (
VirtualRaceForm,VirtualRaceResultForm,RowerImportExportForm,
IndoorVirtualRaceResultForm,IndoorVirtualRaceResult,
IndoorVirtualRaceForm,PlannedSessionCommentForm,
Alert, Condition
Alert, Condition, StaticChartRowerForm
)
from rowers.models import (
FavoriteForm,BaseFavoriteFormSet,SiteAnnouncement,BasePlannedSessionFormSet,

View File

@@ -220,6 +220,9 @@ def rower_favoritecharts_view(request,userid=0):
message = ''
successmessage = ''
r = getrequestrower(request,userid=userid,notpermanent=True)
staticchartform = StaticChartRowerForm(instance=r)
favorites = FavoriteChart.objects.filter(user=r).order_by('id')
aantal = len(favorites)
favorites_data = [{'yparam1':f.yparam1,
@@ -234,8 +237,13 @@ def rower_favoritecharts_view(request,userid=0):
if aantal==0:
FavoriteChartFormSet = formset_factory(FavoriteForm,formset=BaseFavoriteFormSet,extra=1)
if request.method == 'POST' and 'staticgrids' in request.POST:
staticchartform = StaticChartRowerForm(request.POST,instance=r)
if staticchartform.is_valid():
r.staticgrids = staticchartform.cleaned_data.get('staticgrids')
r.save()
if request.method == 'POST':
if request.method == 'POST' and 'form-TOTAL_FORMS' in request.POST:
favorites_formset = FavoriteChartFormSet(request.POST)
if favorites_formset.is_valid():
new_instances = []
@@ -275,6 +283,7 @@ def rower_favoritecharts_view(request,userid=0):
'favorites_formset':favorites_formset,
'teams':get_my_teams(request.user),
'rower':r,
'staticchartform':staticchartform,
}