Self hosted FLOSS fitness/workout, nutrition and weight tracker
Fixing style
Harlene Samraa81881833a2b
diff --git a/wger/exercises/api/serializers.py b/wger/exercises/api/serializers.pyindex 1d43c7303..4792270d2 100644--- a/wger/exercises/api/serializers.py+++ b/wger/exercises/api/serializers.py@@ -14,10 +14,8 @@## You should have received a copy of the GNU Affero General Public License-# Third Party-from rest_framework import serializers-# wger+from rest_framework import serializersfrom wger.exercises.models import (Equipment,Exercise,@@ -28,6 +26,7 @@ from wger.exercises.models import (Muscle)+class ExerciseBaseSerializer(serializers.ModelSerializer):"""Exercise serializer@@ -36,6 +35,7 @@ class ExerciseBaseSerializer(serializers.ModelSerializer):model = ExerciseBasefields = '__all__'+class ExerciseSerializer(serializers.ModelSerializer):"""Exercise serializerdiff --git a/wger/exercises/api/views.py b/wger/exercises/api/views.pyindex bb0b664bb..a342441da 100644--- a/wger/exercises/api/views.py+++ b/wger/exercises/api/views.py@@ -18,7 +18,7 @@# Djangofrom django.utils.translation import ugettext as _-# Third Party+# wgerfrom easy_thumbnails.alias import aliasesfrom easy_thumbnails.files import get_thumbnailerfrom rest_framework import viewsets@@ -28,8 +28,6 @@ from rest_framework.decorators import ()from rest_framework.permissions import IsAuthenticatedOrReadOnlyfrom rest_framework.response import Response--# wgerfrom wger.config.models import LanguageConfigfrom wger.exercises.api.serializers import (EquipmentSerializer,@@ -70,6 +68,7 @@ class ExerciseBaseViewSet(viewsets.ModelViewSet):'muscles_secondary','equipment')+class ExerciseViewSet(viewsets.ModelViewSet):"""API endpoint for exercise objects. For a read-only endpoint with alldiff --git a/wger/exercises/migrations/0008_exercisebase.py b/wger/exercises/migrations/0008_exercisebase.pyindex e2d79f641..6814ebe68 100644--- a/wger/exercises/migrations/0008_exercisebase.py+++ b/wger/exercises/migrations/0008_exercisebase.py@@ -15,14 +15,32 @@ class Migration(migrations.Migration):migrations.CreateModel(name='ExerciseBase',fields=[- ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, 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')),- ('status', models.CharField(choices=[('1', 'Pending'), ('2', 'Accepted'), ('3', 'Declined')], default='1', editable=False, max_length=2)),- ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='exercises.exercisecategory', verbose_name='Category')),- ('equipment', models.ManyToManyField(blank=True, to='exercises.Equipment', verbose_name='Equipment')),- ('license', models.ForeignKey(default=2, on_delete=django.db.models.deletion.CASCADE, to='core.license', verbose_name='License')),- ('muscles', models.ManyToManyField(blank=True, to='exercises.Muscle', verbose_name='Primary muscles')),- ('muscles_secondary', models.ManyToManyField(blank=True, related_name='secondary_muscles_base', to='exercises.Muscle', verbose_name='Secondary muscles')),+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False,+ 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')),+ ('status', models.CharField(choices=[('1', 'Pending'), ('2', 'Accepted'),+ ('3', 'Declined')],+ default='1', editable=False, max_length=2)),+ ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE,+ to='exercises.exercisecategory',+ verbose_name='Category')),+ ('equipment', models.ManyToManyField(blank=True, to='exercises.Equipment',+ verbose_name='Equipment')),+ ('license', models.ForeignKey(default=2,+ on_delete=django.db.models.deletion.CASCADE,+ to='core.license', verbose_name='License')),+ ('muscles', models.ManyToManyField(blank=True, to='exercises.Muscle',+ verbose_name='Primary muscles')),+ ('muscles_secondary', models.ManyToManyField(blank=True,+ related_name='secondary_muscles_base',+ to='exercises.Muscle',+ verbose_name='Secondary muscles')),],options={'abstract': False,@@ -31,6 +49,9 @@ class Migration(migrations.Migration):migrations.AddField(model_name='exercise',name='exercise_base',- field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='exercises', to='exercises.exercisebase', verbose_name='ExerciseBase'),+ field=models.ForeignKey(default=None, null=True,+ on_delete=django.db.models.deletion.CASCADE,+ related_name='exercises', to='exercises.exercisebase',+ verbose_name='ExerciseBase'),),- ]\ No newline at end of file+ ]diff --git a/wger/exercises/migrations/0009_auto_20201211_0139.py b/wger/exercises/migrations/0009_auto_20201211_0139.pyindex 89ddc6ab2..0b4d00908 100644--- a/wger/exercises/migrations/0009_auto_20201211_0139.py+++ b/wger/exercises/migrations/0009_auto_20201211_0139.py@@ -9,7 +9,7 @@ def copy_columns(apps, schema_editor):for exercise in Exercise.objects.all():exercise_base = ExerciseBase.objects.create(- category = exercise.category,+ category=exercise.category,)exercise_base.equipment.set(exercise.equipment.all())exercise_base.muscles.set(exercise.muscles.all())@@ -27,4 +27,4 @@ class Migration(migrations.Migration):operations = [migrations.RunPython(copy_columns),- ]\ No newline at end of file+ ]diff --git a/wger/exercises/migrations/0010_auto_20201211_0205.py b/wger/exercises/migrations/0010_auto_20201211_0205.pyindex 7eab0ec57..54efa53c4 100644--- a/wger/exercises/migrations/0010_auto_20201211_0205.py+++ b/wger/exercises/migrations/0010_auto_20201211_0205.py@@ -26,4 +26,4 @@ class Migration(migrations.Migration):model_name='exercise',name='category',),- ]\ No newline at end of file+ ]diff --git a/wger/exercises/migrations/0011_auto_20201214_0033.py b/wger/exercises/migrations/0011_auto_20201214_0033.pyindex d3053fc15..17ddd327b 100644--- a/wger/exercises/migrations/0011_auto_20201214_0033.py+++ b/wger/exercises/migrations/0011_auto_20201214_0033.py@@ -370,6 +370,7 @@ exercise_mapping = [{'en': 'bdb7bdbb-8930-46e5-8b98-eb13e604553f', 'de': '032a38cf-b15a-4761-b684-577e41893f54'},]+def create_exercise_mapping(apps, schema_editor):Exercise = apps.get_model('exercises', 'Exercise')ExerciseBase = apps.get_model('exercises', 'ExerciseBase')@@ -379,7 +380,7 @@ def create_exercise_mapping(apps, schema_editor):for lang in langs:try:exercise_objects.append(Exercise.objects.get(uuid=exercise_group[lang]))- except:+ except Exercise.DoesNotExist:print(exercise_group[lang], "does not exist")if(len(exercise_objects) > 0):@@ -389,12 +390,14 @@ def create_exercise_mapping(apps, schema_editor):exercise.exercise_base = exercise_base_mainexercise.save()+def remove_mappings(apps, schema_editor):"""- Backwards migration. Removes all variation data.+ Backwards migration."""pass+class Migration(migrations.Migration):dependencies = [diff --git a/wger/exercises/models.py b/wger/exercises/models.pyindex f79a94a7a..efafcbe3b 100644--- a/wger/exercises/models.py+++ b/wger/exercises/models.py@@ -170,6 +170,7 @@ class Variation(models.Model):"""return False+class ExerciseBase(AbstractSubmissionModel, AbstractLicenseModel, models.Model):"""Model for an exercise base@@ -181,24 +182,24 @@ class ExerciseBase(AbstractSubmissionModel, AbstractLicenseModel, models.Model):category = models.ForeignKey(ExerciseCategory,verbose_name=_('Category'),on_delete=models.CASCADE)-+muscles = models.ManyToManyField(Muscle,blank=True,verbose_name=_('Primary muscles'))- """Main muscles trained by the exercise"""+ """Main muscles trained by the exercise"""muscles_secondary = models.ManyToManyField(Muscle,verbose_name=_('Secondary muscles'),related_name='secondary_muscles_base',blank=True)- """Secondary muscles trained by the exercise"""-+ """Secondary muscles trained by the exercise"""equipment = models.ManyToManyField(Equipment,verbose_name=_('Equipment'),blank=True)"""Equipment needed by this exercise"""+class Exercise(AbstractSubmissionModel, AbstractLicenseModel, models.Model):"""Model for an exercise@@ -249,11 +250,11 @@ class Exercise(AbstractSubmissionModel, AbstractLicenseModel, models.Model):"""Variations of this exercise"""exercise_base = models.ForeignKey(ExerciseBase,- verbose_name=('ExerciseBase'),- on_delete=models.CASCADE,- default=None,- null=True,- related_name='exercises')+ verbose_name=('ExerciseBase'),+ on_delete=models.CASCADE,+ default=None,+ null=True,+ related_name='exercises')""" Refers to the base exercise with non translated information """#diff --git a/wger/exercises/views/exercises.py b/wger/exercises/views/exercises.pyindex 7eb3eb58c..958f46faa 100644--- a/wger/exercises/views/exercises.py+++ b/wger/exercises/views/exercises.py@@ -60,20 +60,18 @@ from django.views.generic import (UpdateView)-# Third Party+# wgerfrom crispy_forms.layout import (Column,Layout,Row)--# wgerfrom wger.config.models import LanguageConfigfrom wger.exercises.models import (+ Equipment,Exercise,ExerciseBase,ExerciseCategory,- Equipment,Muscle)from wger.manager.models import WorkoutLog@@ -135,13 +133,14 @@ def view(request, id, slug=None):template_data['show_shariff'] = Trueexercise = get_object_or_404(Exercise, pk=id)+ exercise_base = exercise.exercise_basetemplate_data['exercise'] = exercise- template_data["muscles_main_front"] = exercise.exercise_base.muscles.filter(is_front=True)- template_data["muscles_main_back"] = exercise.exercise_base.muscles.filter(is_front=False)- template_data["muscles_sec_front"] = exercise.exercise_base.muscles_secondary.filter(is_front=True)- template_data["muscles_sec_back"] = exercise.exercise_base.muscles_secondary.filter(is_front=False)+ template_data["muscles_main_front"] = exercise_base.muscles.filter(is_front=True)+ template_data["muscles_main_back"] = exercise_base.muscles.filter(is_front=False)+ template_data["muscles_sec_front"] = exercise_base.muscles_secondary.filter(is_front=True)+ template_data["muscles_sec_back"] = exercise_base.muscles_secondary.filter(is_front=False)# If the user is logged in, load the log and prepare the entries for# rendering in the D3 chart@@ -198,7 +197,6 @@ class ExercisesEditAddView(WgerFormMixin):model = Exercisewidgets = {'equipment': TranslatedSelectMultiple()}fields = ['name_original',- # 'exercise_base','category','description','muscles',@@ -238,14 +236,15 @@ class ExercisesEditAddView(WgerFormMixin):return formdef form_valid(self, form):- exercise_base = Exercise.objects.get(name = form.instance.name).exercise_base+ exercise_base = Exercise.objects.get(name=form.instance.name).exercise_baseexercise_base.equipment.set(form.cleaned_data['equipment'].all())exercise_base.muscles.set(form.cleaned_data['muscles'].all())exercise_base.muscles_secondary.set(form.cleaned_data['muscles_secondary'].all())form.instance.exercise_base = exercise_baseform.instance.save()- return super(ExercisesEditAddView, self).form_valid(form)+ return super(ExercisesEditAddView, self).form_valid(form)+class ExerciseUpdateView(ExercisesEditAddView,LoginRequiredMixin,@@ -261,6 +260,7 @@ class ExerciseUpdateView(ExercisesEditAddView,context['title'] = _('Edit {0}').format(self.object.name)return context+class ExerciseAddView(ExercisesEditAddView, LoginRequiredMixin, CreateView):"""Generic view to add a new exercise@@ -272,8 +272,10 @@ class ExerciseAddView(ExercisesEditAddView, LoginRequiredMixin, CreateView):"""form.instance.language = load_language()form.instance.set_author(self.request)- exercise_base = ExerciseBase.objects.create(category = ExerciseCategory.objects.get(name=form.cleaned_data['category']))-+ exercise_base = ExerciseBase.objects.create(+ category=ExerciseCategory.objects.get(name=form.cleaned_data['category'])+ )+exercise_base.equipment.set(form.cleaned_data['equipment'].all())exercise_base.muscles.set(form.cleaned_data['muscles'].all())exercise_base.muscles_secondary.set(form.cleaned_data['muscles_secondary'].all())diff --git a/wger/nutrition/api/serializers.py b/wger/nutrition/api/serializers.pyindex 261434b27..f7aa35a3e 100644--- a/wger/nutrition/api/serializers.py+++ b/wger/nutrition/api/serializers.py@@ -15,10 +15,8 @@# You should have received a copy of the GNU Affero General Public License# along with Workout Manager. If not, see <http://www.gnu.org/licenses/>.-# Third Party-from rest_framework import serializers-# wger+from rest_framework import serializersfrom wger.nutrition.models import (Ingredient,IngredientWeightUnit,diff --git a/wger/nutrition/api/views.py b/wger/nutrition/api/views.pyindex 8089d4dcd..0ad463eca 100644--- a/wger/nutrition/api/views.py+++ b/wger/nutrition/api/views.py@@ -21,15 +21,13 @@ import datetime# Djangofrom django.shortcuts import get_object_or_404-# Third Party+# wgerfrom rest_framework import viewsetsfrom rest_framework.decorators import (action,api_view)from rest_framework.response import Response--# wgerfrom wger.nutrition.api.serializers import (IngredientInfoSerializer,IngredientSerializer,diff --git a/wger/nutrition/forms.py b/wger/nutrition/forms.pyindex a2ab136c3..eb7e89a3a 100644--- a/wger/nutrition/forms.py+++ b/wger/nutrition/forms.py@@ -25,7 +25,7 @@ from django.utils.translation import (ugettext_lazy)-# Third Party+# wgerfrom crispy_forms.helper import FormHelperfrom crispy_forms.layout import (HTML,@@ -35,8 +35,6 @@ from crispy_forms.layout import (Row,Submit)--# wgerfrom wger.core.models import UserProfilefrom wger.nutrition.models import (Ingredient,@@ -260,21 +258,22 @@ class MealLogItemForm(MealItemForm):'weight_unit','amount']+class IngredientForm(forms.ModelForm):class Meta:model = Ingredientfields = ['name',- 'energy',- 'protein',- 'carbohydrates',- 'carbohydrates_sugar',- 'fat',- 'fat_saturated',- 'fibres',- 'sodium',- 'license',- 'license_author']-+ 'energy',+ 'protein',+ 'carbohydrates',+ 'carbohydrates_sugar',+ 'fat',+ 'fat_saturated',+ 'fibres',+ 'sodium',+ 'license',+ 'license_author']+def __init__(self, *args, **kwargs):super(IngredientForm, self).__init__(*args, **kwargs)self.helper = FormHelper()@@ -296,4 +295,4 @@ class IngredientForm(forms.ModelForm):'sodium','license','license_author'- )\ No newline at end of file+ )diff --git a/wger/nutrition/views/ingredient.py b/wger/nutrition/views/ingredient.pyindex 07526c138..bf055328d 100644--- a/wger/nutrition/views/ingredient.py+++ b/wger/nutrition/views/ingredient.py@@ -46,9 +46,9 @@ from django.views.generic import ()# wger-from wger.nutrition.forms import (- UnitChooserForm,+from wger.nutrition.forms import (IngredientForm,+ UnitChooserForm)from wger.nutrition.models import Ingredientfrom wger.utils.cache import cache_mapper@@ -187,7 +187,7 @@ class IngredientCreateView(WgerFormMixin, CreateView):if request.user.userprofile.is_temporary:return HttpResponseForbidden()return super(IngredientCreateView, self).dispatch(request, *args, **kwargs)-+def get_context_data(self, **kwargs):context = super(IngredientCreateView, self).get_context_data(**kwargs)context['extend_template'] = 'base.html'