Skip to content

armgit / wger

Public Imported from GitHub
0

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.py
index f7526bf1c..765216024 100644
--- a/wger/exercises/models.py
+++ b/wger/exercises/models.py
@@ -19,6 +19,7 @@ import six
import uuid
import logging
import bleach
+import re
from django.db import models
from 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_ACCEPTED
if 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 = name
else:
if not self.license_author:
self.license_author = request.user.username
diff --git a/wger/exercises/tests/test_exercise.py b/wger/exercises/tests/test_exercise.py
index 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 saved
exercise = 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')