improved sunday algorithm
This commit is contained in:
@@ -16989,7 +16989,7 @@ class TrainingTargetUpdate(UpdateView):
|
|||||||
def allsundays(startdate,enddate):
|
def allsundays(startdate,enddate):
|
||||||
d = startdate
|
d = startdate
|
||||||
d += timedelta(days = 6 - d.weekday()) # first Sunday
|
d += timedelta(days = 6 - d.weekday()) # first Sunday
|
||||||
while d<enddate:
|
while d<=enddate:
|
||||||
yield d
|
yield d
|
||||||
d += timedelta(days=7)
|
d += timedelta(days=7)
|
||||||
|
|
||||||
@@ -16997,6 +16997,7 @@ def allsundays(startdate,enddate):
|
|||||||
message="This functionality requires a Coach or Self-Coach plan",
|
message="This functionality requires a Coach or Self-Coach plan",
|
||||||
redirect_field_name=None)
|
redirect_field_name=None)
|
||||||
def planmesocyclebyweek(request,id=0,userid=0):
|
def planmesocyclebyweek(request,id=0,userid=0):
|
||||||
|
print 'planning by week'
|
||||||
try:
|
try:
|
||||||
cycle = TrainingMesoCycle.objects.get(id=id)
|
cycle = TrainingMesoCycle.objects.get(id=id)
|
||||||
except TrainingMesoCycle.DoesNotExist:
|
except TrainingMesoCycle.DoesNotExist:
|
||||||
@@ -17014,17 +17015,19 @@ def planmesocyclebyweek(request,id=0,userid=0):
|
|||||||
|
|
||||||
#we're still here. We have permission
|
#we're still here. We have permission
|
||||||
sundays = [s for s in allsundays(cycle.startdate,cycle.enddate)]
|
sundays = [s for s in allsundays(cycle.startdate,cycle.enddate)]
|
||||||
for i in range(len(sundays)-1):
|
for i in range(len(sundays)):
|
||||||
monday = sundays[i]+timedelta(days=1)
|
if i==0:
|
||||||
nextsunday = sundays[i+1]
|
|
||||||
if i == 0 and monday > cycle.startdate:
|
|
||||||
monday = cycle.startdate
|
monday = cycle.startdate
|
||||||
if nextsunday < cycle.enddate and i == len(sundays)-2:
|
else:
|
||||||
nextsunday = cycle.enddate
|
monday = sundays[i]-timedelta(days=6)
|
||||||
|
if monday < cycle.startdate:
|
||||||
|
monday = cycle.startdate
|
||||||
|
|
||||||
|
nextsunday = sundays[i]
|
||||||
micro = TrainingMicroCycle(startdate = monday,
|
micro = TrainingMicroCycle(startdate = monday,
|
||||||
enddate = nextsunday,
|
enddate = nextsunday,
|
||||||
plan = cycle,
|
plan = cycle,
|
||||||
name = 'Week %s' % sundays[i+1].isocalendar()[1],
|
name = 'Week %s' % monday.isocalendar()[1],
|
||||||
type = 'userdefined')
|
type = 'userdefined')
|
||||||
micro.save()
|
micro.save()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user