Private
Public Access
1
0

createplan page

This commit is contained in:
Sander Roosendaal
2018-09-06 15:40:10 +02:00
parent de4df4473c
commit 1567b24900
4 changed files with 207 additions and 10 deletions

View File

@@ -935,17 +935,31 @@ class TrainingTarget(models.Model):
default=half_year_from_now)
notes = models.TextField(max_length=300,blank=True)
def __unicode__(self):
date = self.date
name = self.name
ownerfirst = self.rower.user.first_name
ownerlast = self.rower.user.last_name
stri = u'{ownerfirst} {ownerlast} {d} {n}'.format(
ownerfirst = ownerfirst,
ownerlast = ownerlast,
d = date.strftime('%Y-%m-%d'),
n = name
)
return stri
class TrainingTargetForm(ModelForm):
class Meta:
model = TrainingTarget
fields = ['name','date','notes']
widgets = {
'date': SelectDateWidget(
years=range(
timezone.now().year-1,timezone.now().year+1)),
'date': AdminDateWidget()
}
# SportTracks has a TrainingGoal like this
#class TrainingGoal(models.Model):
# rower = models.ForeignKey(Rower)
@@ -976,14 +990,19 @@ class TrainingPlanForm(ModelForm):
fields = ['name','target','startdate','enddate']
widgets = {
'startdate': SelectDateWidget(
years=range(
timezone.now().year-1,timezone.now().year+1)),
'enddate': SelectDateWidget(
years=range(
timezone.now().year-1,timezone.now().year+1)),
'startdate': AdminDateWidget(),
'enddate': AdminDateWidget()
}
def __init__(self,*args, **kwargs):
targets = kwargs.pop('targets',None)
super(TrainingPlanForm, self).__init__(*args, **kwargs)
if targets:
targetchoices = [(x.id,x) for x in targets]
targetchoices.append((None,'---'))
self.fields['target'].choices = targetchoices
cycletypechoices = (
('filler','System Defined'),

View File

@@ -0,0 +1,117 @@
{% extends "base.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% block title %}Rowsandall Training Plans{% endblock %}
{% block scripts %}
{% endblock %}
{% block content %}
<style>
#mypointer {
cursor: pointer;
}
</style>
<div class="grid_12">
<div id="targets_table" class="grid_8 alpha">
<h1>Training Targets</h1>
{% if targets %}
<table width="100%" class="listtable shortpadded">
<thead>
<tr>
<th>Target Date</th>
<th>Name</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
{% for target in targets %}
<tr>
<td> {{ target.date }}</td>
<td> {{ target.name }}</td>
<td> {{ target.notes }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
No training targets found
{% endif %}
</div>
<div class="grid_4 omega">
<div class="grid_4" id="planform">
<h1>Add a target</h1>
<form id="newplanform"
enctype="multipart/form-data" action="" method="post">
<table width=100%>
{{ targetform.as_table }}
</table>
{% csrf_token %}
<div id="formbutton" class="grid_1 prefix_2 suffix_1 omega">
<input class="button green" type="submit" value="Save">
</div>
</form>
</div>
</div>
</div>
<div class="grid_12">
<div id="courses_table" class="grid_8 alpha">
<h1>Plans</h1>
{% if plans %}
<table width="100%" class="listtable shortpadded">
<thead>
<tr>
<th> Start Date</th>
<th> End Date</th>
<th> Name</th>
</tr>
</thead>
<tbody>
{% for plan in plans %}
<tr>
<td> {{ plan.startdate }} </td>
<td> {{ plan.enddate }}</td>
<td> {{ plan.name }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p> No plans found </p>
{% endif %}
</div>
<div class="grid_4 omega">
<div class="grid_4" id="planform">
<h1>Add a plan</h1>
<form id="newplanform"
enctype="multipart/form-data" action="" method="post">
<table width=100%>
{{ form.as_table }}
</table>
{% csrf_token %}
<div id="formbutton" class="grid_1 prefix_2 suffix_1 omega">
<input class="button green" type="submit" value="Save">
</div>
</form>
</div>
</div>
</div>
{% endblock %}

View File

@@ -419,6 +419,8 @@ urlpatterns = [
url(r'^workout/compare/(?P<id1>\d+)/(?P<id2>\d+)/(?P<xparam>\w+.*)/(?P<yparam>[\w\ ]+.*)/(?P<plottype>[\w\ ]+.*)$',views.workout_comparison_view2),
url(r'^workout/compare/(?P<id1>\d+)/(?P<id2>\d+)/(?P<xparam>\w+.*)/(?P<yparam>[\w\ ]+.*)/$',views.workout_comparison_view2),
url(r'^test\_callback',views.rower_process_testcallback),
url(r'^createplan$',views.rower_create_trainingplan),
url(r'^createplan/(?P<id>\d+)$',views.rower_create_trainingplan),
url(r'^workout/(?P<id>\d+)/test\_strokedata$',views.strokedataform),
url(r'^sessions/teamcreate$',views.plannedsession_teamcreate_view),

View File

@@ -64,7 +64,10 @@ from rowers.forms import (
)
from rowers.models import (
Workout, User, Rower, WorkoutForm,FavoriteChart,
PlannedSession, DeactivateUserForm,DeleteUserForm
PlannedSession, DeactivateUserForm,DeleteUserForm,
TrainingPlan,TrainingPlanForm,TrainingTarget,TrainingTargetForm,
TrainingMacroCycle,TrainingMesoCycle,TrainingMicroCycle,
TrainingTarget,TrainingTargetForm,
)
from rowers.models import (
RowerPowerForm,RowerForm,GraphImage,AdvancedWorkoutForm,
@@ -14167,5 +14170,61 @@ def virtualevent_submit_result_view(request,id=0):
'w_form':w_form,
})
@user_passes_test(hasplannedsessions,login_url="/", redirect_field_name=None)
def rower_create_trainingplan(request,id=0):
therower = getrequestrower(request,userid=id)
theuser = therower.user
if request.method == 'POST' and 'date' in request.POST:
targetform = TrainingTargetForm(request.POST)
if targetform.is_valid():
name = targetform.cleaned_data['name']
date = targetform.cleaned_data['date']
notes = targetform.cleaned_data['notes']
t = TrainingTarget(rower=therower,
name=name,
date=date,
notes=notes)
t.save()
elif request.method == 'POST' and 'startdate' in request.POST:
form = TrainingPlanForm(request.POST)
if form.is_valid():
name = form.cleaned_data['name']
target = form.cleaned_data['target']
startdate = form.cleaned_data['startdate']
enddate = form.cleaned_data['enddate']
p = TrainingPlan(
name=name,
rower=therower,
target=target,
startdate=startdate,
enddate=enddate,
)
p.save()
targets = TrainingTarget.objects.filter(rower=therower).order_by("date")
targetform = TrainingTargetForm()
plans = TrainingPlan.objects.filter(rower=therower).order_by("-startdate")
form = TrainingPlanForm(targets=targets)
return render(request,'trainingplan_create.html',
{
'form':form,
'plans':plans,
'targets':targets,
'targetform':targetform,
})