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

@@ -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,
}