diff --git a/rowers/models.py b/rowers/models.py index 6a93a110..678920bb 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -668,6 +668,8 @@ class GeoPoint(models.Model): # of multiple GeoPoint instances +def half_year_from_now(): + return timezone.now()+timezone.timedelta(days=182) # models related to training planning - draft @@ -676,7 +678,7 @@ class TrainingTarget(models.Model): rower = models.ForeignKey(Rower) name = models.CharField(max_length=150,blank=True) date = models.DateField( - default=timezone.now()+datetime.timedelta(days=182)) + default=half_year_from_now) notes = models.TextField(max_length=300,blank=True) class TrainingTargetForm(ModelForm): @@ -705,13 +707,14 @@ class TrainingTargetForm(ModelForm): # although such a TrainingGoal could have automatically calculated # values without needing the user to assign + class TrainingPlan(models.Model): rower = models.ForeignKey(Rower) name = models.CharField(max_length=150,blank=True) target = models.ForeignKey(TrainingTarget,blank=True) startdate = models.DateField(default=timezone.now) enddate = models.DateField( - default=timezone.now()+datetime.timedelta(days=182)) + default=half_year_from_now) class TrainingPlanForm(ModelForm): class Meta: @@ -738,7 +741,7 @@ class TrainingMacroCycle(models.Model): name = models.CharField(max_length=150,blank=True) startdate = models.DateField(default=timezone.now) enddate = models.DateField( - default=timezone.now()+datetime.timedelta(days=182)) + default=half_year_from_now) notes = models.TextField(max_length=300,blank=True) type = models.CharField(default='filler', choices=cycletypechoices, @@ -749,7 +752,7 @@ class TrainingMesoCycle(models.Model): name = models.CharField(max_length=150,blank=True) startdate = models.DateField(default=timezone.now) enddate = models.DateField( - default=timezone.now()+datetime.timedelta(days=182)) + default=half_year_from_now) notes = models.TextField(max_length=300,blank=True) type = models.CharField(default='filler', choices=cycletypechoices, @@ -761,7 +764,7 @@ class TrainingMicroCycle(models.Model): name = models.CharField(max_length=150,blank=True) startdate = models.DateField(default=timezone.now) enddate = models.DateField( - default=timezone.now()+datetime.timedelta(days=182)) + default=half_year_from_now) notes = models.TextField(max_length=300,blank=True) type = models.CharField(default='filler', choices=cycletypechoices, @@ -816,7 +819,8 @@ class PlannedSession(models.Model): name = models.CharField(max_length=150,blank=True) - comment = models.TextField(max_length=300,blank=True) + comment = models.TextField(max_length=300,blank=True, + ) startdate = models.DateField(default=timezone.now, verbose_name='Start Date') @@ -826,7 +830,8 @@ class PlannedSession(models.Model): sessiontype = models.CharField(default='session', choices=sessiontypechoices, - max_length=150) + max_length=150, + verbose_name='Session Type') sessionvalue = models.IntegerField(default=60,verbose_name='Value') @@ -855,31 +860,11 @@ class PlannedSession(models.Model): sessionmode = models.CharField(default='distance', choices=sessionmodechoices, - max_length=150) + max_length=150, + verbose_name='Session Mode') hasranking = models.BooleanField(default=False) - -class PlannedSessionForm(ModelForm): - class Meta: - model = PlannedSession - fields = ['startdate', - 'enddate', - 'sessiontype', - 'sessionmode', - 'sessionvalue', - 'sessionunit', - 'comment', - ] - widgets = { - 'comment': forms.Textarea, - 'startdate': SelectDateWidget( - years=range( - timezone.now().year-1,timezone.now().year+1)), - 'enddate': SelectDateWidget( - years=range( - timezone.now().year-1,timezone.now().year+1)), - } - + def __unicode__(self): name = self.name @@ -893,6 +878,30 @@ class PlannedSessionForm(ModelForm): ) return stri + + +class PlannedSessionForm(ModelForm): + class Meta: + model = PlannedSession + fields = ['startdate', + 'enddate', + 'name', + 'sessiontype', + 'sessionmode', + 'sessionvalue', + 'sessionunit', + 'comment', + ] + widgets = { + 'comment': forms.Textarea, + 'startdate': SelectDateWidget( + years=range( + timezone.now().year-1,timezone.now().year+2)), + 'enddate': SelectDateWidget( + years=range( + timezone.now().year-1,timezone.now().year+2)), + } + # Workout class Workout(models.Model): diff --git a/rowers/plannedsessions.py b/rowers/plannedsessions.py index 3de50ad2..92180bd4 100644 --- a/rowers/plannedsessions.py +++ b/rowers/plannedsessions.py @@ -17,7 +17,7 @@ queuehigh = django_rq.get_queue('low') from rowers.models import ( Rower, Workout, GeoCourse, TrainingMicroCycle,TrainingMesoCycle,TrainingMacroCycle, - TrainingPlan, + TrainingPlan,PlannedSession, ) import metrics @@ -103,3 +103,13 @@ def remove_rower_session(r,ps): ps.rower.remove(r) return 1 + +def get_sessions(r,startdate=timezone.now(), + enddate=timezone.now()+timezone.timedelta(+1000)): + sps = PlannedSession.objects.filter( + rower__in=[r], + startdate__gte=startdate, + enddate__lte=enddate, + ).order_by("startdate") + + return sps diff --git a/rowers/templates/plannedsessioncreate.html b/rowers/templates/plannedsessioncreate.html index d977bff9..b3c53315 100644 --- a/rowers/templates/plannedsessioncreate.html +++ b/rowers/templates/plannedsessioncreate.html @@ -7,9 +7,9 @@
Not yet defined
++ Click on session name to view +
+| After | +Before | +Name | +Value | ++ | Edit | +Delete | +
|---|---|---|---|---|---|---|
| {{ ps.startdate|date:"Y-m-d" }} | +{{ ps.enddate|date:"Y-m-d" }} | ++ {% if ps.name != '' %} + {{ ps.name }} + {% else %} + Unnamed Session + {% endif %} + | +{{ ps.sessionvalue }} | +{{ ps.sessionunit }} | ++ Edit + | ++ Delete + | +