Self hosted FLOSS fitness/workout, nutrition and weight tracker
Also delete duplicate/obsolete exercises and translations
Roland Geider3dd21ef99a6e
diff --git a/wger/exercises/management/commands/exercise-cleanup.py b/wger/exercises/management/commands/exercise-cleanup.pyindex 6ece68e10..7f4ab6106 100755--- a/wger/exercises/management/commands/exercise-cleanup.py+++ b/wger/exercises/management/commands/exercise-cleanup.py@@ -73,7 +73,6 @@ class Command(BaseCommand):data[language.short_name] = exercise_dataout.append(data)- # pprint.pprint(out)with open('exercise_cleanup.csv', 'w', newline='') as csvfile:file_writer = csv.writer(csvfile, )diff --git a/wger/exercises/management/commands/exercises-health-check.py b/wger/exercises/management/commands/exercises-health-check.pyindex c7153f6ae..e56f6efe6 100644--- a/wger/exercises/management/commands/exercises-health-check.py+++ b/wger/exercises/management/commands/exercises-health-check.py@@ -1,5 +1,3 @@-# -*- coding: utf-8 *-*-# This file is part of wger Workout Manager.## wger Workout Manager is free software: you can redistribute it and/or modifydiff --git a/wger/exercises/management/commands/read-exercise-cleanup.py b/wger/exercises/management/commands/read-exercise-cleanup.pyindex 82a867a03..b234c9351 100644--- a/wger/exercises/management/commands/read-exercise-cleanup.py+++ b/wger/exercises/management/commands/read-exercise-cleanup.py@@ -76,7 +76,11 @@ class Command(BaseCommand):)def handle(self, **options):- csv_file = open('exercise_cleanup.csv', 'r', newline='')+ self.process_new_exercises(options)+ self.delete_duplicates(options)++ def process_new_exercises(self, options):+ csv_file = open('exercises_cleanup.csv', 'r', newline='')file_reader = csv.DictReader(csv_file)#@@ -102,8 +106,7 @@ class Command(BaseCommand):## Process the exercises#- rows = [f for f in file_reader]- for row in rows:+ for row in file_reader:new_exercise = Falsebase_uuid = row['base:uuid']base_equipment = row['base:equipment']@@ -241,3 +244,30 @@ class Command(BaseCommand):Alias(exercise=exercise, alias=a.strip()).save()csv_file.close()++ def delete_duplicates(self, options):+ csv_file = open('exercises_cleanup_duplicates.csv', 'r', newline='')+ file_reader = csv.DictReader(csv_file)+ self.stdout.write(+ self.style.+ WARNING(f'---> Deleting duplicate bases and translations now...')+ )++ for row in file_reader:+ base_uuid = row['baseUUID:toDelete']+ translation_uuid = row['exerciseUUID:toDelete']++ if base_uuid:+ try:+ ExerciseBase.objects.filter(uuid=base_uuid).delete()+ self.stdout.write(f'* Deleted base {base_uuid}')+ except ExerciseBase.DoesNotExist:+ pass++ if translation_uuid:+ try:+ Exercise.objects.filter(uuid=translation_uuid).delete()+ self.stdout.write(f'* Deleted translation {base_uuid}')+ except Exercise.DoesNotExist:+ pass+ csv_file.close()