Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Use __str__ instead of __unicode__ in models

Roland Geiderd0f666352e0a
diff --git a/wger/config/models.py b/wger/config/models.py
index 06d815fc7..2ecc0d9b6 100644
--- a/wger/config/models.py
+++ b/wger/config/models.py
@@ -19,6 +19,7 @@ import logging
from django.db import models
from django.db.models.signals import post_save
+from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from django.core.cache import cache
from wger.core.models import Language
@@ -33,6 +34,7 @@ from wger.utils.cache import cache_mapper
logger = logging.getLogger('wger.custom')
+@python_2_unicode_compatible
class LanguageConfig(models.Model):
'''
Configuration for languages
@@ -63,7 +65,7 @@ class LanguageConfig(models.Model):
'''
ordering = ["item", "language_target", ]
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -122,6 +124,7 @@ def init_language_config(sender, instance, created, **kwargs):
post_save.connect(init_language_config, sender=Language)
+@python_2_unicode_compatible
class GymConfig(models.Model):
'''
System wide configuration for gyms
@@ -142,7 +145,7 @@ class GymConfig(models.Model):
Default gym for the wger installation
'''
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
diff --git a/wger/core/models.py b/wger/core/models.py
index d443f3f8b..b1105e33e 100644
--- a/wger/core/models.py
+++ b/wger/core/models.py
@@ -24,6 +24,7 @@ from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.core.exceptions import ValidationError
from django.core.validators import MinValueValidator, MaxValueValidator
+from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from wger.gym.models import Gym
@@ -34,6 +35,7 @@ from wger.utils.units import AbstractWeight
from wger.weight.models import WeightEntry
+@python_2_unicode_compatible
class Language(models.Model):
'''
Language of an item (exercise, workout, etc.)
@@ -56,7 +58,7 @@ class Language(models.Model):
#
# Django methods
#
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -78,6 +80,7 @@ class Language(models.Model):
return False
+@python_2_unicode_compatible
class UserProfile(models.Model):
GENDER_MALE = '1'
GENDER_FEMALE = '2'
@@ -317,7 +320,7 @@ by the US Department of Agriculture. It is extremely complete, with around
and (self.sleep_hours + self.freetime_hours + self.work_hours) > 24):
raise ValidationError(_('The sum of all hours has to be 24'))
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -449,6 +452,7 @@ def create_user_profile(sender, instance, created, **kwargs):
post_save.connect(create_user_profile, sender=User)
+@python_2_unicode_compatible
class DaysOfWeek(models.Model):
'''
Model for the days of the week
@@ -465,13 +469,14 @@ class DaysOfWeek(models.Model):
'''
ordering = ["pk", ]
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
return self.day_of_week
+@python_2_unicode_compatible
class License(models.Model):
'''
License for an item (exercise, ingredient, etc.)
@@ -500,7 +505,7 @@ class License(models.Model):
#
# Django methods
#
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
diff --git a/wger/core/tests/test_daysofweek.py b/wger/core/tests/test_daysofweek.py
index cba422912..c4daaad11 100644
--- a/wger/core/tests/test_daysofweek.py
+++ b/wger/core/tests/test_daysofweek.py
@@ -15,9 +15,22 @@
from wger.core.models import DaysOfWeek
from wger.core.tests import api_base_test
+from wger.manager.tests.testcase import WorkoutManagerTestCase
-class LicenseApiTestCase(api_base_test.ApiBaseResourceTestCase):
+class DaysOfWeekRepresentationTestCase(WorkoutManagerTestCase):
+ '''
+ Test the representation of a model
+ '''
+
+ def test_representation(self):
+ '''
+ Test that the representation of an object is correct
+ '''
+ self.assertEqual("{0}".format(DaysOfWeek.objects.get(pk=1)), 'Monday')
+
+
+class DaysOfWeekApiTestCase(api_base_test.ApiBaseResourceTestCase):
'''
Tests the days of week resource
'''
diff --git a/wger/core/tests/test_language.py b/wger/core/tests/test_language.py
index 8bbc0d51a..1c2f6848e 100644
--- a/wger/core/tests/test_language.py
+++ b/wger/core/tests/test_language.py
@@ -19,12 +19,24 @@ from django.core.urlresolvers import reverse_lazy
from wger.core.models import Language
from wger.core.tests import api_base_test
-from wger.manager.tests.testcase import WorkoutManagerDeleteTestCase
+from wger.manager.tests.testcase import WorkoutManagerDeleteTestCase, WorkoutManagerTestCase
from wger.manager.tests.testcase import WorkoutManagerEditTestCase
from wger.manager.tests.testcase import WorkoutManagerAddTestCase
from wger.manager.tests.testcase import WorkoutManagerAccessTestCase
+class LanguageRepresentationTestCase(WorkoutManagerTestCase):
+ '''
+ Test the representation of a model
+ '''
+
+ def test_representation(self):
+ '''
+ Test that the representation of an object is correct
+ '''
+ self.assertEqual("{0}".format(Language.objects.get(pk=1)), 'Deutsch (de)')
+
+
class LanguageOverviewTest(WorkoutManagerAccessTestCase):
'''
Tests accessing the system's languages
diff --git a/wger/core/tests/test_license.py b/wger/core/tests/test_license.py
index 58e5890ff..683a25400 100644
--- a/wger/core/tests/test_license.py
+++ b/wger/core/tests/test_license.py
@@ -15,13 +15,27 @@
from wger.core.models import License
from wger.core.tests import api_base_test
+from wger.exercises.models import Exercise
-from wger.manager.tests.testcase import WorkoutManagerAccessTestCase
+from wger.manager.tests.testcase import WorkoutManagerAccessTestCase, WorkoutManagerTestCase
from wger.manager.tests.testcase import WorkoutManagerDeleteTestCase
from wger.manager.tests.testcase import WorkoutManagerEditTestCase
from wger.manager.tests.testcase import WorkoutManagerAddTestCase
+class LicenseRepresentationTestCase(WorkoutManagerTestCase):
+ '''
+ Test the representation of a model
+ '''
+
+ def test_representation(self):
+ '''
+ Test that the representation of an object is correct
+ '''
+ self.assertEqual("{0}".format(Exercise.objects.get(pk=1)),
+ 'A cool and free license - Germany (ACAFL - DE)')
+
+
class LicenseOverviewTest(WorkoutManagerAccessTestCase):
'''
Tests the licese overview page
diff --git a/wger/exercises/models.py b/wger/exercises/models.py
index 5faed513d..65d9df5c9 100644
--- a/wger/exercises/models.py
+++ b/wger/exercises/models.py
@@ -23,6 +23,7 @@ from django.template.loader import render_to_string
from django.template.defaultfilters import slugify # django.utils.text.slugify in django 1.5!
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
+from django.utils.encoding import python_2_unicode_compatible
from django.utils import translation
from django.core.urlresolvers import reverse
from django.core import mail
@@ -47,6 +48,7 @@ from wger.utils.cache import cache_mapper
logger = logging.getLogger('wger.custom')
+@python_2_unicode_compatible
class Muscle(models.Model):
'''
Muscle an exercise works out
@@ -63,7 +65,7 @@ class Muscle(models.Model):
class Meta:
ordering = ["name", ]
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -76,6 +78,7 @@ class Muscle(models.Model):
return False
+@python_2_unicode_compatible
class Equipment(models.Model):
'''
Equipment used or needed by an exercise
@@ -90,7 +93,7 @@ class Equipment(models.Model):
'''
ordering = ["name", ]
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -103,6 +106,7 @@ class Equipment(models.Model):
return False
+@python_2_unicode_compatible
class ExerciseCategory(models.Model):
'''
Model for an exercise category
@@ -115,7 +119,7 @@ class ExerciseCategory(models.Model):
verbose_name_plural = _("Exercise Categories")
ordering = ["name", ]
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -150,6 +154,7 @@ class ExerciseCategory(models.Model):
super(ExerciseCategory, self).delete(*args, **kwargs)
+@python_2_unicode_compatible
class Exercise(AbstractSubmissionModel, AbstractLicenseModel, models.Model):
'''
Model for an exercise
@@ -257,7 +262,7 @@ class Exercise(AbstractSubmissionModel, AbstractLicenseModel, models.Model):
super(Exercise, self).delete(*args, **kwargs)
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -495,6 +500,7 @@ pre_save.connect(delete_exercise_image_on_update, sender=ExerciseImage)
saved_file.connect(generate_aliases)
+@python_2_unicode_compatible
class ExerciseComment(models.Model):
'''
Model for an exercise comment
@@ -506,7 +512,7 @@ class ExerciseComment(models.Model):
verbose_name=_('Comment'),
help_text=_('A comment about how to correctly do this exercise.'))
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
diff --git a/wger/exercises/tests/test_categories.py b/wger/exercises/tests/test_categories.py
index ed9e48617..91d19b31c 100644
--- a/wger/exercises/tests/test_categories.py
+++ b/wger/exercises/tests/test_categories.py
@@ -25,6 +25,18 @@ from wger.manager.tests.testcase import WorkoutManagerEditTestCase
from wger.manager.tests.testcase import WorkoutManagerAddTestCase
+class ExerciseCategoryRepresentationTestCase(WorkoutManagerTestCase):
+ '''
+ Test the representation of a model
+ '''
+
+ def test_representation(self):
+ '''
+ Test that the representation of an object is correct
+ '''
+ self.assertEqual("{0}".format(ExerciseCategory.objects.get(pk=1)), 'Category')
+
+
class DeleteExerciseCategoryTestCase(WorkoutManagerDeleteTestCase):
'''
Exercise category delete test case
diff --git a/wger/exercises/tests/test_equipment.py b/wger/exercises/tests/test_equipment.py
index 189be322b..31a93b728 100644
--- a/wger/exercises/tests/test_equipment.py
+++ b/wger/exercises/tests/test_equipment.py
@@ -29,6 +29,18 @@ from wger.utils.cache import get_template_cache_name, cache_mapper
from wger.utils.constants import PAGINATION_OBJECTS_PER_PAGE
+class EquipmentRepresentationTestCase(WorkoutManagerTestCase):
+ '''
+ Test the representation of a model
+ '''
+
+ def test_representation(self):
+ '''
+ Test that the representation of an object is correct
+ '''
+ self.assertEqual("{0}".format(Equipment.objects.get(pk=1)), 'Dumbbells')
+
+
class AddEquipmentTestCase(WorkoutManagerAddTestCase):
'''
Tests adding a new equipment
diff --git a/wger/exercises/tests/test_exercise.py b/wger/exercises/tests/test_exercise.py
index a30b65f5c..333192deb 100644
--- a/wger/exercises/tests/test_exercise.py
+++ b/wger/exercises/tests/test_exercise.py
@@ -29,6 +29,18 @@ from wger.utils.cache import get_template_cache_name
from wger.utils.cache import cache_mapper
+class ExerciseRepresentationTestCase(WorkoutManagerTestCase):
+ '''
+ Test the representation of a model
+ '''
+
+ def test_representation(self):
+ '''
+ Test that the representation of an object is correct
+ '''
+ self.assertEqual("{0}".format(Exercise.objects.get(pk=1)), 'An exercise')
+
+
class ExerciseIndexTestCase(WorkoutManagerTestCase):
def exercise_index(self, logged_in=True, demo=False, admin=False):
diff --git a/wger/exercises/tests/test_exercise_comments.py b/wger/exercises/tests/test_exercise_comments.py
index c3560363c..4e7499842 100644
--- a/wger/exercises/tests/test_exercise_comments.py
+++ b/wger/exercises/tests/test_exercise_comments.py
@@ -26,6 +26,18 @@ from wger.manager.tests.testcase import WorkoutManagerAddTestCase
from wger.utils.cache import cache_mapper
+class ExerciseCommentRepresentationTestCase(WorkoutManagerTestCase):
+ '''
+ Test the representation of a model
+ '''
+
+ def test_representation(self):
+ '''
+ Test that the representation of an object is correct
+ '''
+ self.assertEqual("{0}".format(ExerciseComment.objects.get(pk=1)), 'test 123')
+
+
class AddExerciseCommentTestCase(WorkoutManagerAddTestCase):
'''
Tests adding a comment to an exercise
diff --git a/wger/exercises/tests/test_muscles.py b/wger/exercises/tests/test_muscles.py
index 3fd336523..4cff61d4e 100644
--- a/wger/exercises/tests/test_muscles.py
+++ b/wger/exercises/tests/test_muscles.py
@@ -26,6 +26,18 @@ from wger.manager.tests.testcase import WorkoutManagerAddTestCase
from wger.utils.cache import get_template_cache_name
+class MuscleRepresentationTestCase(WorkoutManagerTestCase):
+ '''
+ Test the representation of a model
+ '''
+
+ def test_representation(self):
+ '''
+ Test that the representation of an object is correct
+ '''
+ self.assertEqual("{0}".format(Muscle.objects.get(pk=1)), 'Anterior testoid')
+
+
class AddMuscleTestCase(WorkoutManagerAddTestCase):
'''
Tests adding a muscle
diff --git a/wger/gym/models.py b/wger/gym/models.py
index 69f632d55..b56eb7bb7 100644
--- a/wger/gym/models.py
+++ b/wger/gym/models.py
@@ -19,10 +19,12 @@ import uuid
from django.db import models as m
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
+from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext
+@python_2_unicode_compatible
class Gym(m.Model):
'''
Model for a gym
@@ -75,7 +77,7 @@ class Gym(m.Model):
null=True)
'''Street'''
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -105,6 +107,7 @@ class Gym(m.Model):
return None
+@python_2_unicode_compatible
class GymConfig(m.Model):
'''
Configuration options for a gym
@@ -126,7 +129,7 @@ class GymConfig(m.Model):
Reminder inactive members
'''
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -269,6 +272,7 @@ def gym_document_upload_dir(instance, filename):
uuid.uuid4())
+@python_2_unicode_compatible
class UserDocument(m.Model):
'''
Model for a document
@@ -331,7 +335,7 @@ class UserDocument(m.Model):
Note with additional information
'''
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
diff --git a/wger/gym/tests/test_gym.py b/wger/gym/tests/test_gym.py
index 646a795bc..ee359bcad 100644
--- a/wger/gym/tests/test_gym.py
+++ b/wger/gym/tests/test_gym.py
@@ -24,6 +24,18 @@ from wger.manager.tests.testcase import WorkoutManagerEditTestCase
from wger.manager.tests.testcase import WorkoutManagerAddTestCase
+class GymRepresentationTestCase(WorkoutManagerTestCase):
+ '''
+ Test the representation of a model
+ '''
+
+ def test_representation(self):
+ '''
+ Test that the representation of an object is correct
+ '''
+ self.assertEqual("{0}".format(Gym.objects.get(pk=1)), 'Test 123')
+
+
class GymOverviewTest(WorkoutManagerAccessTestCase):
'''
Tests accessing the gym overview page
diff --git a/wger/manager/models.py b/wger/manager/models.py
index 7a435e338..69810a29c 100644
--- a/wger/manager/models.py
+++ b/wger/manager/models.py
@@ -17,6 +17,7 @@
import datetime
import logging
+from django.utils.encoding import python_2_unicode_compatible
import six
from django.db import models
@@ -42,6 +43,7 @@ logger = logging.getLogger('wger.custom')
#
# Classes
#
+@python_2_unicode_compatible
class Workout(models.Model):
'''
Model for a training schedule
@@ -67,7 +69,7 @@ class Workout(models.Model):
'''
return reverse('manager:workout:view', kwargs={'id': self.id})
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -179,6 +181,7 @@ class ScheduleManager(models.Manager):
return (active_workout, schedule)
+@python_2_unicode_compatible
class Schedule(models.Model):
'''
Model for a workout schedule.
@@ -223,7 +226,7 @@ class Schedule(models.Model):
"in a loop (i.e. A, B, C, A, B, C, and so on)"))
'''A flag indicating whether the schedule should act as a loop'''
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -283,6 +286,7 @@ class Schedule(models.Model):
return end_date
+@python_2_unicode_compatible
class ScheduleStep(models.Model):
'''
Model for a step in a workout schedule.
@@ -320,7 +324,7 @@ class ScheduleStep(models.Model):
'''
return self.workout
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -347,6 +351,7 @@ class ScheduleStep(models.Model):
return start_date, end_date
+@python_2_unicode_compatible
class Day(models.Model):
'''
Model for a training day
@@ -361,7 +366,7 @@ class Day(models.Model):
day = models.ManyToManyField(DaysOfWeek,
verbose_name=_('Day'))
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -494,6 +499,7 @@ class Day(models.Model):
'set_list': canonical_repr}
+@python_2_unicode_compatible
class Set(models.Model):
'''
Model for a set of exercises
@@ -516,7 +522,7 @@ class Set(models.Model):
class Meta:
ordering = ["order", ]
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -545,6 +551,7 @@ class Set(models.Model):
super(Set, self).delete(*args, **kwargs)
+@python_2_unicode_compatible
class Setting(models.Model):
'''
Settings for an exercise (weight, reps, etc.)
@@ -565,7 +572,7 @@ class Setting(models.Model):
class Meta:
ordering = ["order", "id"]
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -594,6 +601,7 @@ class Setting(models.Model):
return self.set.exerciseday.training
+@python_2_unicode_compatible
class WorkoutLog(models.Model):
'''
A log entry for an exercise
@@ -620,7 +628,7 @@ class WorkoutLog(models.Model):
class Meta:
ordering = ["date", "reps"]
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -663,6 +671,7 @@ class WorkoutLog(models.Model):
super(WorkoutLog, self).delete(*args, **kwargs)
+@python_2_unicode_compatible
class WorkoutSession(models.Model):
'''
Model for a workout session
@@ -730,7 +739,7 @@ class WorkoutSession(models.Model):
Time the workout session ended
'''
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
diff --git a/wger/manager/tests/test_day.py b/wger/manager/tests/test_day.py
index fef5314d3..49df3e824 100644
--- a/wger/manager/tests/test_day.py
+++ b/wger/manager/tests/test_day.py
@@ -23,6 +23,18 @@ from wger.manager.tests.testcase import WorkoutManagerEditTestCase
from wger.utils.cache import cache_mapper
+class DayRepresentationTestCase(WorkoutManagerTestCase):
+ '''
+ Test the representation of a model
+ '''
+
+ def test_representation(self):
+ '''
+ Test that the representation of an object is correct
+ '''
+ self.assertEqual("{0}".format(Day.objects.get(pk=1)), 'A day')
+
+
class AddWorkoutDayTestCase(WorkoutManagerAddTestCase):
'''
Tests adding a day to a workout
diff --git a/wger/manager/tests/test_schedule.py b/wger/manager/tests/test_schedule.py
index 7278ddc42..55d9a1940 100644
--- a/wger/manager/tests/test_schedule.py
+++ b/wger/manager/tests/test_schedule.py
@@ -34,6 +34,19 @@ from wger.utils.helpers import make_token
logger = logging.getLogger('wger.custom')
+class ScheduleRepresentationTestCase(WorkoutManagerTestCase):
+ '''
+ Test the representation of a model
+ '''
+
+ def test_representation(self):
+ '''
+ Test that the representation of an object is correct
+ '''
+ self.assertEqual("{0}".format(Schedule.objects.get(pk=1)),
+ 'my cool schedule that i found on the internet')
+
+
class CreateScheduleTestCase(WorkoutManagerAddTestCase):
'''
Tests adding a schedule
diff --git a/wger/manager/tests/test_schedule_step.py b/wger/manager/tests/test_schedule_step.py
index 4ca073fb9..3f3caae99 100644
--- a/wger/manager/tests/test_schedule_step.py
+++ b/wger/manager/tests/test_schedule_step.py
@@ -23,6 +23,18 @@ from wger.manager.tests.testcase import WorkoutManagerEditTestCase
from wger.manager.tests.testcase import WorkoutManagerAddTestCase
+class ScheduleStepRepresentationTestCase(WorkoutManagerTestCase):
+ '''
+ Test the representation of a model
+ '''
+
+ def test_representation(self):
+ '''
+ Test that the representation of an object is correct
+ '''
+ self.assertEqual("{0}".format(ScheduleStep.objects.get(pk=1)), 'A test workout')
+
+
class ScheduleStepTestCase(WorkoutManagerTestCase):
'''
Other tests
diff --git a/wger/manager/tests/test_workout.py b/wger/manager/tests/test_workout.py
index 27c17c54c..d75a36d4f 100644
--- a/wger/manager/tests/test_workout.py
+++ b/wger/manager/tests/test_workout.py
@@ -122,11 +122,11 @@ class WorkoutModelTestCase(WorkoutManagerTestCase):
workout = Workout()
workout.creation_date = datetime.date.today()
- self.assertEqual(workout.__unicode__(),
- u'{0} ({1})'.format(u'Workout', datetime.date.today()))
+ self.assertEqual('{0}'.format(workout),
+ '{0} ({1})'.format(u'Workout', datetime.date.today()))
workout.comment = u'my description'
- self.assertEqual(workout.__unicode__(), u'my description')
+ self.assertEqual('{0}'.format(workout), u'my description')
class WorkoutApiTestCase(api_base_test.ApiBaseResourceTestCase):
diff --git a/wger/manager/tests/test_workout_session.py b/wger/manager/tests/test_workout_session.py
index f9271295c..3d7be3a95 100644
--- a/wger/manager/tests/test_workout_session.py
+++ b/wger/manager/tests/test_workout_session.py
@@ -85,7 +85,7 @@ class WorkoutSessionModelTestCase(WorkoutManagerTestCase):
session = WorkoutSession()
session.workout = Workout.objects.get(pk=1)
session.date = datetime.date.today()
- self.assertEqual(session.__unicode__(),
+ self.assertEqual('{0}'.format(session),
u'{0} - {1}'.format(Workout.objects.get(pk=1), datetime.date.today()))
diff --git a/wger/nutrition/models.py b/wger/nutrition/models.py
index 7cb1feb60..86d2f4f96 100644
--- a/wger/nutrition/models.py
+++ b/wger/nutrition/models.py
@@ -28,6 +28,7 @@ from django.core.urlresolvers import reverse
from django.core import mail
from django.core.cache import cache
from django.contrib.auth.models import User
+from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from django.utils import translation
@@ -57,6 +58,7 @@ Simple approximation of energy (kcal) provided per gram or ounce
logger = logging.getLogger('wger.custom')
+@python_2_unicode_compatible
class NutritionPlan(models.Model):
'''
A nutrition plan
@@ -88,7 +90,7 @@ class NutritionPlan(models.Model):
"value yourself."))
'''A flag indicating whether the plan has a goal amount of calories'''
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -181,6 +183,7 @@ class NutritionPlan(models.Model):
return 4
+@python_2_unicode_compatible
class Ingredient(AbstractLicenseModel, models.Model):
'''
An ingredient, with some approximate nutrition values
@@ -355,11 +358,11 @@ class Ingredient(AbstractLicenseModel, models.Model):
super(Ingredient, self).save(*args, **kwargs)
cache.delete(cache_mapper.get_ingredient_key(self.id))
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
- return u"{0}".format(self.name)
+ return self.name
def __eq__(self, other):
'''
@@ -422,6 +425,7 @@ class Ingredient(AbstractLicenseModel, models.Model):
return False
+@python_2_unicode_compatible
class WeightUnit(models.Model):
'''
A more human usable weight unit (spoon, table, slice...)
@@ -438,9 +442,6 @@ class WeightUnit(models.Model):
ordering = ["name", ]
def __str__(self):
- return self.__unicode__()
-
- def __unicode__(self):
'''
Return a more human-readable representation
'''
@@ -453,6 +454,7 @@ class WeightUnit(models.Model):
return None
+@python_2_unicode_compatible
class IngredientWeightUnit(models.Model):
'''
A specific human usable weight unit for an ingredient
@@ -476,7 +478,7 @@ class IngredientWeightUnit(models.Model):
'''
return None
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -486,6 +488,7 @@ class IngredientWeightUnit(models.Model):
self.gram)
+@python_2_unicode_compatible
class Meal(models.Model):
'''
A meal
@@ -506,7 +509,7 @@ class Meal(models.Model):
blank=True,
verbose_name=_('Time (approx)'))
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
@@ -547,6 +550,7 @@ class Meal(models.Model):
return nutritional_info
+@python_2_unicode_compatible
class MealItem(models.Model):
'''
An item (component) of a meal
@@ -572,7 +576,7 @@ class MealItem(models.Model):
validators=[MinValueValidator(1),
MaxValueValidator(1000)])
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
diff --git a/wger/nutrition/tests/test_ingredient.py b/wger/nutrition/tests/test_ingredient.py
index d5363dd6e..827139ab9 100644
--- a/wger/nutrition/tests/test_ingredient.py
+++ b/wger/nutrition/tests/test_ingredient.py
@@ -32,6 +32,18 @@ from wger.manager.tests.testcase import WorkoutManagerEditTestCase
from wger.manager.tests.testcase import WorkoutManagerAddTestCase
+class IngredientRepresentationTestCase(WorkoutManagerTestCase):
+ '''
+ Test the representation of a model
+ '''
+
+ def test_representation(self):
+ '''
+ Test that the representation of an object is correct
+ '''
+ self.assertEqual("{0}".format(Ingredient.objects.get(pk=1)), 'Test ingredient 1')
+
+
class DeleteIngredientTestCase(WorkoutManagerDeleteTestCase):
'''
Tests deleting an ingredient
diff --git a/wger/nutrition/tests/test_meal.py b/wger/nutrition/tests/test_meal.py
index 0a223f43e..a51dd07b1 100644
--- a/wger/nutrition/tests/test_meal.py
+++ b/wger/nutrition/tests/test_meal.py
@@ -26,6 +26,18 @@ from wger.manager.tests.testcase import WorkoutManagerEditTestCase
from wger.manager.tests.testcase import WorkoutManagerAddTestCase
+class MealRepresentationTestCase(WorkoutManagerTestCase):
+ '''
+ Test the representation of a model
+ '''
+
+ def test_representation(self):
+ '''
+ Test that the representation of an object is correct
+ '''
+ self.assertEqual("{0}".format(Meal.objects.get(pk=1)), '1 Meal')
+
+
class EditMealTestCase(WorkoutManagerEditTestCase):
'''
Tests editing a meal
diff --git a/wger/nutrition/tests/test_plan.py b/wger/nutrition/tests/test_plan.py
index 4c2553230..451d2f2be 100644
--- a/wger/nutrition/tests/test_plan.py
+++ b/wger/nutrition/tests/test_plan.py
@@ -22,6 +22,23 @@ from wger.manager.tests.testcase import WorkoutManagerEditTestCase
from wger.manager.tests.testcase import WorkoutManagerTestCase
+class PlanRepresentationTestCase(WorkoutManagerTestCase):
+ '''
+ Test the representation of a model
+ '''
+
+ def test_representation(self):
+ '''
+ Test that the representation of an object is correct
+ '''
+ p = NutritionPlan.objects.get(pk=1)
+ self.assertEqual("{0}".format(p), 'Description 1')
+
+ p.description = ''
+ p.save()
+ self.assertEqual("{0}".format(p), 'Nutrition plan')
+
+
class DeletePlanTestCase(WorkoutManagerDeleteTestCase):
'''
Tests deleting a nutritional plan
diff --git a/wger/nutrition/tests/test_weight_unit.py b/wger/nutrition/tests/test_weight_unit.py
index d48a5d734..1559b677b 100644
--- a/wger/nutrition/tests/test_weight_unit.py
+++ b/wger/nutrition/tests/test_weight_unit.py
@@ -26,6 +26,18 @@ from wger.manager.tests.testcase import WorkoutManagerAddTestCase
from wger.utils.constants import PAGINATION_OBJECTS_PER_PAGE
+class WeightUnitRepresentationTestCase(WorkoutManagerTestCase):
+ '''
+ Test the representation of a model
+ '''
+
+ def test_representation(self):
+ '''
+ Test that the representation of an object is correct
+ '''
+ self.assertEqual("{0}".format(WeightUnit.objects.get(pk=1)), 'Scheibe')
+
+
class AddWeightUnitTestCase(WorkoutManagerAddTestCase):
'''
Tests adding a new weight unit
diff --git a/wger/nutrition/tests/test_weight_unit_ingredient.py b/wger/nutrition/tests/test_weight_unit_ingredient.py
index 0ed5568fc..3aaed0862 100644
--- a/wger/nutrition/tests/test_weight_unit_ingredient.py
+++ b/wger/nutrition/tests/test_weight_unit_ingredient.py
@@ -26,6 +26,18 @@ from wger.manager.tests.testcase import WorkoutManagerEditTestCase
from wger.manager.tests.testcase import WorkoutManagerAddTestCase
+class WeightUnitIngredientRepresentationTestCase(WorkoutManagerTestCase):
+ '''
+ Test the representation of a model
+ '''
+
+ def test_representation(self):
+ '''
+ Test that the representation of an object is correct
+ '''
+ self.assertEqual("{0}".format(IngredientWeightUnit.objects.get(pk=1)), 'Spoon (109g)')
+
+
class AddWeightUnitIngredientTestCase(WorkoutManagerAddTestCase):
'''
Tests adding a new weight unit to an ingredient
diff --git a/wger/weight/models.py b/wger/weight/models.py
index 0cc3c3e5e..e4481dc62 100644
--- a/wger/weight/models.py
+++ b/wger/weight/models.py
@@ -19,9 +19,11 @@ from django.db import models
from django.core.validators import MinValueValidator, MaxValueValidator
from django.contrib.auth.models import User
+from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
+@python_2_unicode_compatible
class WeightEntry(models.Model):
'''
Model for a weight point
@@ -52,7 +54,7 @@ class WeightEntry(models.Model):
get_latest_by = "creation_date"
unique_together = ("creation_date", "user")
- def __unicode__(self):
+ def __str__(self):
'''
Return a more human-readable representation
'''
diff --git a/wger/weight/tests/test_entry.py b/wger/weight/tests/test_entry.py
index 77478d5b9..1cbed55fc 100644
--- a/wger/weight/tests/test_entry.py
+++ b/wger/weight/tests/test_entry.py
@@ -20,10 +20,22 @@ from wger.utils.constants import TWOPLACES
from wger.weight.models import WeightEntry
-from wger.manager.tests.testcase import WorkoutManagerEditTestCase
+from wger.manager.tests.testcase import WorkoutManagerEditTestCase, WorkoutManagerTestCase
from wger.manager.tests.testcase import WorkoutManagerAddTestCase
+class MealRepresentationTestCase(WorkoutManagerTestCase):
+ '''
+ Test the representation of a model
+ '''
+
+ def test_representation(self):
+ '''
+ Test that the representation of an object is correct
+ '''
+ self.assertEqual("{0}".format(WeightEntry.objects.get(pk=1)), '2012-10-01: 77kg')
+
+
class AddWeightEntryTestCase(WorkoutManagerAddTestCase):
'''
Tests adding a weight entry