Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Cleanup

Roland Geider0dc3ec105e6f
diff --git a/wger/exercises/api/serializers.py b/wger/exercises/api/serializers.py
index b7740b7c2..bf00d247e 100644
--- a/wger/exercises/api/serializers.py
+++ b/wger/exercises/api/serializers.py
@@ -694,15 +694,17 @@ class ExerciseSubmissionSerializer(serializers.ModelSerializer):
serializer: ExerciseTranslationSubmissionSerializer = self.fields['translations'].child
serializer.create(validated_data=translation, exercise=exercise)
- # If requested, create a new variation group for both exercises
+ # If requested, add the exercise to an existing or new variation group
connect_to: Exercise | None = validated_data.get('variations_connect_to')
if connect_to:
- new_group = uuid.uuid4()
+ # Reuse the target's existing group, or create a new one
+ group = connect_to.variation_group or uuid.uuid4()
- connect_to.variation_group = new_group
- connect_to.save()
+ if not connect_to.variation_group:
+ connect_to.variation_group = group
+ connect_to.save()
- exercise.variation_group = new_group
+ exercise.variation_group = group
exercise.save()
return exercise
diff --git a/wger/exercises/management/commands/exercises-health-check.py b/wger/exercises/management/commands/exercises-health-check.py
index ca3438f73..167f540a5 100644
--- a/wger/exercises/management/commands/exercises-health-check.py
+++ b/wger/exercises/management/commands/exercises-health-check.py
@@ -39,7 +39,7 @@ class Command(BaseCommand):
'- has at least one translation\n'
'- has a translation in English\n'
'- has no duplicate translations\n\n'
- 'It also checks for orphaned variation groups (0 or 1 exercises).\n\n'
+ 'It also checks for orphaned variation groups (only 1 exercise).\n\n'
'Each problem can be fixed individually by using the --delete-* flags\n'
)
@@ -71,7 +71,7 @@ class Command(BaseCommand):
action='store_true',
dest='delete_orphan_variations',
default=False,
- help='Delete variation groups with 0 or 1 exercises',
+ help='Clear variation_group for exercises that are alone in their group',
)
parser.add_argument(
diff --git a/wger/exercises/models/translation.py b/wger/exercises/models/translation.py
index 462f0a6e9..78d7ffda5 100644
--- a/wger/exercises/models/translation.py
+++ b/wger/exercises/models/translation.py
@@ -104,7 +104,6 @@ class Translation(AbstractLicenseModel, AbstractHistoryMixin, models.Model):
'name',
]
indexes = (GinIndex(fields=['name'], name='exercises_e_name_ac11f4_gin'),)
- # indexes = (GinIndex(fields=['name']),)
constraints = [
models.UniqueConstraint(
fields=['exercise', 'language'],