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