Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Start adding the models for the improved routines

Roland Geider6f545685085f
diff --git a/wger/manager/models/__init__.py b/wger/manager/models/__init__.py
index fea4e1270..60c77740e 100644
--- a/wger/manager/models/__init__.py
+++ b/wger/manager/models/__init__.py
@@ -15,11 +15,16 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Local
+from .abstract_config import AbstractChangeConfig
from .day import Day
from .log import WorkoutLog
+from .reps_config import RepsConfig
+from .rest_config import RestConfig
+from .rir_config import RiRConfig
from .schedule import Schedule
from .schedule_step import ScheduleStep
from .session import WorkoutSession
from .set import Set
from .setting import Setting
+from .weight_config import WeightConfig
from .workout import Workout
diff --git a/wger/manager/models/abstract_config.py b/wger/manager/models/abstract_config.py
new file mode 100644
index 000000000..589690551
--- /dev/null
+++ b/wger/manager/models/abstract_config.py
@@ -0,0 +1,103 @@
+# This file is part of wger Workout Manager <https://github.com/wger-project>.
+# Copyright (C) 2013 - 2021 wger Team
+#
+# wger Workout Manager is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wger Workout Manager is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Django
+from django.db import models
+from django.utils.translation import gettext_lazy as _
+
+# wger
+from wger.manager.models.set_config import SetConfig
+
+
+class OperationChoices(models.TextChoices):
+ PLUS = "+"
+ MINUS = "-"
+
+
+class TriggerChoices(models.TextChoices):
+ SESSION = "session"
+ WEEK = "week"
+
+
+class StepChoices(models.TextChoices):
+ ABSOLUTE = "abs"
+ PERCENT = "percent"
+
+
+class AbstractChangeConfig(models.Model):
+ """
+ Abstract model for weight configurations
+ """
+
+ class Meta:
+ abstract = True
+
+ iteration = models.PositiveIntegerField()
+
+ value = models.DecimalField(
+ decimal_places=2,
+ )
+
+ set_config = models.ForeignKey(
+ SetConfig,
+ on_delete=models.CASCADE,
+ )
+
+ creation_date = models.DateTimeField(
+ _('Creation date'),
+ auto_now_add=True,
+ )
+
+ operation = models.CharField(
+ choices=OperationChoices.choices,
+ max_length=1,
+ default=OperationChoices.PLUS,
+ null=True,
+ )
+ """The operation"""
+
+ trigger = models.CharField(
+ choices=TriggerChoices.choices,
+ max_length=10,
+ default=TriggerChoices.SESSION,
+ null=True,
+ )
+ """When the changes are calculated"""
+
+ step = models.CharField(
+ choices=StepChoices.choices,
+ max_length=10,
+ default=StepChoices.ABSOLUTE,
+ null=True,
+ )
+ """The step by which the change will happen"""
+
+ replace = models.BooleanField(
+ default=False,
+ )
+ """
+ Flag indicating that there is no increase, but that the value will simply
+ be replaced with the new one
+ """
+
+ code = models.CharField(
+ max_length=100,
+ )
+ """
+ The name of a python class that will take care of the change logic.
+
+ If this is set, all other settings will be ignored.
+ """
diff --git a/wger/manager/models/day.py b/wger/manager/models/day.py
index f2da1eb21..f49764281 100644
--- a/wger/manager/models/day.py
+++ b/wger/manager/models/day.py
@@ -31,7 +31,11 @@ class Day(models.Model):
Model for a training day
"""
- training = models.ForeignKey(Workout, verbose_name=_('Workout'), on_delete=models.CASCADE)
+ training = models.ForeignKey(
+ Workout,
+ verbose_name=_('Workout'),
+ on_delete=models.CASCADE,
+ )
description = models.CharField(
max_length=100,
verbose_name=_('Description'),
diff --git a/wger/manager/models/reps_config.py b/wger/manager/models/reps_config.py
new file mode 100644
index 000000000..ce136c019
--- /dev/null
+++ b/wger/manager/models/reps_config.py
@@ -0,0 +1,29 @@
+# This file is part of wger Workout Manager <https://github.com/wger-project>.
+# Copyright (C) 2013 - 2021 wger Team
+#
+# wger Workout Manager is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wger Workout Manager is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# wger
+from wger.manager.models import AbstractChangeConfig
+
+
+class RepsConfig(AbstractChangeConfig):
+ """
+ Model for a routine
+ """
+
+ class Meta:
+ ordering = [
+ '-creation_date',
+ ]
diff --git a/wger/manager/models/rest_config.py b/wger/manager/models/rest_config.py
new file mode 100644
index 000000000..2102b8282
--- /dev/null
+++ b/wger/manager/models/rest_config.py
@@ -0,0 +1,29 @@
+# This file is part of wger Workout Manager <https://github.com/wger-project>.
+# Copyright (C) 2013 - 2021 wger Team
+#
+# wger Workout Manager is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wger Workout Manager is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# wger
+from wger.manager.models import AbstractChangeConfig
+
+
+class RestConfig(AbstractChangeConfig):
+ """
+ Model for a routine
+ """
+
+ class Meta:
+ ordering = [
+ '-creation_date',
+ ]
diff --git a/wger/manager/models/rir_config.py b/wger/manager/models/rir_config.py
new file mode 100644
index 000000000..f552b3d50
--- /dev/null
+++ b/wger/manager/models/rir_config.py
@@ -0,0 +1,29 @@
+# This file is part of wger Workout Manager <https://github.com/wger-project>.
+# Copyright (C) 2013 - 2021 wger Team
+#
+# wger Workout Manager is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wger Workout Manager is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# wger
+from wger.manager.models import AbstractChangeConfig
+
+
+class RiRConfig(AbstractChangeConfig):
+ """
+ Model for a routine
+ """
+
+ class Meta:
+ ordering = [
+ '-creation_date',
+ ]
diff --git a/wger/manager/models/routine.py b/wger/manager/models/routine.py
new file mode 100644
index 000000000..092022b38
--- /dev/null
+++ b/wger/manager/models/routine.py
@@ -0,0 +1,95 @@
+# This file is part of wger Workout Manager <https://github.com/wger-project>.
+# Copyright (C) 2013 - 2021 wger Team
+#
+# wger Workout Manager is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wger Workout Manager is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Django
+from django.contrib.auth.models import User
+from django.core.exceptions import ValidationError
+from django.db import models
+from django.urls import reverse
+from django.utils.translation import gettext_lazy as _
+
+
+class Routine(models.Model):
+ """
+ Model for a routine
+ """
+
+ class Meta:
+ ordering = [
+ '-creation_date',
+ ]
+
+ name = models.CharField(
+ verbose_name=_('Name'),
+ max_length=50,
+ blank=True,
+ )
+ description = models.TextField(
+ verbose_name=_('Description'),
+ max_length=1000,
+ blank=True,
+ )
+
+ creation_date = models.DateTimeField(
+ _('Creation date'),
+ auto_now_add=True,
+ )
+
+ start = models.DateField(
+ _('Start date'),
+ )
+
+ end = models.DateField(
+ _('End date'),
+ )
+
+ user = models.ForeignKey(
+ User,
+ verbose_name=_('User'),
+ on_delete=models.CASCADE,
+ )
+
+ def get_absolute_url(self):
+ """
+ Returns the canonical URL to view a workout
+ """
+ return reverse(
+ 'manager:routine:view',
+ kwargs={'pk': self.id},
+ )
+
+ def __str__(self):
+ """
+ Return a more human-readable representation
+ """
+ if self.name:
+ return self.name
+ else:
+ return f'{_("Routine")} ({self.creation_date})'
+
+ def get_owner_object(self):
+ """
+ Returns the object that has owner information
+ """
+ return self
+
+ def clean(self):
+ """
+ Perform some additional validations
+ """
+
+ if self.end and self.start and self.start > self.end:
+ raise ValidationError(_('The start time cannot be after the end time.'))
diff --git a/wger/manager/models/set_config.py b/wger/manager/models/set_config.py
new file mode 100644
index 000000000..19bee3dde
--- /dev/null
+++ b/wger/manager/models/set_config.py
@@ -0,0 +1,100 @@
+# This file is part of wger Workout Manager <https://github.com/wger-project>.
+# Copyright (C) 2013 - 2021 wger Team
+#
+# wger Workout Manager is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wger Workout Manager is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Django
+from django.core.validators import (
+ MaxValueValidator,
+ MinValueValidator,
+)
+from django.db import models
+from django.utils.translation import gettext_lazy as _
+
+# wger
+from wger.core.models import (
+ RepetitionUnit,
+ WeightUnit,
+)
+from wger.exercises.models import (
+ Exercise,
+ ExerciseBase,
+)
+from wger.utils.cache import reset_workout_canonical_form
+
+# Local
+from ..consts import RIR_OPTIONS
+from .set import Set
+
+
+class SetConfig(models.Model):
+ """
+ Set configuration for an exercise (weight, reps, etc.)
+ """
+
+ set = models.ForeignKey(
+ Set,
+ verbose_name=_('Sets'),
+ on_delete=models.CASCADE,
+ )
+
+ exercise = models.ForeignKey(
+ ExerciseBase,
+ verbose_name=_('Exercise'),
+ on_delete=models.CASCADE,
+ )
+
+ repetition_unit = models.ForeignKey(
+ RepetitionUnit,
+ verbose_name=_('Unit'),
+ default=1,
+ on_delete=models.CASCADE,
+ )
+ """
+ The repetition unit of a set. This can be e.g. a repetition, a minute, etc.
+ """
+
+ weight_unit = models.ForeignKey(
+ WeightUnit,
+ verbose_name=_('Unit'),
+ default=1,
+ on_delete=models.CASCADE,
+ )
+ """
+ The weight unit of a set. This can be e.g. kg, lb, km/h, etc.
+ """
+
+ order = models.PositiveIntegerField(
+ blank=True,
+ verbose_name=_('Order'),
+ )
+
+ comment = models.CharField(
+ max_length=100,
+ blank=True,
+ verbose_name=_('Comment'),
+ )
+
+ # Metaclass to set some other properties
+ class Meta:
+ ordering = [
+ 'order',
+ 'id',
+ ]
+
+ def get_owner_object(self):
+ """
+ Returns the object that has owner information
+ """
+ return self.set.exerciseday.training
diff --git a/wger/manager/models/weight_config.py b/wger/manager/models/weight_config.py
new file mode 100644
index 000000000..fa951546c
--- /dev/null
+++ b/wger/manager/models/weight_config.py
@@ -0,0 +1,29 @@
+# This file is part of wger Workout Manager <https://github.com/wger-project>.
+# Copyright (C) 2013 - 2021 wger Team
+#
+# wger Workout Manager is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wger Workout Manager is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# wger
+from wger.manager.models import AbstractChangeConfig
+
+
+class WeightConfig(AbstractChangeConfig):
+ """
+ Model for a routine
+ """
+
+ class Meta:
+ ordering = [
+ '-creation_date',
+ ]