Self hosted FLOSS fitness/workout, nutrition and weight tracker
Show last diary entries in nutrition page view
Roland Geiderf38663b2dae5
diff --git a/wger/nutrition/templates/plan/view.html b/wger/nutrition/templates/plan/view.htmlindex 9d3022987..be6687e96 100644--- a/wger/nutrition/templates/plan/view.html+++ b/wger/nutrition/templates/plan/view.html@@ -184,6 +184,8 @@ function custom_modal_init()</p>{% endif %}++<h4>{% trans "Nutritional data" %}</h4>{% if weight_entry %}{% blocktrans with date=weight_entry.date weight=weight_entry.weight %}@@ -261,6 +263,46 @@ function custom_modal_init()</tr></tbody></table>+++<h4>{% trans "Nutrition diary" %}</h4>+<table class="table table-condensed">+ <thead>+ <tr>+ <th>{% trans "Date" %}</th>+ <th class="align-right">{% trans "Planned" %}</th>+ <th class="align-right">{% trans "Logged" %}</th>+ <th class="align-right">{% trans "Difference" %}</th>+ </tr>+ </thead>+ <tbody>+ {% for entry in log_data %}+ <tr>+ <td>+ <a href="{% url 'nutrition:log:detail' plan.pk entry.date.year entry.date.month entry.date.day %}">+ {{ entry.date|date }}+ </a>+ </td>+ <td class="align-right">+ {{ entry.planned_calories|floatformat }} {% trans "kcal" %}+ </td>+ <td class="align-right">+ {{ entry.logged_calories }} {% trans "kcal" %}+ </td>+ <td class="align-right">+ {{ entry.difference }}+ </td>+ </tr>+ {% empty %}+ <tr>+ <td colspan="4">+ <em>{% trans "nothing found" %}</em>+ </td>+ </tr>+ {% endfor %}+ </tbody>+</table>+<a href="{% url 'nutrition:log:overview' plan.pk %}">{% trans "View details" %}</a>{% endblock %}@@ -268,7 +310,6 @@ function custom_modal_init(){# Side bar #}{# #}{% block sidebar %}-<a href="{% url 'nutrition:log:overview' plan.pk %}">{% trans "Nutrition diary" %}</a><h4>{% trans "Energy" %}</h4><table class="table table-condensed" id="nutritional-data-energy">diff --git a/wger/nutrition/views/plan.py b/wger/nutrition/views/plan.pyindex 24f41a703..6e10c93ba 100644--- a/wger/nutrition/views/plan.py+++ b/wger/nutrition/views/plan.py@@ -136,6 +136,17 @@ def view(request, id):uid, token = make_token(user)+ # Process and show the last 5 diary entries+ log_data = []+ planned_calories = plan.get_nutritional_values()['total']['energy']+ for date, items in plan.get_log_overview().items():+ if len(log_data) == 5:+ break+ log_data.append({'date': date,+ 'planned_calories': planned_calories,+ 'logged_calories': items['energy'],+ 'difference': items['energy'] - planned_calories})+# Load the language and pass it to the templatelanguage = load_language()template_data['language'] = language@@ -152,6 +163,7 @@ def view(request, id):# Tokens for the linkstemplate_data['uid'] = uid+ template_data['log_data'] = log_datatemplate_data['token'] = tokentemplate_data['owner_user'] = usertemplate_data['is_owner'] = is_owner