added plan macro by months
This commit is contained in:
@@ -104,6 +104,10 @@
|
||||
/
|
||||
<a href="/rowers/deletemacrocycle/{{ macrocycle.0.id }}/">delete</a>
|
||||
/
|
||||
<a href="/rowers/macrocycle/{{ macrocycle.0.id }}/planbymonths/user/{{ rower.user.id }}">
|
||||
Replan by Months
|
||||
</a>
|
||||
/
|
||||
{% endif %}
|
||||
<a href='/rowers/sessions/{{ macrocycle.0.startdate|date:"Y-m-d" }}/{{ macrocycle.0.enddate|date:"Y-m-d" }}/user/{{ rower.user.id }}'>sessions</a>
|
||||
</td>
|
||||
|
||||
@@ -441,6 +441,8 @@ urlpatterns = [
|
||||
name='macrocycle_update_view'),
|
||||
url(r'^mesocycle/(?P<pk>\d+)/$',views.TrainingMesoCycleUpdate.as_view(),
|
||||
name='mesocycle_update_view'),
|
||||
url(r'^macrocycle/(?P<id>\d+)/planbymonths/$',views.planmacrocyclebymonth),
|
||||
url(r'^macrocycle/(?P<id>\d+)/planbymonths/user/(?P<userid>\d+)/$',views.planmacrocyclebymonth),
|
||||
url(r'^mesocycle/(?P<id>\d+)/planbyweeks/$',views.planmesocyclebyweek),
|
||||
url(r'^mesocycle/(?P<id>\d+)/planbyweeks/user/(?P<userid>\d+)/$',views.planmesocyclebyweek),
|
||||
url(r'^microcycle/(?P<pk>\d+)/$',views.TrainingMicroCycleUpdate.as_view(),
|
||||
|
||||
@@ -17027,5 +17027,58 @@ def planmesocyclebyweek(request,id=0,userid=0):
|
||||
'thismicroid':str(micros[0].id)})
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
def allmonths(startdate,enddate):
|
||||
d = startdate
|
||||
while d<enddate:
|
||||
yield d
|
||||
d = datetime.date(d.year+(d.month / 12),((d.month % 12) + 1),1)
|
||||
|
||||
@user_passes_test(hasplannedsessions,login_url="/rowers/promembership",
|
||||
message="This functionality requires a Coach or Self-Coach plan",
|
||||
redirect_field_name=None)
|
||||
def planmacrocyclebymonth(request,id=0,userid=0):
|
||||
try:
|
||||
cycle = TrainingMacroCycle.objects.get(id=id)
|
||||
except TrainingMacroCycle.DoesNotExist:
|
||||
raise Http404("Training Cycle does not exist")
|
||||
|
||||
if not checkaccessuser(request.user,cycle.plan.manager):
|
||||
raise PermissionDenied("You are not allowed to do this")
|
||||
|
||||
mesos = TrainingMesoCycle.objects.filter(plan=cycle)
|
||||
for m in mesos:
|
||||
m.delete()
|
||||
|
||||
cycle.type = 'userdefined'
|
||||
cycle.save()
|
||||
|
||||
#we're still here. We have permission
|
||||
monthstarts = [d for d in allmonths(cycle.startdate,cycle.enddate)]
|
||||
monthstarts.append(cycle.enddate)
|
||||
for i in range(len(monthstarts)-1):
|
||||
firstday = monthstarts[i]
|
||||
lastday = monthstarts[i+1]-timedelta(days=1)
|
||||
if lastday < cycle.enddate and i == len(monthstarts)-2:
|
||||
lastday = cycle.enddate
|
||||
|
||||
print i,firstday,lastday,monthstarts[i],monthstarts[i+1]
|
||||
|
||||
meso = TrainingMesoCycle(startdate = firstday,
|
||||
enddate = lastday,
|
||||
plan = cycle,
|
||||
name = '%s' % firstday.strftime("%B"),
|
||||
type = 'userdefined')
|
||||
meso.save()
|
||||
|
||||
mesos = TrainingMesoCycle.objects.filter(plan=cycle)
|
||||
|
||||
url = reverse(rower_trainingplan_view,
|
||||
kwargs = {'userid':str(userid),
|
||||
'id':str(cycle.plan.id),
|
||||
'thismesoid':str(mesos[0].id)})
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user