Private
Public Access
1
0

adding macro and meso cycles and adding filler cycles

This commit is contained in:
Sander Roosendaal
2018-09-07 21:06:50 +02:00
parent 54cc552a99
commit 47eed84479

View File

@@ -1009,7 +1009,7 @@ class TrainingPlan(models.Model):
self.startdate = enddate
self.enddate = startdate
otherplans = TrainingPlan.objects.filter(rower=self.rower).exclude(pk=self.pk)
otherplans = TrainingPlan.objects.filter(rower=self.rower).exclude(pk=self.pk).order_by("-startdate")
for otherplan in otherplans:
if otherplan.startdate <= self.enddate and otherplan.startdate >= self.startdate:
@@ -1020,6 +1020,19 @@ class TrainingPlan(models.Model):
if not self.enddate <= self.startdate:
super(TrainingPlan,self).save(*args, **kwargs)
macrocycles = TrainingMacroCycle.objects.filter(plan = self)
if not macrocycles:
m = TrainingMacroCycle(
plan = self,
name = 'Filler',
startdate = self.startdate,
enddate = self.enddate,
)
m.save()
createmacrofillers(self)
class TrainingPlanForm(ModelForm):
class Meta:
model = TrainingPlan
@@ -1045,6 +1058,32 @@ cycletypechoices = (
('userdefined','User Defined')
)
def createmacrofillers(plan):
fillers = TrainingMacroCycle.objects.filter(
plan = plan, type = 'filler'
)
for f in fillers:
f.delete()
cycles = TrainingMacroCycle.objects.filter(
plan = plan
).order_by("-startdate")
thedate = plan.enddate
while cycles:
if cycles[0].enddate < thedate:
macr = TrainingMacroCycle(
startdate = cycles[0].enddate+datetime.timedelta(days=1),
enddate = thedate,
type='filler',
name='Filler'
)
macr.save()
thedate = cycles[0].startdate-datetime.timedelta(days=1)
cycles = cycles[1:]
class TrainingMacroCycle(models.Model):
plan = models.ForeignKey(TrainingPlan)
name = models.CharField(max_length=150,blank=True)
@@ -1056,6 +1095,44 @@ class TrainingMacroCycle(models.Model):
choices=cycletypechoices,
max_length=150)
def save(self, *args, **kwargs):
if self.enddate < self.startdate:
startdate = self.startdate
enddate = self.enddate
self.startdate = enddate
self.enddate = startdate
fillers = TrainingMacroCycle.objects.filter(
plan=self.plan,type='filler')
for f in fillers:
f.delete()
othercycles = TrainingMacroCycle.objects.filter(
plan=self.plan).exclude(pk=self.pk).order_by("-startdate")
for othercycle in othercycles:
if othercycle.startdate <= self.enddate and othercycle.startdate >= self.startdate:
self.enddate = othercycle.startdate-datetime.timedelta(days=1)
if othercycle.enddate >= self.startdate and othercycle.enddate <= self.enddate:
self.startdate = othercycle.enddate+datetime.timedelta(days=1)
if not self.enddate <= self.startdate:
super(TrainingMacroCycle,self).save(*args, **kwargs)
mesocycles = TrainingMesoCycle.objects.filter(plan = self)
if not mesocycles:
meso = TrainingMesoCycle(
plan = self,
name = 'Filler',
startdate = self.startdate,
enddate = self.enddate,
)
meso.save()
class TrainingMesoCycle(models.Model):
plan = models.ForeignKey(TrainingMacroCycle)
name = models.CharField(max_length=150,blank=True)