Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Fix some small issues, improve the display of units in drop downs

Roland Geider62ef9a00c843
diff --git a/wger/manager/static/js/workout-manager.js b/wger/manager/static/js/workout-manager.js
index 90b0992da..7397c7dfe 100644
--- a/wger/manager/static/js/workout-manager.js
+++ b/wger/manager/static/js/workout-manager.js
@@ -377,10 +377,20 @@ function init_ingredient_autocompleter()
// See if the ingredient has any units and set the values for the forms
$.get('/' + get_current_language() + '/nutrition/ingredient/' + ui.item.id + '/get-units',
function(data){
+
+ // Remove any old units, if any
+ options = $('#id_weight_unit').find('option');
+ $.each(options, function(index, option_obj) {
+ if (option_obj.value != '')
+ {
+ $(option_obj).remove();
+ }
+ });
+
+ // Add new units, if any
$.each(data, function(index, value) {
- $('#id_unit').append(new Option(value.name, value.id));
- $('#id_weight_unit').append(new Option(value.name, value.id));
- //console.log(index + ': ' + value.name);
+ $('#id_unit').append(new Option(value.name, value.id));
+ $('#id_weight_unit').append(new Option(value.name_model, value.id));
});
});
}
diff --git a/wger/nutrition/models.py b/wger/nutrition/models.py
index 5acdc987f..e80496b34 100644
--- a/wger/nutrition/models.py
+++ b/wger/nutrition/models.py
@@ -234,10 +234,9 @@ class IngredientWeightUnit(models.Model):
Return a more human-readable representation
'''
- return u"{0}: {1}{2} á {3}g".format(self.ingredient.name,
- self.amount,
- self.unit.name,
- self.gramm)
+ return u"{0}{1} ({2}g)".format(self.amount if self.amount > 1 else '',
+ self.unit.name,
+ self.gramm)
class Meal(models.Model):
diff --git a/wger/nutrition/views/ingredient.py b/wger/nutrition/views/ingredient.py
index e1dfe4dc8..7e1fe305c 100644
--- a/wger/nutrition/views/ingredient.py
+++ b/wger/nutrition/views/ingredient.py
@@ -322,7 +322,10 @@ def ajax_get_ingredient_units(request, pk):
units = IngredientWeightUnit.objects.filter(ingredient_id=pk)
result = []
for unit in units:
- result.append({'id': unit.id, 'name': unit.unit.name, 'amount': unit.amount})
+ result.append({'id': unit.id,
+ 'name': unit.unit.name,
+ 'amount': unit.amount,
+ 'name_model': unicode(unit)})
return HttpResponse(json.dumps(result, cls=helpers.DecimalJsonEncoder),
'application/json')
diff --git a/wger/nutrition/views/plan.py b/wger/nutrition/views/plan.py
index 92bfe988f..5590d4958 100644
--- a/wger/nutrition/views/plan.py
+++ b/wger/nutrition/views/plan.py
@@ -238,7 +238,7 @@ def export_pdf(request, id):
P = Paragraph('<para>%s</para>' % item.ingredient.name,
styleSheet["Normal"])
- if item.weight_type == MEALITEM_WEIGHT_GRAM:
+ if item.get_unit_type() == MEALITEM_WEIGHT_GRAM:
unit_name = 'g'
else:
unit_name = ' ' + item.weight_unit.unit.name