Self hosted FLOSS fitness/workout, nutrition and weight tracker
Also allow to set the language for ingredients
Roland Geider8ecfa78bcbde
diff --git a/wger/nutrition/forms.py b/wger/nutrition/forms.pyindex 4c846df75..b4b5c46e3 100644--- a/wger/nutrition/forms.py+++ b/wger/nutrition/forms.py@@ -20,6 +20,7 @@ from datetime import datetime# Djangofrom django import forms+from django.forms import BooleanFieldfrom django.urls import reversefrom django.utils.translation import (gettext as _,@@ -110,7 +111,7 @@ class BmiForm(forms.ModelForm):def __init__(self, *args, **kwargs):super(BmiForm, self).__init__(*args, **kwargs)- if 'initial' in kwargs: #if the form is rendering for the first time+ if 'initial' in kwargs: # if the form is rendering for the first timeself['height'].label = _('Height (cm)') if kwargs['initial']['use_metric'] else _('Height (in)')self['weight'].label = _('Weight (kg)'@@ -233,13 +234,30 @@ class MealItemForm(forms.ModelForm):empty_label="g",required=False,)- ingredient = forms.ModelChoiceField(queryset=Ingredient.objects.all(), widget=forms.HiddenInput)+ ingredient = forms.ModelChoiceField(+ queryset=Ingredient.objects.all(),+ widget=forms.HiddenInput,+ )++ ingredient_searchfield = forms.CharField(+ required=False,+ label=gettext_lazy("Ingredient"),+ )- ingredient_searchfield = forms.CharField(required=False, label=gettext_lazy("Ingredient"))+ english_results = BooleanField(+ label=gettext_lazy("Also search for names in English"),+ initial=True,+ required=False,+ )class Meta:model = MealItem- fields = ['ingredient', 'weight_unit', 'amount']+ fields = [+ 'ingredient',+ 'english_results',+ 'weight_unit',+ 'amount',+ ]def __init__(self, *args, **kwargs):super(MealItemForm, self).__init__(*args, **kwargs)@@ -260,7 +278,8 @@ class MealItemForm(forms.ModelForm):self.helper = FormHelper()self.helper.layout = Layout(- 'ingredient', 'ingredient_searchfield', HTML('<div id="ingredient_name"></div>'),+ 'ingredient', 'ingredient_searchfield', 'english_results',+ HTML('<div id="ingredient_name"></div>'),Row(Column('amount', css_class='col-6'),Column('weight_unit', css_class='col-6'),@@ -298,7 +317,7 @@ class MealLogItemForm(MealItemForm):super(MealLogItemForm, self).__init__(*args, **kwargs)self.helper.layout = Layout(- 'ingredient', 'ingredient_searchfield',+ 'ingredient', 'ingredient_searchfield', 'english_results',Row(Column('amount', css_class='col-6'),Column('weight_unit', css_class='col-6'),diff --git a/wger/nutrition/static/js/nutrition.js b/wger/nutrition/static/js/nutrition.jsindex 9eb222f14..284aa50be 100644--- a/wger/nutrition/static/js/nutrition.js+++ b/wger/nutrition/static/js/nutrition.js@@ -65,7 +65,9 @@ function wgerInitIngredientDetail(url) {function wgerInitIngredientAutocompleter() {// Init the autocompleter$('#id_ingredient_searchfield').autocomplete({- serviceUrl: '/api/v2/ingredient/search/',+ serviceUrl: function () {+ return '/api/v2/ingredient/search/?language=' + getSearchLanguages()+ },paramName: 'term',minChars: 3,onSelect: function (suggestion) {@@ -117,8 +119,10 @@ function wgerDrawNutritionDiaryChart(planPk) {x_accessor: 'date',decimals: 0,full_width: true,- baselines: [{ value: nutritionalValues.total.energy,- label: 'Planned (' + nutritionalValues.total.energy + 'kcal)' }],+ baselines: [{+ value: nutritionalValues.total.energy,+ label: 'Planned (' + nutritionalValues.total.energy + 'kcal)'+ }],target: '#nutrition_diary_chart',colors: '#307916'});@@ -154,7 +158,7 @@ function wgerRenderBodyMassIndex() {heightFactor = (widthFactor / 600) * 300;- margin = { top: 20, right: 80, bottom: 30, left: 50 };+ margin = {top: 20, right: 80, bottom: 30, left: 50};width = widthFactor - margin.left - margin.right;height = heightFactor - margin.top - margin.bottom;@@ -294,7 +298,7 @@ function wgerInitCaloriesCalculator() {$.ajax({url: '/api/v2/userprofile/' + userprofile.results[0].user + '/',type: 'PATCH',- data: { calories: totalCalories }+ data: {calories: totalCalories}});});});