Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Keep history for images and videos as well

Roland Geiderefeb9c8c7ffc
diff --git a/wger/exercises/migrations/0020_historicalexerciseimage_historicalexercisevideo.py b/wger/exercises/migrations/0020_historicalexerciseimage_historicalexercisevideo.py
new file mode 100644
index 000000000..785cf5cda
--- /dev/null
+++ b/wger/exercises/migrations/0020_historicalexerciseimage_historicalexercisevideo.py
@@ -0,0 +1,75 @@
+# Generated by Django 3.2.15 on 2022-09-22 19:39
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+import simple_history.models
+import uuid
+import wger.exercises.models.video
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('core', '0014_merge_20210818_1735'),
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ('exercises', '0019_exercise_crowdsourcing_changes'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='HistoricalExerciseVideo',
+ fields=[
+ ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
+ ('license_author', models.CharField(blank=True, help_text='If you are not the author, enter the name or source here. This is needed for some licenses e.g. the CC-BY-SA.', max_length=50, null=True, verbose_name='Author')),
+ ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, verbose_name='UUID')),
+ ('is_main', models.BooleanField(default=False, verbose_name='Main video')),
+ ('video', models.TextField(max_length=100, validators=[wger.exercises.models.video.validate_video], verbose_name='Video')),
+ ('size', models.IntegerField(default=0, editable=False, verbose_name='Size')),
+ ('duration', models.DecimalField(decimal_places=2, default=0, editable=False, max_digits=12, verbose_name='Duration')),
+ ('width', models.IntegerField(default=0, editable=False, verbose_name='Width')),
+ ('height', models.IntegerField(default=0, editable=False, verbose_name='Height')),
+ ('codec', models.CharField(default='', editable=False, max_length=30, verbose_name='Codec')),
+ ('codec_long', models.CharField(default='', editable=False, max_length=100, verbose_name='Codec, long name')),
+ ('history_id', models.AutoField(primary_key=True, serialize=False)),
+ ('history_date', models.DateTimeField(db_index=True)),
+ ('history_change_reason', models.CharField(max_length=100, null=True)),
+ ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
+ ('exercise_base', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='exercises.exercisebase', verbose_name='Exercise')),
+ ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
+ ('license', models.ForeignKey(blank=True, db_constraint=False, default=2, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='core.license', verbose_name='License')),
+ ],
+ options={
+ 'verbose_name': 'historical exercise video',
+ 'verbose_name_plural': 'historical exercise videos',
+ 'ordering': ('-history_date', '-history_id'),
+ 'get_latest_by': ('history_date', 'history_id'),
+ },
+ bases=(simple_history.models.HistoricalChanges, models.Model),
+ ),
+ migrations.CreateModel(
+ name='HistoricalExerciseImage',
+ fields=[
+ ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
+ ('license_author', models.CharField(blank=True, help_text='If you are not the author, enter the name or source here. This is needed for some licenses e.g. the CC-BY-SA.', max_length=50, null=True, verbose_name='Author')),
+ ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, verbose_name='UUID')),
+ ('image', models.TextField(help_text='Only PNG and JPEG formats are supported', max_length=100, verbose_name='Image')),
+ ('is_main', models.BooleanField(default=False, help_text='Tick the box if you want to set this image as the main one for the exercise (will be shown e.g. in the search). The first image is automatically marked by the system.', verbose_name='Main picture')),
+ ('style', models.CharField(choices=[('1', 'Line'), ('2', '3D'), ('3', 'Low-poly'), ('4', 'Photo'), ('5', 'Other')], default='4', help_text='The art style of your image', max_length=1)),
+ ('history_id', models.AutoField(primary_key=True, serialize=False)),
+ ('history_date', models.DateTimeField(db_index=True)),
+ ('history_change_reason', models.CharField(max_length=100, null=True)),
+ ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
+ ('exercise_base', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='exercises.exercisebase', verbose_name='Exercise')),
+ ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
+ ('license', models.ForeignKey(blank=True, db_constraint=False, default=2, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='core.license', verbose_name='License')),
+ ],
+ options={
+ 'verbose_name': 'historical exercise image',
+ 'verbose_name_plural': 'historical exercise images',
+ 'ordering': ('-history_date', '-history_id'),
+ 'get_latest_by': ('history_date', 'history_id'),
+ },
+ bases=(simple_history.models.HistoricalChanges, models.Model),
+ ),
+ ]
diff --git a/wger/exercises/models/base.py b/wger/exercises/models/base.py
index 63f8eb5c5..ccf130be4 100644
--- a/wger/exercises/models/base.py
+++ b/wger/exercises/models/base.py
@@ -109,7 +109,13 @@ class ExerciseBase(AbstractLicenseModel, AbstractHistoryMixin, models.Model):
"""
Return a more human-readable representation
"""
- return f"base {self.uuid}"
+ return f"base {self.uuid} ({self.get_exercise(ENGLISH_SHORT_NAME).name})"
+
+ def get_absolute_url(self):
+ """
+ Returns the canonical URL to view an exercise
+ """
+ return reverse('exercise:exercise:view-base', kwargs={'id': self.id})
#
# Own methods
diff --git a/wger/exercises/models/image.py b/wger/exercises/models/image.py
index ac24c6cbd..56343fb1a 100644
--- a/wger/exercises/models/image.py
+++ b/wger/exercises/models/image.py
@@ -22,6 +22,7 @@ import uuid
from django.core import mail
from django.db import models
from django.utils.translation import gettext_lazy as _
+from simple_history.models import HistoricalRecords
# wger
from wger.core.models import Language
@@ -101,6 +102,15 @@ class ExerciseImage(AbstractLicenseModel, models.Model):
)
"""The art style of the image"""
+ history = HistoricalRecords()
+ """Edit history"""
+
+ def get_absolute_url(self):
+ """
+ Return the image URL
+ """
+ return self.image.url
+
class Meta:
"""
Set default ordering
diff --git a/wger/exercises/models/video.py b/wger/exercises/models/video.py
index a6bdf0599..b90352649 100644
--- a/wger/exercises/models/video.py
+++ b/wger/exercises/models/video.py
@@ -22,7 +22,7 @@ import uuid
from django.core.exceptions import ValidationError
from django.db import models
from django.utils.translation import gettext_lazy as _
-
+from simple_history.models import HistoricalRecords
try:
# Third Party
@@ -150,6 +150,15 @@ class ExerciseVideo(AbstractLicenseModel, models.Model):
)
"""The video codec, in full"""
+ history = HistoricalRecords()
+ """Edit history"""
+
+ def get_absolute_url(self):
+ """
+ Returns the video URL
+ """
+ return self.video.url
+
class Meta:
"""
Set default ordering