Self hosted FLOSS fitness/workout, nutrition and weight tracker
Make the timer in the gym view configurable
Roland Geider35db9eecf4ce
diff --git a/wger/manager/forms.py b/wger/manager/forms.pyindex 2cb4a9984..a404e178b 100644--- a/wger/manager/forms.py+++ b/wger/manager/forms.py@@ -55,7 +55,9 @@ class UserPreferencesForm(ModelForm):'workout_reminder_active','workout_reminder','workout_duration',- 'notification_language')+ 'notification_language',+ 'timer_active',+ 'timer_pause')class UserEmailForm(ModelForm):diff --git a/wger/manager/models.py b/wger/manager/models.pyindex 2fb45c08d..981a24b8d 100644--- a/wger/manager/models.py+++ b/wger/manager/models.py@@ -731,6 +731,23 @@ by the US Department of Agriculture. It is extremely complete, with around'language used on the website.'),default=2)+ timer_active = models.BooleanField(verbose_name=_('Use pauses in workout timer'),+ help_text=_('Check to activate timer pauses between '+ 'exercises.'),+ default=True)+ '''+ Switch to activate pauses in the gym view+ '''++ timer_pause = Html5IntegerField(verbose_name=_('Default duration of workout pauses'),+ help_text=_('Default duration in seconds of pauses used by '+ 'the timer in the gym mode.'),+ default=90,+ validators=[MinValueValidator(10), MaxValueValidator(400)])+ '''+ Default duration of workout pauses in the gym view+ '''+## User statistics#diff --git a/wger/manager/templates/mobile/index.html b/wger/manager/templates/mobile/index.htmlindex a52f359e3..280cad6ce 100644--- a/wger/manager/templates/mobile/index.html+++ b/wger/manager/templates/mobile/index.html@@ -98,13 +98,18 @@data-overlay-theme="a"><div data-role="header"><h4>{% trans "Start gym mode" %}</h4>- </div>+ </div><div role="main" class="ui-content">- <div style="margin-bottom: 1.5em;">{% blocktrans %}Use the gym mode to+ <p>{% blocktrans %}Use the gym mode tostart an interactive training session. If you enter lifted weights, they willbe added to your workout log. A timer between sets helps you keep track of the-pauses you do.{% endblocktrans %}</div>+pauses you do.{% endblocktrans %}</p>+ <p>+ <strong>{% trans "Tip:" %}</strong>+ {% blocktrans %}You can deactivate the timer or set+its default duration in your settings.{% endblocktrans %}+ </p><ul data-role="listview" data-inset="true" style="margin-bottom:1em;">{% if current_workout %}diff --git a/wger/manager/tests/test_timer.py b/wger/manager/tests/test_timer.pyindex d5b37c23b..1dc49c384 100644--- a/wger/manager/tests/test_timer.py+++ b/wger/manager/tests/test_timer.py@@ -14,6 +14,7 @@import loggingimport math+from django.contrib.auth.models import Userfrom django.core.urlresolvers import reversefrom wger.exercises.models import Exercise@@ -28,7 +29,7 @@ class WorkoutTimerTestCase(WorkoutManagerTestCase):Tests the timer view (gym mode) for a workout day'''- def timer(self, fail=True):+ def timer(self, fail=True, pause_active=True, pause_seconds=90):'''Helper function'''@@ -43,37 +44,51 @@ class WorkoutTimerTestCase(WorkoutManagerTestCase):# Check some of the stepsstep_list = response.context['step_list']-- self.assertEqual(step_list[0]['exercise'], Exercise.objects.get(pk=2))- self.assertEqual(step_list[0]['reps'], 10)- self.assertEqual(step_list[0]['step_nr'], 1)- self.assertEqual(math.floor(step_list[0]['step_percent']), 14)- self.assertEqual(step_list[0]['type'], 'exercise')- self.assertEqual(step_list[0]['weight'], '')-- self.assertEqual(step_list[1]['step_nr'], 2)- self.assertEqual(math.floor(step_list[1]['step_percent']), 28)- self.assertEqual(step_list[1]['time'], 90)- self.assertEqual(step_list[1]['type'], 'pause')-- self.assertEqual(step_list[2]['exercise'], Exercise.objects.get(pk=2))- self.assertEqual(step_list[2]['reps'], 10)- self.assertEqual(step_list[2]['step_nr'], 3)- self.assertEqual(math.floor(step_list[2]['step_percent']), 42)- self.assertEqual(step_list[2]['type'], 'exercise')- self.assertEqual(step_list[2]['weight'], '')-- self.assertEqual(step_list[3]['step_nr'], 4)- self.assertEqual(math.floor(step_list[3]['step_percent']), 57)- self.assertEqual(step_list[3]['time'], 90)- self.assertEqual(step_list[3]['type'], 'pause')-- self.assertEqual(step_list[4]['exercise'], Exercise.objects.get(pk=2))- self.assertEqual(step_list[4]['reps'], 10)- self.assertEqual(step_list[4]['step_nr'], 5)- self.assertEqual(math.floor(step_list[4]['step_percent']), 71)- self.assertEqual(step_list[4]['type'], 'exercise')- self.assertEqual(step_list[4]['weight'], '')+ step_list.reverse()+ list_length = len(step_list)++ current_step = step_list.pop()+ self.assertEqual(current_step['exercise'], Exercise.objects.get(pk=2))+ self.assertEqual(current_step['reps'], 10)+ self.assertEqual(current_step['step_nr'], list_length - len(step_list))+ self.assertEqual(math.floor(current_step['step_percent']),+ math.floor(current_step['step_nr'] * (100.0 / list_length)))+ self.assertEqual(current_step['type'], 'exercise')+ self.assertEqual(current_step['weight'], '')++ if pause_active:+ current_step = step_list.pop()+ self.assertEqual(current_step['step_nr'], list_length - len(step_list))+ self.assertEqual(math.floor(current_step['step_percent']),+ math.floor(current_step['step_nr'] * (100.0 / list_length)))+ self.assertEqual(current_step['time'], pause_seconds)+ self.assertEqual(current_step['type'], 'pause')++ current_step = step_list.pop()+ self.assertEqual(current_step['exercise'], Exercise.objects.get(pk=2))+ self.assertEqual(current_step['reps'], 10)+ self.assertEqual(current_step['step_nr'], list_length - len(step_list))+ self.assertEqual(math.floor(current_step['step_percent']),+ math.floor(current_step['step_nr'] * (100.0 / list_length)))+ self.assertEqual(current_step['type'], 'exercise')+ self.assertEqual(current_step['weight'], '')++ if pause_active:+ current_step = step_list.pop()+ self.assertEqual(current_step['step_nr'], list_length - len(step_list))+ self.assertEqual(math.floor(current_step['step_percent']),+ math.floor(current_step['step_nr'] * (100.0 / list_length)))+ self.assertEqual(current_step['time'], pause_seconds)+ self.assertEqual(current_step['type'], 'pause')++ current_step = step_list.pop()+ self.assertEqual(current_step['exercise'], Exercise.objects.get(pk=2))+ self.assertEqual(current_step['reps'], 10)+ self.assertEqual(current_step['step_nr'], list_length - len(step_list))+ self.assertEqual(math.floor(current_step['step_percent']),+ math.floor(current_step['step_nr'] * (100.0 / list_length)))+ self.assertEqual(current_step['type'], 'exercise')+ self.assertEqual(current_step['weight'], '')def test_timer_anonymous(self):'''@@ -86,14 +101,33 @@ class WorkoutTimerTestCase(WorkoutManagerTestCase):'''Tests the timer as the owner user'''+ self.user_login('admin')+ self.timer(fail=False)- self.user_login('test')- self.timer(fail=True)+ def test_timer_owner_custom_pause(self):+ '''+ Tests the timer as the owner, use custom time+ '''+ self.user_login('admin')+ user = User.objects.get(username='admin')+ user.userprofile.timer_pause = 120+ user.userprofile.save()+ self.timer(fail=False, pause_seconds=120)++ def test_timer_owner_no_pause(self):+ '''+ Tests the timer as the owner, deactivate timer+ '''+ self.user_login('admin')+ user = User.objects.get(username='admin')+ user.userprofile.timer_active = False+ user.userprofile.save()+ self.timer(fail=False, pause_active=False)def test_timer_other(self):'''Tests the timer as a logged user not owning the data'''- self.user_login('admin')- self.timer(fail=False)+ self.user_login('test')+ self.timer(fail=True)diff --git a/wger/manager/views/workout.py b/wger/manager/views/workout.pyindex e7e3c3e68..589a2216c 100644--- a/wger/manager/views/workout.py+++ b/wger/manager/views/workout.py@@ -271,12 +271,12 @@ def timer(request, day_pk):'type': 'exercise','reps': reps,'weight': last_log.get_last_weight(exercise, reps)})-- step_list.append({'current_step': uuid.uuid4().hex,- 'step_percent': 0,- 'step_nr': len(step_list) + 1,- 'type': 'pause',- 'time': 90})+ if request.user.userprofile.timer_active:+ step_list.append({'current_step': uuid.uuid4().hex,+ 'step_percent': 0,+ 'step_nr': len(step_list) + 1,+ 'type': 'pause',+ 'time': request.user.userprofile.timer_pause})# Supersets need extra work to group the exercises and reps togetherelse:@@ -294,11 +294,12 @@ def timer(request, day_pk):'reps': reps,'weight': last_log.get_last_weight(exercise, reps)})- step_list.append({'current_step': uuid.uuid4().hex,- 'step_percent': 0,- 'step_nr': len(step_list) + 1,- 'type': 'pause',- 'time': 90})+ if request.user.userprofile.timer_active:+ step_list.append({'current_step': uuid.uuid4().hex,+ 'step_percent': 0,+ 'step_nr': len(step_list) + 1,+ 'type': 'pause',+ 'time': 90})# Remove the last pause step as it is not needed. If the list is empty,# because the user didn't add any repetitions to any exercise, do nothing