Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Crispify ingredient calories calculator

Roland Geidere2484d010951
diff --git a/wger/nutrition/forms.py b/wger/nutrition/forms.py
index 3f9744395..1f4568cec 100644
--- a/wger/nutrition/forms.py
+++ b/wger/nutrition/forms.py
@@ -19,7 +19,18 @@ import logging
# Django
from django import forms
-from django.utils.translation import ugettext as _
+from django.utils.translation import (
+ ugettext as _,
+ ugettext_lazy
+)
+
+# Third Party
+from crispy_forms.helper import FormHelper
+from crispy_forms.layout import (
+ Column,
+ Layout,
+ Row
+)
# wger
from wger.core.models import UserProfile
@@ -39,9 +50,11 @@ class UnitChooserForm(forms.Form):
A small form to select an amount and a unit for an ingredient
'''
amount = forms.DecimalField(decimal_places=2,
+ label=ugettext_lazy("Amount"),
max_digits=5,
localize=True)
unit = forms.ModelChoiceField(queryset=IngredientWeightUnit.objects.none(),
+ label=ugettext_lazy("Unit"),
empty_label="g",
required=False)
@@ -60,6 +73,16 @@ class UnitChooserForm(forms.Form):
self.fields['unit'].queryset = IngredientWeightUnit.objects.filter(
ingredient_id=ingredient_id).select_related()
+ self.helper = FormHelper()
+ self.helper.layout = Layout(
+ Row(
+ Column('amount', css_class='form-group col-6 mb-0'),
+ Column('unit', css_class='form-group col-6 mb-0'),
+ css_class='form-row'
+ )
+ )
+ self.helper.form_tag = False
+
class BmiForm(forms.ModelForm):
height = forms.DecimalField(widget=Html5NumberInput(),
diff --git a/wger/nutrition/templates/ingredient/view.html b/wger/nutrition/templates/ingredient/view.html
index 18686c788..5d5bb4b40 100644
--- a/wger/nutrition/templates/ingredient/view.html
+++ b/wger/nutrition/templates/ingredient/view.html
@@ -1,5 +1,5 @@
{% extends "base.html" %}
-{% load i18n static wger_extras django_bootstrap_breadcrumbs %}
+{% load i18n static wger_extras django_bootstrap_breadcrumbs crispy_forms_tags %}
{% block title %}{{ingredient.name}}{% endblock %}
@@ -61,19 +61,7 @@ the search.{% endblocktrans %}
<div id="calculator-errors"></div>
<input type="hidden" value="{{ingredient.id}}" name="ingredient">
- <div class="row">
- <div class="col-md-4" style="text-align:right;">
- {% trans 'Nutritional values in' %}
- </div>
-
- <div class="col-md-4">
- <div>{{form.amount|form_field_add_css:'form-control'}}</div>
- </div>
-
- <div class="col-md-4">
- <div>{{form.unit|form_field_add_css:'form-control'}}</div>
- </div>
- </div>
+ {% crispy form %}
</form>
<table class="table">