From 084e384aaa913d9b23ef61e3d4bc7accd57d0d59 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 7 Apr 2022 12:14:47 +0200 Subject: [PATCH] works --- rowers/models.py | 19 ++++++++++--- rowers/templates/stepeditor.html | 46 +++++++++++++++++++++++++++++--- rowers/views/planviews.py | 46 ++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 7 deletions(-) diff --git a/rowers/models.py b/rowers/models.py index efc43f81..06364051 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -2420,11 +2420,11 @@ class PlannedSessionStep(models.Model): targetvalue = models.IntegerField(default=0) targettype = models.TextField(default='',max_length=200, blank=True, null=True, choices=targettypes) - customtargetvaluelow = models.IntegerField(default=0) - customtargetvaluehigh = models.IntegerField(default=0) + targetvaluelow = models.IntegerField(default=0) + targetvaluehigh = models.IntegerField(default=0) intensity = models.TextField(default='',max_length=200, blank=True, null=True, choices=intensitytypes) - notes = models.TextField(default='',max_length=200, blank=True, null=True) + description = models.TextField(default='',max_length=200, blank=True, null=True) color = models.TextField(default='#ddd',max_length=200) def save(self, *args, **kwargs): @@ -2437,6 +2437,19 @@ class PlannedSessionStep(models.Model): super(PlannedSessionStep, self).save(*args, **kwargs) + def asdict(self): + d = { + 'wkt_step_name': self.name, + 'durationType': self.durationtype, + 'durationValue': self.durationvalue, + 'targetValue': self.targetvalue, + 'description': self.description, + 'stepId': self.pk, + 'intensity': self.intensity, + } + + return d + class StepEditorForm(ModelForm): class Meta: model = PlannedSessionStep diff --git a/rowers/templates/stepeditor.html b/rowers/templates/stepeditor.html index 088275c4..ecfee243 100644 --- a/rowers/templates/stepeditor.html +++ b/rowers/templates/stepeditor.html @@ -31,7 +31,8 @@ {% endfor %} -
+
    +
  • Add new step

    @@ -40,7 +41,14 @@ {% csrf_token %} - + +
  • +

    Step Information

    +
    +

    Step information

    +
    +
  • + {% endblock %} {% block scripts %} @@ -49,6 +57,15 @@ diff --git a/rowers/views/planviews.py b/rowers/views/planviews.py index 72236892..6612e01f 100644 --- a/rowers/views/planviews.py +++ b/rowers/views/planviews.py @@ -7,6 +7,7 @@ from rowers.views.statements import * import rowers.garmin_stuff as gs from rowers import credits from json.decoder import JSONDecodeError +from rowers.utils import step_to_string @login_required @@ -3013,6 +3014,40 @@ def stepadder(request, id=0): redirect_field_name=None) def stepeditor(request, id=0): ps = get_object_or_404(PlannedSession, pk=id) + if ps.steps: + for step in ps.steps['steps']: + print(step) + durationtype = step.get('durationType','') + durationvalue = step.get('durationValue',0) + targetvalue = step.get('targetValue',0) + targettype = step.get('targetType','') + targetvaluelow = step.get('targetValueLow',0) + targetvaluehigh = step.get('targetValueHigh',0) + intensity = step.get('intensity','Active') + + archived_steps = PlannedSessionStep.objects.filter( + manager = request.user, + durationtype = durationtype, + durationvalue = durationvalue, + targetvalue = targetvalue, + targettype = targettype, + targetvaluelow = targetvaluelow, + targetvaluehigh = targetvaluehigh, + intensity = intensity, + ).count() + if not archived_steps and durationvalue != 0: + s = PlannedSessionStep( + manager = request.user, + durationtype = durationtype, + durationvalue = durationvalue, + targetvalue = targetvalue, + targettype = targettype, + targetvaluelow = targetvaluelow, + targetvaluehigh = targetvaluehigh, + intensity = intensity, + name = step.get('wkt_step_name','Step') + ) + s.save() ps.steps = {} @@ -3028,9 +3063,20 @@ def stepeditor(request, id=0): steps = PlannedSessionStep.objects.filter(manager=request.user) + + stepdescriptions = {} + + for step in steps: + stepdescriptions[step.id] = step_to_string(step.asdict(), short=False)[0] + + print(stepdescriptions) + print(steps) + + return render(request, 'stepeditor.html', { 'steps':steps, + 'stepdescriptions': stepdescriptions, 'form':form, 'ps':ps, })