|
|
|
|
@@ -16725,7 +16725,7 @@ class TrainingMacroCycleUpdate(UpdateView):
|
|
|
|
|
|
|
|
|
|
def get_object(self, *args, **kwargs):
|
|
|
|
|
obj = super(TrainingMacroCycleUpdate, self).get_object(*args, **kwargs)
|
|
|
|
|
if obj.plan.manager is not None and self.request.user != obj.plan.manager:
|
|
|
|
|
if obj.plan.manager is not None and self.request.user.rower != obj.plan.manager:
|
|
|
|
|
raise PermissionDenied('You are not allowed to edit this training plan cycle')
|
|
|
|
|
|
|
|
|
|
if not checkaccessuser(self.request.user,obj.plan.rower):
|
|
|
|
|
@@ -16800,7 +16800,7 @@ class TrainingMesoCycleUpdate(UpdateView):
|
|
|
|
|
def get_object(self, *args, **kwargs):
|
|
|
|
|
obj = super(TrainingMesoCycleUpdate, self).get_object(*args, **kwargs)
|
|
|
|
|
r = obj.plan.plan.rower
|
|
|
|
|
if obj.plan.plan.manager is not None and self.request.user != obj.plan.plan.manager:
|
|
|
|
|
if obj.plan.plan.manager is not None and self.request.user.rower != obj.plan.plan.manager:
|
|
|
|
|
raise PermissionDenied('You are not allowed to edit this training plan cycle')
|
|
|
|
|
|
|
|
|
|
if not checkaccessuser(self.request.user,r):
|
|
|
|
|
@@ -16881,7 +16881,7 @@ class TrainingMicroCycleUpdate(UpdateView):
|
|
|
|
|
def get_object(self, *args, **kwargs):
|
|
|
|
|
obj = super(TrainingMicroCycleUpdate, self).get_object(*args, **kwargs)
|
|
|
|
|
r = obj.plan.plan.plan.rower
|
|
|
|
|
if obj.plan.plan.plan.manager is not None and self.request.user != obj.plan.plan.plan.manager.user:
|
|
|
|
|
if obj.plan.plan.plan.manager is not None and self.request.user.rower != obj.plan.plan.plan.manager:
|
|
|
|
|
raise PermissionDenied('You are not allowed to edit this training plan cycle')
|
|
|
|
|
|
|
|
|
|
if not checkaccessuser(self.request.user,r):
|
|
|
|
|
@@ -16898,6 +16898,41 @@ class TrainingPlanUpdate(UpdateView):
|
|
|
|
|
template_name = 'trainingplan_edit.html'
|
|
|
|
|
form_class = TrainingPlanForm
|
|
|
|
|
|
|
|
|
|
# extra parameters
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
|
context = super(TrainingPlanUpdate, self).get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
|
if 'userid' in kwargs:
|
|
|
|
|
userid = kwargs['userid']
|
|
|
|
|
else:
|
|
|
|
|
userid=0
|
|
|
|
|
|
|
|
|
|
breadcrumbs = [
|
|
|
|
|
{
|
|
|
|
|
'url':reverse(plannedsessions_view,
|
|
|
|
|
kwargs={'userid':userid}),
|
|
|
|
|
'name': 'Plan'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'url':reverse(rower_trainingplan_view,
|
|
|
|
|
kwargs={'userid':userid,
|
|
|
|
|
'id':self.object.id}),
|
|
|
|
|
'name': self.object.name
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'url':reverse('trainingplan_update_view',
|
|
|
|
|
kwargs={'pk':self.object.pk}),
|
|
|
|
|
'name': 'Edit'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
context['active'] = 'nav-plan'
|
|
|
|
|
context['breadcrumbs'] = breadcrumbs
|
|
|
|
|
context['rower'] = getrequestrower(self.request,userid=userid)
|
|
|
|
|
|
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
|
return reverse(rower_create_trainingplan)
|
|
|
|
|
|
|
|
|
|
@@ -16912,7 +16947,7 @@ class TrainingPlanUpdate(UpdateView):
|
|
|
|
|
|
|
|
|
|
def get_object(self, *args, **kwargs):
|
|
|
|
|
obj = super(TrainingPlanUpdate, self).get_object(*args, **kwargs)
|
|
|
|
|
if obj.manager is not None and self.request.user != obj.manager.user:
|
|
|
|
|
if obj.manager is not None and self.request.user.rower != obj.manager.user:
|
|
|
|
|
raise PermissionDenied('You are not allowed to edit this training plan cycle')
|
|
|
|
|
|
|
|
|
|
if not checkaccessuser(self.request.user,obj.rower):
|
|
|
|
|
@@ -16935,15 +16970,62 @@ class TrainingTargetUpdate(UpdateView):
|
|
|
|
|
|
|
|
|
|
def get_object(self, *args, **kwargs):
|
|
|
|
|
obj = super(TrainingTargetUpdate, self).get_object(*args, **kwargs)
|
|
|
|
|
if obj.manager is not None and self.request.user != obj.manager.user:
|
|
|
|
|
if obj.manager is not None and self.request.user.rower != obj.manager.user:
|
|
|
|
|
raise PermissionDenied('You are not allowed to edit this training plan cycle')
|
|
|
|
|
|
|
|
|
|
if not checkaccessuser(self.request.user,obj.rower):
|
|
|
|
|
raise PermissionDenied('You are not allowed to edit this training plan target')
|
|
|
|
|
return obj
|
|
|
|
|
|
|
|
|
|
def allsundays(startdate,enddate):
|
|
|
|
|
d = startdate
|
|
|
|
|
d += timedelta(days = 6 - d.weekday()) # first Sunday
|
|
|
|
|
while d<enddate:
|
|
|
|
|
yield d
|
|
|
|
|
d += timedelta(days=7)
|
|
|
|
|
|
|
|
|
|
@user_passes_test(hasplannedsessions,login_url="/rowers/promembership",
|
|
|
|
|
message="This functionality requires a Coach or Self-Coach plan",
|
|
|
|
|
redirect_field_name=None)
|
|
|
|
|
def bla():
|
|
|
|
|
pass
|
|
|
|
|
def planmesocyclebyweek(request,id=0,userid=0):
|
|
|
|
|
try:
|
|
|
|
|
cycle = TrainingMesoCycle.objects.get(id=id)
|
|
|
|
|
except TrainingMesoCycle.DoesNotExist:
|
|
|
|
|
raise Http404("Training Cycle does not exist")
|
|
|
|
|
|
|
|
|
|
if not checkaccessuser(request.user,cycle.plan.plan.manager):
|
|
|
|
|
raise PermissionDenied("You are not allowed to do this")
|
|
|
|
|
|
|
|
|
|
micros = TrainingMicroCycle.objects.filter(plan=cycle)
|
|
|
|
|
for m in micros:
|
|
|
|
|
m.delete()
|
|
|
|
|
|
|
|
|
|
cycle.type = 'userdefined'
|
|
|
|
|
cycle.save()
|
|
|
|
|
|
|
|
|
|
#we're still here. We have permission
|
|
|
|
|
sundays = [s for s in allsundays(cycle.startdate,cycle.enddate)]
|
|
|
|
|
for i in range(len(sundays)-1):
|
|
|
|
|
monday = sundays[i]+timedelta(days=1)
|
|
|
|
|
nextsunday = sundays[i+1]
|
|
|
|
|
if i == 0 and monday > cycle.startdate:
|
|
|
|
|
monday = cycle.startdate
|
|
|
|
|
if nextsunday < cycle.enddate and i == len(sundays)-2:
|
|
|
|
|
nextsunday = cycle.enddate
|
|
|
|
|
micro = TrainingMicroCycle(startdate = monday,
|
|
|
|
|
enddate = nextsunday,
|
|
|
|
|
plan = cycle,
|
|
|
|
|
name = 'Week %s' % sundays[i+1].isocalendar()[1],
|
|
|
|
|
type = 'userdefined')
|
|
|
|
|
micro.save()
|
|
|
|
|
|
|
|
|
|
micros = TrainingMicroCycle.objects.filter(plan=cycle)
|
|
|
|
|
|
|
|
|
|
url = reverse(rower_trainingplan_view,
|
|
|
|
|
kwargs = {'userid':str(userid),
|
|
|
|
|
'id':str(cycle.plan.plan.id),
|
|
|
|
|
'thismicroid':str(micros[0].id)})
|
|
|
|
|
|
|
|
|
|
return HttpResponseRedirect(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|