Self hosted FLOSS fitness/workout, nutrition and weight tracker
Formatting
Roland Geiderdd1827d00a08
diff --git a/wger/exercises/api/views.py b/wger/exercises/api/views.pyindex f7dd8e029..1e99dadda 100644--- a/wger/exercises/api/views.py+++ b/wger/exercises/api/views.py@@ -447,7 +447,7 @@ class ExerciseVideoViewSet(ModelViewSet):"""queryset = ExerciseVideo.objects.all()serializer_class = ExerciseVideoSerializer- permission_classes = (CanContributeExercises,)+ permission_classes = (CanContributeExercises, )ordering_fields = '__all__'filterset_fields = ('is_main',diff --git a/wger/exercises/migrations/0019_exercise_crowdsourcing_changes.py b/wger/exercises/migrations/0019_exercise_crowdsourcing_changes.pyindex 3ccb32c7a..bd35b4f5a 100644--- a/wger/exercises/migrations/0019_exercise_crowdsourcing_changes.py+++ b/wger/exercises/migrations/0019_exercise_crowdsourcing_changes.py@@ -378,16 +378,26 @@ class Migration(migrations.Migration):migrations.AlterField(model_name='exercise',name='exercise_base',- field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE,- related_name='exercises', to='exercises.exercisebase',- verbose_name='ExerciseBase'),+ field=models.ForeignKey(+ default=None,+ on_delete=django.db.models.deletion.CASCADE,+ related_name='exercises',+ to='exercises.exercisebase',+ verbose_name='ExerciseBase'+ ),),migrations.AlterField(model_name='historicalexercise',name='exercise_base',- field=models.ForeignKey(blank=True, db_constraint=False, default=None, null=True,- on_delete=django.db.models.deletion.DO_NOTHING,- related_name='+', to='exercises.exercisebase',- verbose_name='ExerciseBase'),+ field=models.ForeignKey(+ blank=True,+ db_constraint=False,+ default=None,+ null=True,+ on_delete=django.db.models.deletion.DO_NOTHING,+ related_name='+',+ to='exercises.exercisebase',+ verbose_name='ExerciseBase'+ ),),]diff --git a/wger/exercises/migrations/0020_historicalexerciseimage_historicalexercisevideo.py b/wger/exercises/migrations/0020_historicalexerciseimage_historicalexercisevideo.pyindex 785cf5cda..cf8734d0d 100644--- a/wger/exercises/migrations/0020_historicalexerciseimage_historicalexercisevideo.py+++ b/wger/exercises/migrations/0020_historicalexerciseimage_historicalexercisevideo.py@@ -20,24 +20,102 @@ class Migration(migrations.Migration):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')),+ (+ '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')),+ (+ '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')),+ (+ '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')),+ (+ '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')),+ (+ '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',@@ -50,19 +128,97 @@ class Migration(migrations.Migration):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')),+ (+ '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)),+ (+ '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')),+ (+ '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',diff --git a/wger/exercises/models/base.py b/wger/exercises/models/base.pyindex b28e9abbb..5b941a6e8 100644--- a/wger/exercises/models/base.py+++ b/wger/exercises/models/base.py@@ -155,6 +155,7 @@ class ExerciseBase(AbstractLicenseModel, AbstractHistoryMixin, models.Model):happen in our dataset, but it is possible that some local installationshave deleted the English translation or similar"""+ # wgerfrom wger.exercises.models import Exerciselanguage = language or get_language()diff --git a/wger/exercises/models/exercise.py b/wger/exercises/models/exercise.pyindex 491d264aa..0908993ab 100644--- a/wger/exercises/models/exercise.py+++ b/wger/exercises/models/exercise.py@@ -116,8 +116,13 @@ class Exercise(AbstractLicenseModel, AbstractHistoryMixin, models.Model):"""Returns the canonical URL to view an exercise"""- return reverse('exercise:exercise:view-base',- kwargs={'id': self.exercise_base_id, 'slug': slugify(self.name)})+ return reverse(+ 'exercise:exercise:view-base',+ kwargs={+ 'id': self.exercise_base_id,+ 'slug': slugify(self.name)+ }+ )def save(self, *args, **kwargs):"""diff --git a/wger/exercises/models/image.py b/wger/exercises/models/image.pyindex 56343fb1a..5ac52bedb 100644--- a/wger/exercises/models/image.py+++ b/wger/exercises/models/image.py@@ -19,20 +19,15 @@ import pathlibimport uuid# Django-from django.core import mailfrom django.db import modelsfrom django.utils.translation import gettext_lazy as _++# Third Partyfrom simple_history.models import HistoricalRecords# wger-from wger.core.models import Languagefrom wger.exercises.models import ExerciseBase-from wger.utils.cache import delete_template_fragment_cache-from wger.utils.managers import SubmissionManager-from wger.utils.models import (- AbstractLicenseModel,- AbstractSubmissionModel,-)+from wger.utils.models import AbstractLicenseModeldef exercise_image_upload_dir(instance, filename):@@ -144,10 +139,10 @@ class ExerciseImage(AbstractLicenseModel, models.Model):super(ExerciseImage, self).delete(*args, **kwargs)# Make sure there is always a main image- if not ExerciseImage.objects.all().filter(- exercise_base=self.exercise_base, is_main=True- ).count() and ExerciseImage.objects.all().filter(exercise_base=self.exercise_base- ).filter(is_main=False).count():+ if not ExerciseImage.objects.all().filter(exercise_base=self.exercise_base, is_main=True+ ).count() and ExerciseImage.objects.all().filter(+ exercise_base=self.exercise_base+ ).filter(is_main=False).count():image = ExerciseImage.objects.all() \.filter(exercise_base=self.exercise_base, is_main=False)[0]diff --git a/wger/exercises/models/video.py b/wger/exercises/models/video.pyindex b90352649..d6bd97862 100644--- a/wger/exercises/models/video.py+++ b/wger/exercises/models/video.py@@ -22,8 +22,11 @@ import uuidfrom django.core.exceptions import ValidationErrorfrom django.db import modelsfrom django.utils.translation import gettext_lazy as _++# Third Partyfrom simple_history.models import HistoricalRecords+try:# Third Partyimport ffmpegdiff --git a/wger/exercises/tests/test_history.py b/wger/exercises/tests/test_history.pyindex f55f78484..ed8f9e486 100644--- a/wger/exercises/tests/test_history.py+++ b/wger/exercises/tests/test_history.py@@ -11,24 +11,21 @@# GNU General Public License for more details.## You should have received a copy of the GNU Affero General Public License+# Standard Libraryfrom time import sleep-from django.contrib.contenttypes.models import ContentType# Django+from django.contrib.auth.models import User+from django.contrib.contenttypes.models import ContentTypefrom django.urls import reverse# Third Partyfrom actstream import action as actstream_action# wger-from wger.core.tests.base_testcase import (- WgerTestCase,-)-from wger.exercises.models import (- Exercise,-)+from wger.core.tests.base_testcase import WgerTestCase+from wger.exercises.models import Exercisefrom wger.exercises.views.helper import StreamVerbs-from django.contrib.auth.models import Userclass ExerciseHistoryControl(WgerTestCase):@@ -74,9 +71,15 @@ class ExerciseHistoryControl(WgerTestCase):exercise.description = 'Very cool exercise!'exercise.save()- self.client.get(reverse('exercise:history:revert',- kwargs={'history_pk': most_recent_history.history_id,- 'content_type_id': ContentType.objects.get_for_model(exercise).id}))+ self.client.get(+ reverse(+ 'exercise:history:revert',+ kwargs={+ 'history_pk': most_recent_history.history_id,+ 'content_type_id': ContentType.objects.get_for_model(exercise).id+ }+ )+ )exercise = Exercise.objects.get(pk=2)self.assertEqual(exercise.description, 'Boring exercise')diff --git a/wger/exercises/urls.py b/wger/exercises/urls.pyindex 37b150d2c..1e337a64b 100644--- a/wger/exercises/urls.py+++ b/wger/exercises/urls.py@@ -36,14 +36,10 @@ from wger.exercises.views import (# sub patterns for historypatterns_history = [- path(- 'admin-control',- history.control,- name='overview'- ),+ path('admin-control', history.control, name='overview'),path('admin-control/revert/<int:history_pk>/<int:content_type_id>',- history.history_revert,+ history.history_revert,name='revert'),]@@ -72,7 +68,6 @@ patterns_muscle = [),]-# sub patterns for exercise commentspatterns_comment = [path(diff --git a/wger/exercises/views/history.py b/wger/exercises/views/history.pyindex 3fdffebf7..270401e17 100644--- a/wger/exercises/views/history.py+++ b/wger/exercises/views/history.py@@ -19,19 +19,21 @@ import logging# Djangofrom django.contrib.auth.decorators import permission_requiredfrom django.contrib.contenttypes.models import ContentType-from django.shortcuts import render, get_object_or_404from django.http import HttpResponseRedirect-from django.urls import (- reverse,+from django.shortcuts import (+ get_object_or_404,+ render,)+from django.urls import reverse# Third Party-from actstream.models import Actionfrom actstream import action as actstream_action+from actstream.models import Action# wgerfrom wger.exercises.views.helper import StreamVerbs+logger = logging.getLogger(__name__)@@ -59,13 +61,17 @@ def control(request):out.append(data)- return render(request, 'history/overview.html', {- 'context': out,+ return render(+ request,+ 'history/overview.html',+ {+ 'context': out,- # We can't pass the enum to the template, so we have to do this- # https://stackoverflow.com/questions/35953132/- 'verbs': StreamVerbs.__members__- })+ # We can't pass the enum to the template, so we have to do this+ # https://stackoverflow.com/questions/35953132/+ 'verbs': StreamVerbs.__members__+ }+ )@permission_required('exercises.change_exercise')