basic plan page and edit macro cycle
This commit is contained in:
@@ -71,6 +71,7 @@ from rowers.models import (
|
||||
TrainingPlan,TrainingPlanForm,TrainingTarget,TrainingTargetForm,
|
||||
TrainingMacroCycle,TrainingMesoCycle,TrainingMicroCycle,
|
||||
TrainingTarget,TrainingTargetForm,
|
||||
TrainingMacroCycleForm,createmacrofillers
|
||||
)
|
||||
from rowers.models import (
|
||||
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)
|
||||
def rower_view_trainingplan(request,id=0):
|
||||
pass
|
||||
def rower_trainingplan_view(request,id=0):
|
||||
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):
|
||||
model = TrainingPlan
|
||||
|
||||
Reference in New Issue
Block a user