diff --git a/rowers/models.py b/rowers/models.py index 924c4a4a..00fd6da7 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -1095,7 +1095,20 @@ def createmacrofillers(plan): thedate = cycles[0].startdate-datetime.timedelta(days=1) cycles = cycles[1:] + cycles = TrainingMacroCycle.objects.filter( + plan = plan + ).order_by("startdate") + if cycles[0].startdate > plan.startdate: + macr = TrainingMacroCycle( + plan=plan, + startdate = plan.startdate, + enddate = cycles[0].startdate-datetime.timedelta(days=1), + type='filler', + name='Filler' + ) + macr.save() + def createmesofillers(plan): fillers = TrainingMesoCycle.objects.filter( plan = plan, type = 'filler' @@ -1131,6 +1144,20 @@ def createmesofillers(plan): macr.save() thedate = cycles[0].startdate-datetime.timedelta(days=1) cycles = cycles[1:] + + cycles = TrainingMesoCycle.objects.filter( + plan = plan + ).order_by("startdate") + + if cycles[0].startdate > plan.startdate: + macr = TrainingMesoCycle( + plan=plan, + startdate = plan.startdate, + enddate = cycles[0].startdate-datetime.timedelta(days=1), + type='filler', + name='Filler' + ) + macr.save() def createmicrofillers(plan): @@ -1169,6 +1196,20 @@ def createmicrofillers(plan): thedate = cycles[0].startdate-datetime.timedelta(days=1) cycles = cycles[1:] + cycles = TrainingMicroCycle.objects.filter( + plan = plan + ).order_by("startdate") + + if cycles[0].startdate > plan.startdate: + macr = TrainingMicroCycle( + plan=plan, + startdate = plan.startdate, + enddate = cycles[0].startdate-datetime.timedelta(days=1), + type='filler', + name='Filler' + ) + macr.save() + def microcyclecheckdates(plan): cycles = TrainingMicroCycle.objects.filter( plan=plan @@ -1203,6 +1244,21 @@ def mesocyclecheckdates(plan): thedate = cycles[0].startdate-datetime.timedelta(days=1) cycles = cycles[1:] + cycles = TrainingMesoCycle.objects.filter( + plan=plan + ).order_by("startdate") + + thedate = plan.startdate + while cycles: + if cycles[0].startdate < thedate: + cycles[0].startdate = thedate + cycles[0].save() + try: + thedate = cycles[1].startdate-datetime.timedelta(days=1) + except IndexError: + pass + cycles = cycles[1:] + def macrocyclecheckdates(plan): cycles = TrainingMacroCycle.objects.filter( plan=plan diff --git a/rowers/templates/trainingplan.html b/rowers/templates/trainingplan.html index 62dbb83c..cb063a44 100644 --- a/rowers/templates/trainingplan.html +++ b/rowers/templates/trainingplan.html @@ -29,7 +29,7 @@ are typically used to address specific phases of preparation and to indicate the racing season and may span several months. Meso cycles can be used to group sequences of three to five light, medium and - hard weeks.

+ hard weeks. It is recommended to work from left to right, starting with the macro cycles.

Macro Cycles

@@ -42,6 +42,7 @@
+ {% now "Y-m-d" as todays_date %} {% for key,macrocycle in cycles.items %}
{% if macrocycle.0.type == 'filler' %} @@ -51,9 +52,11 @@ {% endif %}

{{ macrocycle.0.name }} ({{ macrocycle.0.startdate }} - {{ macrocycle.0.enddate }})

+ {% if todays_date <= macrocycle.0.enddate|date:"Y-m-d" %}

edit - / - delete

+ / + delete

+ {% endif %}
@@ -65,9 +68,13 @@ {% endif %}

{{ mesocycle.0.name }} ({{ mesocycle.0.startdate }} - {{ mesocycle.0.enddate }})

+ {% if mesocycle.0.plan.type == 'userdefined' %} + {% if todays_date <= mesocycle.0.enddate|date:"Y-m-d" %}

edit / - delete

+ delete

+ {% endif %} + {% endif %}
@@ -79,10 +86,14 @@ {% endif %}

{{ microcycle.name }} ({{ microcycle.startdate }} - {{ microcycle.enddate }})

+ {% if microcycle.plan.type == 'userdefined' %} + {% if todays_date <= microcycle.enddate|date:"Y-m-d" %}

edit / delete

+ {% endif %} + {% endif %}
{% endfor %} diff --git a/rowers/templates/trainingplan_create.html b/rowers/templates/trainingplan_create.html index 83a7654b..350e2119 100644 --- a/rowers/templates/trainingplan_create.html +++ b/rowers/templates/trainingplan_create.html @@ -100,8 +100,9 @@ {{ plan.startdate }} {{ plan.enddate }} {{ plan.name }} - Edit - Delete + Edit + Plan + Delete {% endfor %} diff --git a/rowers/templatetags/rowerfilters.py b/rowers/templatetags/rowerfilters.py index 80e888a7..dede3b70 100644 --- a/rowers/templatetags/rowerfilters.py +++ b/rowers/templatetags/rowerfilters.py @@ -275,3 +275,10 @@ def future_registered(race,r): is_complete, has_registered = race_rower_status(r,race) is_open = race.evaluation_closure > timezone.now() return has_registered and not is_complete and is_open + +@property +def is_past_due(self): + return datetime.date.today() > self.date +@property +def is_not_past_due(self): + return datetime.date.today() <= self.date