Self hosted FLOSS fitness/workout, nutrition and weight tracker
Move helper function to own file
Roland Geider96ca6a9ed391
diff --git a/wger/manager/helpers.py b/wger/manager/helpers.pynew file mode 100644index 000000000..f8f9447a1--- /dev/null+++ b/wger/manager/helpers.py@@ -0,0 +1,47 @@+# -*- coding: utf-8 -*-++# This file is part of wger Workout Manager.+#+# wger Workout Manager is free software: you can redistribute it and/or modify+# it under the terms of the GNU Affero General Public License as published by+# the Free Software Foundation, either version 3 of the License, or+# (at your option) any later version.+#+# wger Workout Manager is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU Affero General Public License+# along with Workout Manager. If not, see <http://www.gnu.org/licenses/>.+++def reps_smart_text(settings, set_obj):+ '''+ "Smart" textual representation+ This is a human representation of the settings, in a way that humans+ would also write: e.g. "8 8 10 10" but "4 x 10" and not "10 10 10 10"++ :param settings:+ :param set_obj:+ :return setting_text, setting_list:+ '''+ if len(settings) == 0:+ setting_text = ''+ setting_list = []+ elif len(settings) == 1:+ reps = settings[0].reps if settings[0].reps != 99 else u'∞'+ setting_text = u'{0} × {1}'.format(set_obj.sets, reps)+ setting_list = [settings[0].reps] * set_obj.sets+ elif len(settings) > 1:+ tmp_reps_text = []+ tmp_reps = []+ for i in settings:+ reps = str(i.reps) if i.reps != 99 else u'∞'+ tmp_reps_text.append(reps)+ tmp_reps.append(i.reps)++ setting_text = u' – '.join(tmp_reps_text)+ setting_list = tmp_reps++ return setting_text, setting_listdiff --git a/wger/manager/models.py b/wger/manager/models.pyindex 011d84d3d..ca941f739 100644--- a/wger/manager/models.py+++ b/wger/manager/models.py@@ -15,10 +15,10 @@# You should have received a copy of the GNU Affero General Public License# along with Workout Manager. If not, see <http://www.gnu.org/licenses/>.-import siximport datetimeimport logging+import sixfrom django.db import modelsfrom django.utils.translation import ugettext_lazy as _from django.contrib.auth.models import User@@ -31,6 +31,7 @@ from django.core.validators import MinValueValidatorfrom wger.core.models import DaysOfWeekfrom wger.exercises.models import Exercise+from wger.manager.helpers import reps_smart_textfrom wger.utils.cache import cache_mapper, reset_workout_canonical_formfrom wger.utils.fields import Html5DateField@@ -724,37 +725,3 @@ class WorkoutSession(models.Model):Returns the object that has owner information'''return self---#-# Helpers-#-def reps_smart_text(settings, set_obj):- '''- "Smart" textual representation- This is a human representation of the settings, in a way that humans- would also write: e.g. "8 8 10 10" but "4 x 10" and not "10 10 10 10"-- :param settings:- :param set_obj:- :return setting_text, setting_list:- '''- if len(settings) == 0:- setting_text = ''- setting_list = []- elif len(settings) == 1:- reps = settings[0].reps if settings[0].reps != 99 else u'∞'- setting_text = u'{0} × {1}'.format(set_obj.sets, reps)- setting_list = [settings[0].reps] * set_obj.sets- elif len(settings) > 1:- tmp_reps_text = []- tmp_reps = []- for i in settings:- reps = str(i.reps) if i.reps != 99 else u'∞'- tmp_reps_text.append(reps)- tmp_reps.append(i.reps)-- setting_text = u' – '.join(tmp_reps_text)- setting_list = tmp_reps-- return setting_text, setting_list