Self hosted FLOSS fitness/workout, nutrition and weight tracker
Remove license author history
Tom Bowyer38b880b961ac
diff --git a/wger/core/migrations/0015_licenseauthorhistory.py b/wger/core/migrations/0015_licenseauthorhistory.pydeleted file mode 100644index 75833d590..000000000--- a/wger/core/migrations/0015_licenseauthorhistory.py+++ /dev/null@@ -1,28 +0,0 @@-# Generated by Django 3.2.13 on 2022-05-28 22:47--import django.core.validators-from django.db import migrations, models-import django.utils.timezone---class Migration(migrations.Migration):-- dependencies = [- ('core', '0014_merge_20210818_1735'),- ]-- operations = [- migrations.CreateModel(- name='LicenseAuthorHistory',- fields=[- ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),- ('model_id', models.IntegerField(validators=[django.core.validators.MinValueValidator(1)], verbose_name='Model ID')),- ('model_type', models.CharField(choices=[('1', 'Exercise')], editable=False, max_length=3)),- ('name', models.CharField(max_length=120, verbose_name='Name')),- ('datetime', models.DateTimeField(default=django.utils.timezone.now, verbose_name='Date and Time')),- ],- options={- 'ordering': ['model_id', 'model_type', 'name', 'datetime'],- },- ),- ]diff --git a/wger/core/models/__init__.py b/wger/core/models/__init__.pyindex f7bd76a98..8b71cadd7 100644--- a/wger/core/models/__init__.py+++ b/wger/core/models/__init__.py@@ -19,7 +19,6 @@ from .cache import UserCachefrom .days_of_week import DaysOfWeekfrom .language import Languagefrom .license import License-from .license_author_history import LicenseAuthorHistoryfrom .profile import UserProfilefrom .rep_unit import RepetitionUnitfrom .weight_unit import WeightUnitdiff --git a/wger/core/models/license_author_history.py b/wger/core/models/license_author_history.pydeleted file mode 100644index d13197224..000000000--- a/wger/core/models/license_author_history.py+++ /dev/null@@ -1,87 +0,0 @@-# 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.db.models import IntegerField-from django.utils import timezone-from django.core.validators import (- MinValueValidator,-)-from django.utils.translation import gettext_lazy as _---class LicenseAuthorHistory(models.Model):- """- Tracks model authors- """-- MODEL_TYPE_EXERCISE = '1'-- MODEL_TYPES = (- (MODEL_TYPE_EXERCISE, _('Exercise')),- )-- model_id = IntegerField(- verbose_name=_('Model ID'),- validators=[MinValueValidator(1)]- )- """The model ID"""-- model_type = models.CharField(- max_length=3,- choices=MODEL_TYPES,- editable=False,- )- """The model type"""-- name = models.CharField(- max_length=120,- verbose_name=_('Name'),- )- """Name"""-- datetime = models.DateTimeField(verbose_name=_('Date and Time'), default=timezone.now)- """Date and time entry was created"""-- class Meta:- """- Set Meta options- """- ordering = [- "model_id",- "model_type",- "name",- "datetime",- ]-- #- # Django methods- #- def __str__(self):- """- Return a more human-readable representation- """- return f"Model type: {self.model_type} Name: {self.name} Datetime: ({self.datetime})"-- #- # Own methods- #- def get_owner_object(self):- """- License author history has no owner information- """- return Nonediff --git a/wger/exercises/api/serializers.py b/wger/exercises/api/serializers.pyindex c9e0c9f8d..2b7686a36 100644--- a/wger/exercises/api/serializers.py+++ b/wger/exercises/api/serializers.py@@ -16,7 +16,6 @@# Third Partyfrom rest_framework import serializers-from wger.core.models.license_author_history import LicenseAuthorHistory# wgerfrom wger.exercises.models import (@@ -194,7 +193,6 @@ class ExerciseSerializer(serializers.ModelSerializer):muscles_secondary = serializers.PrimaryKeyRelatedField(many=True, queryset=Muscle.objects.all())equipment = serializers.PrimaryKeyRelatedField(many=True, queryset=Equipment.objects.all())variations = serializers.PrimaryKeyRelatedField(many=True, queryset=Variation.objects.all())- license_author_history = serializers.PrimaryKeyRelatedField(many=True, queryset=LicenseAuthorHistory.objects.all())class Meta:model = Exercise@@ -213,7 +211,6 @@ class ExerciseSerializer(serializers.ModelSerializer):"license","license_author","variations",- "license_author_history",)diff --git a/wger/exercises/management/commands/change-author.py b/wger/exercises/management/commands/change-author.pyindex 96cd1ea4d..73b4ff359 100644--- a/wger/exercises/management/commands/change-author.py+++ b/wger/exercises/management/commands/change-author.py@@ -16,9 +16,9 @@# Djangofrom django.core.management.base import BaseCommand-from wger.core.models.license_author_history import LicenseAuthorHistory# wger+from wger.exercises.models import ExerciseBasefrom wger.exercises.models.exercise import Exercise@@ -29,9 +29,10 @@ class Command(BaseCommand):help = ('Used to alter exercise license authors\n'- 'Must provide at least the exercise id using --exercise-id\n'+ 'Must provide at least the exercise base id using --exercise-base-id\n'+ 'or the exercise id using --exercise-id.\n''Must also provide the new author name using --author-name\n'- )+ )def add_arguments(self, parser):parser.add_argument(@@ -40,6 +41,12 @@ class Command(BaseCommand):dest='author_name',help='The name of the new author')+ parser.add_argument(+ '--exercise-base-id',+ action='store',+ dest='exercise_base_id',+ help='The ID of the exercise'+ )parser.add_argument('--exercise-id',action='store',@@ -49,31 +56,37 @@ class Command(BaseCommand):def handle(self, **options):author_name = options['author_name']+ exercise_base_id = options['exercise_base_id']exercise_id = options['exercise_id']if author_name is None:self.print_error('Please enter an author name')return- if exercise_id is None:- self.print_error('Please enter an exercise ID')+ if exercise_base_id is None and exercise_id is None:+ self.print_error('Please enter an exercise base or exercise ID')return- try:- exercise = Exercise.objects.get(id=exercise_id)- except Exercise.DoesNotExist:- self.print_error('Failed to find exercise')- return+ if exercise_base_id is not None:+ try:+ exercise_base = ExerciseBase.objects.get(id=exercise_base_id)+ except ExerciseBase.DoesNotExist:+ self.print_error('Failed to find exercise base')+ return+ exercise_base.license_author = author_name+ exercise_base.save()- lh = LicenseAuthorHistory(- model_id=exercise.id,- model_type=LicenseAuthorHistory.MODEL_TYPE_EXERCISE,- name=author_name,- )- lh.save()+ if exercise_id is not None:+ try:+ exercise = Exercise.objects.get(id=exercise_id)+ except ExerciseBase.DoesNotExist:+ self.print_error('Failed to find exercise')+ return+ exercise.license_author = author_name+ exercise.save()self.stdout.write(- self.style.SUCCESS(f"Exercise has been updated")+ self.style.SUCCESS(f"Exercise and/or exercise base has been updated"))def print_error(self, error_message):diff --git a/wger/exercises/models/exercise.py b/wger/exercises/models/exercise.pyindex 9d51f7433..43119261b 100644--- a/wger/exercises/models/exercise.py+++ b/wger/exercises/models/exercise.py@@ -37,7 +37,6 @@ from simple_history.models import HistoricalRecords# wgerfrom wger.core.models import Language-from wger.core.models.license_author_history import LicenseAuthorHistoryfrom wger.exercises.models import ExerciseBasefrom wger.utils.cache import (delete_template_fragment_cache,@@ -194,16 +193,6 @@ class Exercise(AbstractLicenseModel, models.Model):out.append(exercise)return out- #- # Properties to expose the information about license history- #- @property- def license_author_history(self):- return LicenseAuthorHistory.objects.all().filter(- model_id=self.id,- model_type=LicenseAuthorHistory.MODEL_TYPE_EXERCISE,- )-## Own methods#diff --git a/wger/exercises/tests/test_change_author.py b/wger/exercises/tests/test_change_author.pyindex b1212d4c3..1f8720bad 100644--- a/wger/exercises/tests/test_change_author.py+++ b/wger/exercises/tests/test_change_author.py@@ -15,10 +15,10 @@from io import StringIOfrom django.core.management import call_command-from wger.core.models.license_author_history import LicenseAuthorHistory# wgerfrom wger.core.tests.base_testcase import WgerTestCase+from wger.exercises.models.base import ExerciseBasefrom wger.exercises.models.exercise import Exercise@@ -31,7 +31,6 @@ class ChangeAuthorTestCase(WgerTestCase):super(ChangeAuthorTestCase, self).setUp()self.out = StringIO()-def test_missing_author(self):"""Test to ensure command handles a missing author parameter@@ -48,12 +47,36 @@ class ChangeAuthorTestCase(WgerTestCase):"tom"]call_command('change-author', *args, stdout=self.out, no_color=True)- self.assertIn('Please enter an exercise ID', self.out.getvalue())+ self.assertIn(+ 'Please enter an exercise base or exercise ID', self.out.getvalue())++ def test_can_update_exercise_base(self):+ """+ Test to ensure command can handle an exercise base id passed+ """+ exercise_base = ExerciseBase.objects.get(id=2)+ self.assertNotEquals(exercise_base.license_author, "tom")++ args = [+ "--author-name",+ "tom",+ "--exercise-base-id",+ "2"+ ]+ call_command('change-author', *args, stdout=self.out, no_color=True)+ self.assertIn(+ 'Exercise and/or exercise base has been updated', self.out.getvalue())++ exercise_base = ExerciseBase.objects.get(id=2)+ self.assertEquals(exercise_base.license_author, "tom")def test_can_update_exercise(self):"""Test to ensure command can handle an exercise id passed"""+ exercise = Exercise.objects.get(id=1)+ self.assertNotEquals(exercise.license_author, "tom")+args = ["--author-name","tom",@@ -61,9 +84,8 @@ class ChangeAuthorTestCase(WgerTestCase):"1"]call_command('change-author', *args, stdout=self.out, no_color=True)- self.assertIn('Exercise has been updated', self.out.getvalue())+ self.assertIn(+ 'Exercise and/or exercise base has been updated', self.out.getvalue())- exercise = LicenseAuthorHistory.objects.filter(- model_type=LicenseAuthorHistory.MODEL_TYPE_EXERCISE- )- self.assertEquals(len(exercise), 1)+ exercise = Exercise.objects.get(id=1)+ self.assertEquals(exercise.license_author, "tom")