Private
Public Access
1
0

data settings form

This commit is contained in:
Sander Roosendaal
2021-03-17 08:30:04 +01:00
parent 736ea040a9
commit fa4cee8fd6
5 changed files with 70 additions and 18 deletions

View File

@@ -879,6 +879,25 @@ class Rower(models.Model):
surveydone = models.BooleanField(default=False)
surveydonedate = models.DateTimeField(blank=True,null=True)
birthdate = models.DateField(null=True,blank=True)
emailalternatives = AlternativeEmails(default=[],null=True,blank=True,verbose_name='Alternative Email addresses (separate with ",")')
emailbounced = models.BooleanField(default=False,
verbose_name='Email Address Bounced')
getimportantemails = models.BooleanField(default=True,
verbose_name='Get Important Emails')
sex = models.CharField(default="not specified",
max_length=30,
choices=sexcategories)
adaptiveclass = models.CharField(choices=adaptivetypes,max_length=50,
default='None',
verbose_name='Adaptive Classification')
# Heart Rate Zone data
max = models.IntegerField(default=192,verbose_name="Max Heart Rate")
@@ -895,15 +914,6 @@ class Rower(models.Model):
max_length=30,
choices=weightcategories)
sex = models.CharField(default="not specified",
max_length=30,
choices=sexcategories)
adaptiveclass = models.CharField(choices=adaptivetypes,max_length=50,
default='None',
verbose_name='Adaptive Classification')
birthdate = models.DateField(null=True,blank=True)
# Power Zone Data
ftp = models.IntegerField(default=226,verbose_name="Functional Threshold Power")
@@ -951,7 +961,6 @@ class Rower(models.Model):
'TR',
'AN','max'])
emailalternatives = AlternativeEmails(default=[],null=True,blank=True,verbose_name='Alternative Email addresses (separate with ",")')
# Site Settings
workflowleftpanel = TemplateListField(default=defaultleft)
@@ -1024,11 +1033,6 @@ class Rower(models.Model):
getemailnotifications = models.BooleanField(default=False,
verbose_name='Receive email notifications')
emailbounced = models.BooleanField(default=False,
verbose_name='Email Address Bounced')
getimportantemails = models.BooleanField(default=True,
verbose_name='Get Important Emails')
# Friends/Team
@@ -1049,7 +1053,7 @@ class Rower(models.Model):
showfavoritechartnotes = models.BooleanField(default=True,
verbose_name='Show Notes for Favorite Charts')
# Static chart settings
# Static chart and data settings
staticgrids = models.CharField(default='both',choices=gridtypes,null=True,max_length=50,
verbose_name='Chart Grid')
@@ -1073,6 +1077,8 @@ class Rower(models.Model):
max_length=100,
verbose_name='Generate a static chart automatically on upload')
dosmooth = models.BooleanField(default=True,verbose_name='Savitzky-Golay Filter (recommended)')
# Auto Join
autojoin = models.BooleanField(default=False,verbose_name='Auto Join Workout Segments')
@@ -4234,6 +4240,10 @@ class StaticChartRowerForm(ModelForm):
super(StaticChartRowerForm, self).__init__(*args, **kwargs)
self.fields['staticgrids'].required = False
class DataRowerForm(ModelForm):
class Meta:
model = Rower
fields = ['dosmooth','autojoin']
class UserForm(ModelForm):
class Meta:

View File

@@ -3,6 +3,25 @@
{% block title %}Change Charts Settings {% endblock %}
{% block main %}
<h1>Data Treatment Settings of {{ rower.user.first_name }} {{ rower.user.last_name }}</h1>
<p>It is recommended to leave this to default settings</p>
<p>
<form method="post">
{% csrf_token %}
<table>
{{ datasettingsform.as_table }}
</table>
<p>
<input type="submit" value="Save" name="save_data" class="button"/>
</p>
<p>
<input type="submit" value="Restore Defaults" name="defaults_data" class="button"/>
</p>
</form>
</p>
<h1>Charts Settings of {{ rower.user.first_name }} {{ rower.user.last_name }}</h1>
<p>

View File

@@ -991,8 +991,10 @@ def step_to_string(step):
name = step['wkt_step_name']
notes = ''
try:
notes = ' - '+step['description']
if len(step['description']):
notes = ' - '+step['description']
except KeyError:
notes = ''

View File

@@ -133,7 +133,7 @@ from rowers.models import (
IndoorVirtualRaceResultForm,IndoorVirtualRaceResult,
IndoorVirtualRaceForm,PlannedSessionCommentForm,
Alert, Condition, StaticChartRowerForm,
FollowerForm,VirtualRaceAthleteForm,InstantPlanForm,
FollowerForm,VirtualRaceAthleteForm,InstantPlanForm,DataRowerForm
)
from rowers.models import (
FavoriteForm,BaseFavoriteFormSet,SiteAnnouncement,BasePlannedSessionFormSet,

View File

@@ -213,6 +213,7 @@ def start_plantrial_view(request):
return HttpResponseRedirect(url)
# Page where user can manage his favorite charts
@login_required()
@permission_required('rower.is_coach',fn=get_user_by_userid,raise_exception=True)
@@ -222,6 +223,7 @@ def rower_favoritecharts_view(request,userid=0):
r = getrequestrowercoachee(request,userid=userid,notpermanent=True)
staticchartform = StaticChartRowerForm(instance=r)
datasettingsform = DataRowerForm(instance=r)
favorites = FavoriteChart.objects.filter(user=r).order_by('id')
aantal = len(favorites)
@@ -250,6 +252,24 @@ def rower_favoritecharts_view(request,userid=0):
r.usersmooth = staticchartform.cleaned_data.get('usersmooth')
r.save()
print(request.POST)
if request.method == 'POST' and 'save_data' in request.POST:
datasettingsform = DataRowerForm(request.POST,instance=r)
if datasettingsform.is_valid():
cd = datasettingsform.cleaned_data
r.autojoin = cd.get('autojoin')
r.dosmooth = cd.get('dosmooth')
r.save()
messages.info(request,"We have updated your data settings")
if request.method == 'POST' and 'defaults_data' in request.POST:
defaultsmooth = Rower._meta.get_field('dosmooth').get_default()
defaultautojoin = Rower._meta.get_field('autojoin').get_default()
r.dosmooth = defaultsmooth
r.autojoin = defaultautojoin
datasettingsform = DataRowerForm(instance=r)
messages.info(request,"We have reset your data settings to the default values")
if request.method == 'POST' and 'form-TOTAL_FORMS' in request.POST:
favorites_formset = FavoriteChartFormSet(request.POST)
if favorites_formset.is_valid():
@@ -291,6 +311,7 @@ def rower_favoritecharts_view(request,userid=0):
'teams':get_my_teams(request.user),
'rower':r,
'staticchartform':staticchartform,
'datasettingsform':datasettingsform,
}