Self hosted FLOSS fitness/workout, nutrition and weight tracker
Change default author for exercises to get_host()
James Simas74db8c2d54fe
diff --git a/wger/exercises/models.py b/wger/exercises/models.pyindex f7526bf1c..765216024 100644--- a/wger/exercises/models.py+++ b/wger/exercises/models.py@@ -19,6 +19,7 @@ import siximport uuidimport loggingimport bleach+import refrom django.db import modelsfrom django.template.loader import render_to_string@@ -330,8 +331,15 @@ class Exercise(AbstractSubmissionModel, AbstractLicenseModel, models.Model):if request.user.has_perm('exercises.add_exercise'):self.status = self.STATUS_ACCEPTEDif not self.license_author:- self.license_author = 'wger.de'+ # Get everything up to semicolon, exclusive. Example: my-gym.com:9090 returns my-gym.com+ results = re.search('^([^:]+).*', request.get_host())++ if results:+ name = results.group(1)+ else:+ name = request.get_host()+ self.license_author = nameelse:if not self.license_author:self.license_author = request.user.usernamediff --git a/wger/exercises/tests/test_exercise.py b/wger/exercises/tests/test_exercise.pyindex 94c8de54b..896f0f9ed 100644--- a/wger/exercises/tests/test_exercise.py+++ b/wger/exercises/tests/test_exercise.py@@ -290,7 +290,7 @@ class ExercisesTestCase(WorkoutManagerTestCase):# Exercise was savedexercise = Exercise.objects.get(pk=exercise_id)if admin:- self.assertEqual(exercise.license_author, 'wger.de')+ self.assertEqual(exercise.license_author, 'testserver')self.assertEqual(exercise.status, Exercise.STATUS_ACCEPTED)else:self.assertEqual(exercise.license_author, 'test')