Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Support for imperial units

Roland Geider48fa7fb84eae
diff --git a/wger/core/forms.py b/wger/core/forms.py
index 061440e60..b0f55ce0f 100644
--- a/wger/core/forms.py
+++ b/wger/core/forms.py
@@ -33,6 +33,7 @@ class UserPreferencesForm(forms.ModelForm):
'workout_reminder',
'workout_duration',
'notification_language',
+ 'weight_unit',
'timer_active',
'timer_pause')
diff --git a/wger/core/migrations/0010_auto__add_field_userprofile_weight_unit.py b/wger/core/migrations/0010_auto__add_field_userprofile_weight_unit.py
new file mode 100644
index 000000000..deb9dc969
--- /dev/null
+++ b/wger/core/migrations/0010_auto__add_field_userprofile_weight_unit.py
@@ -0,0 +1,118 @@
+# -*- coding: utf-8 -*-
+from south.utils import datetime_utils as datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding field 'UserProfile.weight_unit'
+ db.add_column(u'core_userprofile', 'weight_unit',
+ self.gf('django.db.models.fields.CharField')(default='kg', max_length=2),
+ keep_default=False)
+
+
+ def backwards(self, orm):
+ # Deleting field 'UserProfile.weight_unit'
+ db.delete_column(u'core_userprofile', 'weight_unit')
+
+
+ models = {
+ u'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ u'auth.permission': {
+ 'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ u'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Group']"}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Permission']"}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ u'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ u'core.daysofweek': {
+ 'Meta': {'ordering': "['pk']", 'object_name': 'DaysOfWeek'},
+ 'day_of_week': ('django.db.models.fields.CharField', [], {'max_length': '9'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+ },
+ u'core.language': {
+ 'Meta': {'ordering': "['full_name']", 'object_name': 'Language'},
+ 'full_name': ('django.db.models.fields.CharField', [], {'max_length': '30'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'short_name': ('django.db.models.fields.CharField', [], {'max_length': '2'})
+ },
+ u'core.license': {
+ 'Meta': {'ordering': "['full_name']", 'object_name': 'License'},
+ 'full_name': ('django.db.models.fields.CharField', [], {'max_length': '60'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'short_name': ('django.db.models.fields.CharField', [], {'max_length': '15'}),
+ 'url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'})
+ },
+ u'core.userprofile': {
+ 'Meta': {'object_name': 'UserProfile'},
+ 'age': ('django.db.models.fields.IntegerField', [], {'max_length': '2', 'null': 'True'}),
+ 'calories': ('django.db.models.fields.IntegerField', [], {'default': '2500', 'null': 'True'}),
+ 'freetime_hours': ('django.db.models.fields.IntegerField', [], {'default': '8', 'null': 'True'}),
+ 'freetime_intensity': ('django.db.models.fields.CharField', [], {'default': "'1'", 'max_length': '1', 'null': 'True'}),
+ 'gender': ('django.db.models.fields.CharField', [], {'default': "'1'", 'max_length': '1', 'null': 'True'}),
+ 'gym': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['gym.Gym']", 'null': 'True', 'blank': 'True'}),
+ 'height': ('django.db.models.fields.IntegerField', [], {'max_length': '2', 'null': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_temporary': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_workout_notification': ('django.db.models.fields.DateField', [], {'null': 'True'}),
+ 'notification_language': ('django.db.models.fields.related.ForeignKey', [], {'default': '2', 'to': u"orm['core.Language']"}),
+ 'show_comments': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'show_english_ingredients': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'sleep_hours': ('django.db.models.fields.IntegerField', [], {'default': '7', 'null': 'True'}),
+ 'sport_hours': ('django.db.models.fields.IntegerField', [], {'default': '3', 'null': 'True'}),
+ 'sport_intensity': ('django.db.models.fields.CharField', [], {'default': "'2'", 'max_length': '1', 'null': 'True'}),
+ 'timer_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'timer_pause': ('django.db.models.fields.IntegerField', [], {'default': '90'}),
+ 'user': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['auth.User']", 'unique': 'True'}),
+ 'weight_unit': ('django.db.models.fields.CharField', [], {'default': "'kg'", 'max_length': '2'}),
+ 'work_hours': ('django.db.models.fields.IntegerField', [], {'default': '8', 'null': 'True'}),
+ 'work_intensity': ('django.db.models.fields.CharField', [], {'default': "'1'", 'max_length': '1', 'null': 'True'}),
+ 'workout_duration': ('django.db.models.fields.IntegerField', [], {'default': '12'}),
+ 'workout_reminder': ('django.db.models.fields.IntegerField', [], {'default': '14'}),
+ 'workout_reminder_active': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
+ },
+ u'gym.gym': {
+ 'Meta': {'ordering': "['name']", 'object_name': 'Gym'},
+ 'city': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '60'}),
+ 'owner': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'phone': ('django.db.models.fields.CharField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'}),
+ 'street': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}),
+ 'zip_code': ('django.db.models.fields.IntegerField', [], {'max_length': '5', 'null': 'True', 'blank': 'True'})
+ }
+ }
+
+ complete_apps = ['core']
\ No newline at end of file
diff --git a/wger/core/models.py b/wger/core/models.py
index dfadfa0cd..98b3e715e 100644
--- a/wger/core/models.py
+++ b/wger/core/models.py
@@ -94,6 +94,13 @@ class UserProfile(models.Model):
(INTENSITY_HIGH, _('High')),
)
+ UNITS_KG = 'kg'
+ UNITS_LB = 'lb'
+ UNITS = (
+ (UNITS_KG, _('Metric (kilogram)')),
+ (UNITS_LB, _('Imperial (pound)'))
+ )
+
user = models.OneToOneField(User,
editable=False)
'''
@@ -280,6 +287,18 @@ by the US Department of Agriculture. It is extremely complete, with around
validators=[MinValueValidator(1500), MaxValueValidator(5000)])
'''Basic caloric intake based on physical activity'''
+ #
+ # Others
+ #
+ weight_unit = models.CharField(verbose_name=_('Weight unit'),
+ help_text=_('Select your preferred unit. This setting controls '
+ 'how the weight entries are interpreted if there '
+ 'are any calculations as well as their display.'),
+ max_length=2,
+ choices=UNITS,
+ default=UNITS_KG)
+ '''Preferred weight unit'''
+
@property
def weight(self):
'''
diff --git a/wger/core/templates/user/preferences.html b/wger/core/templates/user/preferences.html
index 5d35e444d..de7f9882c 100644
--- a/wger/core/templates/user/preferences.html
+++ b/wger/core/templates/user/preferences.html
@@ -89,6 +89,7 @@ $(function() {
<div id="collapseOther" class="panel-collapse collapse">
<div class="panel-body">
{% render_form_field form.notification_language %}
+ {% render_form_field form.weight_unit %}
{% render_form_field form.show_comments %}
{% render_form_field form.show_english_ingredients %}
</div>
diff --git a/wger/core/tests/test_preferences.py b/wger/core/tests/test_preferences.py
index abe84f3ec..10ec987ab 100644
--- a/wger/core/tests/test_preferences.py
+++ b/wger/core/tests/test_preferences.py
@@ -57,7 +57,8 @@ class PreferencesTestCase(WorkoutManagerTestCase):
'workout_duration': 12,
'notification_language': 2,
'timer_active': False,
- 'timer_pause': 100})
+ 'timer_pause': 100,
+ 'weight_unit': 'kg'})
self.assertEqual(response.status_code, 302)
response = self.client.get(reverse('core:user:preferences'))
@@ -78,7 +79,8 @@ class PreferencesTestCase(WorkoutManagerTestCase):
'workout_duration': 10,
'notification_language': 2,
'timer_active': True,
- 'timer_pause': 40})
+ 'timer_pause': 40,
+ 'weight_unit': 'lb'})
self.assertEqual(response.status_code, 302)
response = self.client.get(reverse('core:user:preferences'))
diff --git a/wger/manager/fixtures/test-user-data.json b/wger/manager/fixtures/test-user-data.json
index 1bae46a87..5d62567e2 100644
--- a/wger/manager/fixtures/test-user-data.json
+++ b/wger/manager/fixtures/test-user-data.json
@@ -500,7 +500,8 @@
"notification_language": 1,
"timer_active": true,
"timer_pause": 90,
- "gym": 1
+ "gym": 1,
+ "weight_unit": "kg"
}
},
{
@@ -528,7 +529,8 @@
"notification_language": 2,
"timer_active": true,
"timer_pause": 90,
- "gym": 1
+ "gym": 1,
+ "weight_unit": "kg"
}
},
{
@@ -554,7 +556,8 @@
"workout_reminder": 10,
"workout_duration": 15,
"notification_language": 2,
- "gym": 2
+ "gym": 2,
+ "weight_unit": "kg"
}
},
{
@@ -582,7 +585,8 @@
"notification_language": 2,
"timer_active": true,
"timer_pause": 90,
- "gym": 1
+ "gym": 1,
+ "weight_unit": "kg"
}
},
{
@@ -610,7 +614,8 @@
"notification_language": 2,
"timer_active": true,
"timer_pause": 90,
- "gym": 1
+ "gym": 1,
+ "weight_unit": "kg"
}
},
{
@@ -638,7 +643,8 @@
"notification_language": 2,
"timer_active": true,
"timer_pause": 90,
- "gym": 1
+ "gym": 1,
+ "weight_unit": "kg"
}
},
{
@@ -666,7 +672,8 @@
"notification_language": 2,
"timer_active": true,
"timer_pause": 90,
- "gym": 2
+ "gym": 2,
+ "weight_unit": "lb"
}
},
{
@@ -694,7 +701,8 @@
"notification_language": 2,
"timer_active": true,
"timer_pause": 90,
- "gym": 2
+ "gym": 2,
+ "weight_unit": "lb"
}
},
{
@@ -722,7 +730,8 @@
"notification_language": 2,
"timer_active": true,
"timer_pause": 90,
- "gym": 1
+ "gym": 1,
+ "weight_unit": "kg"
}
},
{
@@ -750,7 +759,8 @@
"notification_language": 2,
"timer_active": true,
"timer_pause": 90,
- "gym": 1
+ "gym": 1,
+ "weight_unit": "kg"
}
},
{
@@ -778,7 +788,8 @@
"notification_language": 2,
"timer_active": true,
"timer_pause": 90,
- "gym": 2
+ "gym": 2,
+ "weight_unit": "lb"
}
},
{
@@ -806,7 +817,8 @@
"notification_language": 2,
"timer_active": true,
"timer_pause": 90,
- "gym": 1
+ "gym": 1,
+ "weight_unit": "kg"
}
},
{
@@ -834,7 +846,8 @@
"notification_language": 2,
"timer_active": true,
"timer_pause": 90,
- "gym": 2
+ "gym": 2,
+ "weight_unit": "lb"
}
},
{
@@ -862,7 +875,8 @@
"notification_language": 1,
"calories": 3500,
"sport_hours": 6,
- "is_temporary": false
+ "is_temporary": false,
+ "weight_unit": "kg"
}
},
{
@@ -890,7 +904,8 @@
"notification_language": 1,
"calories": 3500,
"sport_hours": 6,
- "is_temporary": false
+ "is_temporary": false,
+ "weight_unit": "kg"
}
},
{
@@ -918,7 +933,8 @@
"notification_language": 1,
"calories": 3500,
"sport_hours": 6,
- "is_temporary": false
+ "is_temporary": false,
+ "weight_unit": "kg"
}
},
{
@@ -946,7 +962,8 @@
"notification_language": 1,
"calories": 3500,
"sport_hours": 6,
- "is_temporary": false
+ "is_temporary": false,
+ "weight_unit": "kg"
}
},
{
@@ -974,7 +991,8 @@
"notification_language": 1,
"calories": 3500,
"sport_hours": 6,
- "is_temporary": false
+ "is_temporary": false,
+ "weight_unit": "kg"
}
},
{
@@ -1002,7 +1020,8 @@
"notification_language": 1,
"calories": 3500,
"sport_hours": 6,
- "is_temporary": false
+ "is_temporary": false,
+ "weight_unit": "lb"
}
},
{
@@ -1030,7 +1049,8 @@
"notification_language": 1,
"calories": 3500,
"sport_hours": 6,
- "is_temporary": false
+ "is_temporary": false,
+ "weight_unit": "lb"
}
},
{
@@ -1058,7 +1078,8 @@
"notification_language": 1,
"calories": 3500,
"sport_hours": 6,
- "is_temporary": false
+ "is_temporary": false,
+ "weight_unit": "kg"
}
},
{
@@ -1086,7 +1107,8 @@
"notification_language": 1,
"calories": 3500,
"sport_hours": 6,
- "is_temporary": false
+ "is_temporary": false,
+ "weight_unit": "kg"
}
},
{
@@ -1114,7 +1136,8 @@
"notification_language": 1,
"calories": 3500,
"sport_hours": 6,
- "is_temporary": false
+ "is_temporary": false,
+ "weight_unit": "kg"
}
},
{
@@ -1142,7 +1165,8 @@
"notification_language": 1,
"calories": 3500,
"sport_hours": 6,
- "is_temporary": false
+ "is_temporary": false,
+ "weight_unit": "kg"
}
}
]