basic plan page and edit macro cycle
This commit is contained in:
@@ -992,7 +992,7 @@ class TrainingPlan(models.Model):
|
|||||||
firstname = self.rower.user.first_name
|
firstname = self.rower.user.first_name
|
||||||
lastname = self.rower.user.last_name
|
lastname = self.rower.user.last_name
|
||||||
|
|
||||||
stri = u'Training Plan for {first_name} {last_name} {s} - {e}: {n}'.format(
|
stri = u'Training Plan for {firstname} {lastname} {s} - {e}: {n}'.format(
|
||||||
s = startdate.strftime('%Y-%m-%d'),
|
s = startdate.strftime('%Y-%m-%d'),
|
||||||
e = enddate.strftime('%Y-%m-%d'),
|
e = enddate.strftime('%Y-%m-%d'),
|
||||||
firstname = firstname,
|
firstname = firstname,
|
||||||
@@ -1031,7 +1031,8 @@ class TrainingPlan(models.Model):
|
|||||||
|
|
||||||
m.save()
|
m.save()
|
||||||
|
|
||||||
createmacrofillers(self)
|
else:
|
||||||
|
createmacrofillers(self)
|
||||||
|
|
||||||
class TrainingPlanForm(ModelForm):
|
class TrainingPlanForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
@@ -1070,10 +1071,20 @@ def createmacrofillers(plan):
|
|||||||
plan = plan
|
plan = plan
|
||||||
).order_by("-startdate")
|
).order_by("-startdate")
|
||||||
|
|
||||||
|
if not cycles:
|
||||||
|
macr = TrainingMacroCycle(
|
||||||
|
startdate = plan.startdate,
|
||||||
|
enddate = plan.enddate,
|
||||||
|
type='filler',
|
||||||
|
name='Filler'
|
||||||
|
)
|
||||||
|
macr.save()
|
||||||
|
|
||||||
thedate = plan.enddate
|
thedate = plan.enddate
|
||||||
while cycles:
|
while cycles:
|
||||||
if cycles[0].enddate < thedate:
|
if cycles[0].enddate < thedate:
|
||||||
macr = TrainingMacroCycle(
|
macr = TrainingMacroCycle(
|
||||||
|
plan=plan,
|
||||||
startdate = cycles[0].enddate+datetime.timedelta(days=1),
|
startdate = cycles[0].enddate+datetime.timedelta(days=1),
|
||||||
enddate = thedate,
|
enddate = thedate,
|
||||||
type='filler',
|
type='filler',
|
||||||
@@ -1095,6 +1106,15 @@ class TrainingMacroCycle(models.Model):
|
|||||||
choices=cycletypechoices,
|
choices=cycletypechoices,
|
||||||
max_length=150)
|
max_length=150)
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
stri = 'Macro Cycle - {n} ({sd} - {ed})'.format(
|
||||||
|
n = self.name,
|
||||||
|
sd = self.startdate,
|
||||||
|
ed = self.enddate,
|
||||||
|
)
|
||||||
|
|
||||||
|
return stri
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if self.enddate < self.startdate:
|
if self.enddate < self.startdate:
|
||||||
startdate = self.startdate
|
startdate = self.startdate
|
||||||
@@ -1132,6 +1152,15 @@ class TrainingMacroCycle(models.Model):
|
|||||||
|
|
||||||
meso.save()
|
meso.save()
|
||||||
|
|
||||||
|
class TrainingMacroCycleForm(ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = TrainingMacroCycle
|
||||||
|
fields = ['name','startdate','enddate']
|
||||||
|
|
||||||
|
widgets = {
|
||||||
|
'startdate': AdminDateWidget(),
|
||||||
|
'enddate': AdminDateWidget()
|
||||||
|
}
|
||||||
|
|
||||||
class TrainingMesoCycle(models.Model):
|
class TrainingMesoCycle(models.Model):
|
||||||
plan = models.ForeignKey(TrainingMacroCycle)
|
plan = models.ForeignKey(TrainingMacroCycle)
|
||||||
@@ -1143,6 +1172,14 @@ class TrainingMesoCycle(models.Model):
|
|||||||
type = models.CharField(default='filler',
|
type = models.CharField(default='filler',
|
||||||
choices=cycletypechoices,
|
choices=cycletypechoices,
|
||||||
max_length=150)
|
max_length=150)
|
||||||
|
def __unicode__(self):
|
||||||
|
stri = 'Meso Cycle - {n} ({sd} - {ed})'.format(
|
||||||
|
n = self.name,
|
||||||
|
sd = self.startdate,
|
||||||
|
ed = self.enddate,
|
||||||
|
)
|
||||||
|
|
||||||
|
return stri
|
||||||
|
|
||||||
|
|
||||||
class TrainingMicroCycle(models.Model):
|
class TrainingMicroCycle(models.Model):
|
||||||
@@ -1155,6 +1192,14 @@ class TrainingMicroCycle(models.Model):
|
|||||||
type = models.CharField(default='filler',
|
type = models.CharField(default='filler',
|
||||||
choices=cycletypechoices,
|
choices=cycletypechoices,
|
||||||
max_length=150)
|
max_length=150)
|
||||||
|
def __unicode__(self):
|
||||||
|
stri = 'Micro Cycle - {n} ({sd} - {ed})'.format(
|
||||||
|
n = self.name,
|
||||||
|
sd = self.startdate,
|
||||||
|
ed = self.enddate,
|
||||||
|
)
|
||||||
|
|
||||||
|
return stri
|
||||||
|
|
||||||
|
|
||||||
# Needs some error checking
|
# Needs some error checking
|
||||||
|
|||||||
60
rowers/templates/trainingplan.html
Normal file
60
rowers/templates/trainingplan.html
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
{% 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 class="grid_12 alpha">
|
||||||
|
<h1>Training Plan - {{ plan.name }}</h1>
|
||||||
|
</div>
|
||||||
|
<div class="grid_4 alpha">
|
||||||
|
<h2>Macro Cycles</h2>
|
||||||
|
</div>
|
||||||
|
<div class="grid_4">
|
||||||
|
<h2>Meso Cycles</h2>
|
||||||
|
</div>
|
||||||
|
<div class="grid_4 omega">
|
||||||
|
<h2>Micro Cycles</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="grid_12">
|
||||||
|
{% for key,macrocycle in cycles.items %}
|
||||||
|
<div class="grid_12 alpha">
|
||||||
|
<div class="grid_4 alpha">
|
||||||
|
<h3>{{ macrocycle.0.name }}</h3>
|
||||||
|
<p>{{ macrocycle.0.startdate }}</p>
|
||||||
|
<p>{{ macrocycle.0.enddate }}</p>
|
||||||
|
<p><a href="/rowers/macrocycle/{{ macrocycle.0.id }}">edit</a></p>
|
||||||
|
</div>
|
||||||
|
<div class="grid_8 omega">
|
||||||
|
{% for key, mesocycle in macrocycle.1.items %}
|
||||||
|
<div class="grid_4 alpha">
|
||||||
|
{{ mesocycle.0 }}
|
||||||
|
</div>
|
||||||
|
<div class="grid_4 omega">
|
||||||
|
{% for key, microcycle in mesocycle.1.items %}
|
||||||
|
<div class="grid_4 alpha">
|
||||||
|
{{ microcycle }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@@ -83,7 +83,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td> {{ plan.startdate }} </td>
|
<td> {{ plan.startdate }} </td>
|
||||||
<td> {{ plan.enddate }}</td>
|
<td> {{ plan.enddate }}</td>
|
||||||
<td> {{ plan.name }}</td>
|
<td><a href="/rowers/plan/{{ plan.id }}">{{ plan.name }}</a></td>
|
||||||
<td> <a href="/rowers/editplan/{{ plan.id }}">Edit</a>
|
<td> <a href="/rowers/editplan/{{ plan.id }}">Edit</a>
|
||||||
<td> <a href="/rowers/deleteplan/{{ plan.id }}">Delete</a>
|
<td> <a href="/rowers/deleteplan/{{ plan.id }}">Delete</a>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -422,6 +422,8 @@ urlpatterns = [
|
|||||||
url(r'^createplan$',views.rower_create_trainingplan),
|
url(r'^createplan$',views.rower_create_trainingplan),
|
||||||
url(r'^createplan/(?P<id>\d+)$',views.rower_create_trainingplan),
|
url(r'^createplan/(?P<id>\d+)$',views.rower_create_trainingplan),
|
||||||
url(r'^deleteplan/(?P<id>\d+)$',views.rower_delete_trainingplan),
|
url(r'^deleteplan/(?P<id>\d+)$',views.rower_delete_trainingplan),
|
||||||
|
url(r'^plan/(?P<id>\d+)$',views.rower_trainingplan_view),
|
||||||
|
url(r'^macrocycle/(?P<pk>\d+)$',views.TrainingMacroCycleUpdate.as_view()),
|
||||||
url(r'^deletetarget/(?P<id>\d+)$',views.rower_delete_trainingtarget),
|
url(r'^deletetarget/(?P<id>\d+)$',views.rower_delete_trainingtarget),
|
||||||
url(r'^editplan/(?P<pk>\d+)$',views.TrainingPlanUpdate.as_view()),
|
url(r'^editplan/(?P<pk>\d+)$',views.TrainingPlanUpdate.as_view()),
|
||||||
url(r'^edittarget/(?P<pk>\d+)$',views.TrainingTargetUpdate.as_view()),
|
url(r'^edittarget/(?P<pk>\d+)$',views.TrainingTargetUpdate.as_view()),
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ from rowers.models import (
|
|||||||
TrainingPlan,TrainingPlanForm,TrainingTarget,TrainingTargetForm,
|
TrainingPlan,TrainingPlanForm,TrainingTarget,TrainingTargetForm,
|
||||||
TrainingMacroCycle,TrainingMesoCycle,TrainingMicroCycle,
|
TrainingMacroCycle,TrainingMesoCycle,TrainingMicroCycle,
|
||||||
TrainingTarget,TrainingTargetForm,
|
TrainingTarget,TrainingTargetForm,
|
||||||
|
TrainingMacroCycleForm,createmacrofillers
|
||||||
)
|
)
|
||||||
from rowers.models import (
|
from rowers.models import (
|
||||||
RowerPowerForm,RowerForm,GraphImage,AdvancedWorkoutForm,
|
RowerPowerForm,RowerForm,GraphImage,AdvancedWorkoutForm,
|
||||||
@@ -14269,8 +14270,66 @@ def rower_create_trainingplan(request,id=0):
|
|||||||
|
|
||||||
|
|
||||||
@user_passes_test(hasplannedsessions,login_url="/", redirect_field_name=None)
|
@user_passes_test(hasplannedsessions,login_url="/", redirect_field_name=None)
|
||||||
def rower_view_trainingplan(request,id=0):
|
def rower_trainingplan_view(request,id=0):
|
||||||
pass
|
try:
|
||||||
|
plan = TrainingPlan.objects.get(id=id)
|
||||||
|
except TrainingPlan.DoesNotExist:
|
||||||
|
raise Http404("Training Plan Does Not Exist")
|
||||||
|
|
||||||
|
if not checkaccessuser(request.user,plan.rower):
|
||||||
|
raise PermissionDenied("Access denied")
|
||||||
|
|
||||||
|
macrocycles = TrainingMacroCycle.objects.filter(plan=plan).order_by("startdate")
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
cycles = {}
|
||||||
|
|
||||||
|
|
||||||
|
for m in macrocycles:
|
||||||
|
mesocycles = TrainingMesoCycle.objects.filter(plan=m).order_by("startdate")
|
||||||
|
mesos = {}
|
||||||
|
count2 = 0
|
||||||
|
for me in mesocycles:
|
||||||
|
microcycles = TrainingMicroCycle.objects.filter(plan=me).order_by("startdate")
|
||||||
|
mesos[count2] = (me, microcycles)
|
||||||
|
count2 += 1
|
||||||
|
cycles[count] = (m,mesos)
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
|
||||||
|
return render(request,'trainingplan.html',
|
||||||
|
{
|
||||||
|
'plan':plan,
|
||||||
|
'cycles':cycles,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
class TrainingMacroCycleUpdate(UpdateView):
|
||||||
|
model = TrainingMacroCycle
|
||||||
|
template_name = 'trainingplan_edit.html'
|
||||||
|
form_class = TrainingMacroCycleForm
|
||||||
|
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
plan = self.object.plan
|
||||||
|
createmacrofillers(plan)
|
||||||
|
return reverse(rower_trainingplan_view,
|
||||||
|
kwargs = {
|
||||||
|
'id':plan.id
|
||||||
|
}
|
||||||
|
)
|
||||||
|
def form_valid(self, form):
|
||||||
|
macrocycle = form.save()
|
||||||
|
return super(TrainingMacroCycleUpdate, self).form_valid(form)
|
||||||
|
|
||||||
|
def get_object(self, *args, **kwargs):
|
||||||
|
obj = super(TrainingMacroCycleUpdate, self).get_object(*args, **kwargs)
|
||||||
|
if not checkaccessuser(self.request.user,obj.plan.rower):
|
||||||
|
raise Http404
|
||||||
|
else:
|
||||||
|
obj.type = 'userdefined'
|
||||||
|
obj.save()
|
||||||
|
return obj
|
||||||
|
|
||||||
class TrainingPlanUpdate(UpdateView):
|
class TrainingPlanUpdate(UpdateView):
|
||||||
model = TrainingPlan
|
model = TrainingPlan
|
||||||
|
|||||||
Reference in New Issue
Block a user