Self hosted FLOSS fitness/workout, nutrition and weight tracker
Start removing unneeded code and templates
Roland Geider91b4fef45023
diff --git a/wger/nutrition/templates/log/detail.html b/wger/nutrition/templates/log/detail.htmldeleted file mode 100644index dc9b7788b..000000000--- a/wger/nutrition/templates/log/detail.html+++ /dev/null@@ -1,215 +0,0 @@-{% extends "base.html" %}-{% load i18n static wger_extras django_bootstrap_breadcrumbs %}--{# #}-{# Title #}-{# #}-{% block title %}{% translate "Nutrition diary" %} - {{ date }}{% endblock %}----{# #}-{# Breadcrumbs #}-{# #}-{% block breadcrumbs %}- {{ block.super }}-- {% breadcrumb "Nutrition plans" "nutrition:plan:overview" %}- {% breadcrumb plan plan.get_absolute_url %}- {% breadcrumb "Nutrition diary" "nutrition:log:overview" plan.pk %}- {% breadcrumb date|date "nutrition:log:detail" plan.pk date.year date.month date.day %}-{% endblock %}---{# #}-{# Content #}-{# #}-{% block content %}- <table class="table table-condensed">- <thead>- <tr>- <th>{% translate "Macronutrients" %}</th>- <th class="align-right">{% translate "Planned" %}</th>- <th class="align-right">{% translate "Logged" %}</th>- <th class="align-right">{% translate "Difference" %}</th>- </tr>- </thead>- <tbody>- <tr>- <td>{% translate "Energy" %}</td>- <td class="align-right">{{ nutritional_data.total.energy|floatformat:0 }} {% translate "kcal" %}</td>- <td class="align-right">{{ log_summary.energy|floatformat:0 }} {% translate "kcal" %}</td>- <td class="align-right">- {% with diff=nutritional_data.total.energy|minus:log_summary.energy %}- {% if diff|is_positive %}- +- {% endif %}- {{ diff|floatformat:0 }}- {% endwith %}- </td>- </tr>- <tr>- <td>{% translate "Protein" %}</td>- <td class="align-right">{{ nutritional_data.total.protein|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">{{ log_summary.protein|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">- {% with diff=nutritional_data.total.protein|minus:log_summary.protein %}- {% if diff|is_positive %}- +- {% endif %}- {{ diff|floatformat:0 }}- {% endwith %}- </td>- </tr>- <tr>- <td>{% translate "Carbohydrates" %}</td>- <td class="align-right">{{ nutritional_data.total.carbohydrates|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">{{ log_summary.carbohydrates|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">- {% with diff=nutritional_data.total.carbohydrates|minus:log_summary.carbohydrates %}- {% if diff|is_positive %}- +- {% endif %}- {{ diff|floatformat:0 }}- {% endwith %}- </td>- </tr>- <tr>- <td class="pl-4">{% translate "Sugar content in carbohydrates" %}</td>- <td class="align-right">{{ nutritional_data.total.carbohydrates_sugar|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">{{ log_summary.carbohydrates_sugar|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">- {% with diff=nutritional_data.total.carbohydrates_sugar|minus:log_summary.carbohydrates_sugar %}- {% if diff|is_positive %}- +- {% endif %}- {{ diff|floatformat:0 }}- {% endwith %}- </td>- </tr>- <tr>- <td>{% translate "Fat" %}</td>- <td class="align-right">{{ nutritional_data.total.fat|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">{{ log_summary.fat|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">- {% with diff=nutritional_data.total.fat|minus:log_summary.fat %}- {% if diff|is_positive %}- +- {% endif %}- {{ diff|floatformat:0 }}- {% endwith %}- </td>- </tr>- <tr>- <td class="pl-4">{% translate "Saturated fat content in fats" %}</td>- <td class="align-right">{{ nutritional_data.total.fat_saturated|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">{{ log_summary.fat_saturated|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">- {% with diff=nutritional_data.total.fat_saturated|minus:log_summary.fat_saturated %}- {% if diff|is_positive %}- +- {% endif %}- {{ diff|floatformat:0 }}- {% endwith %}- </td>- </tr>--- <tr>- <th colspan="4">{% translate "Others" %}</th>- </tr>- <tr>- <td>{% translate "Fibres" %}</td>- <td class="align-right">{{ nutritional_data.total.fibres|floatformat }} {% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">{{ log_summary.fibres|floatformat }} {% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">- {% with diff=nutritional_data.total.fibres|minus:log_summary.fibres %}- {% if diff|is_positive %}- +- {% endif %}- {{ diff|floatformat:0 }}- {% endwith %}- </td>- </tr>- <tr>- <td>{% translate "Sodium" %}</td>- <td class="align-right">{{ nutritional_data.total.sodium|floatformat }} {% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">{{ log_summary.sodium|floatformat }} {% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">- {% with diff=nutritional_data.total.sodium|minus:log_summary.sodium %}- {% if diff|is_positive %}- +- {% endif %}- {{ diff|floatformat:0 }}- {% endwith %}- </td>- </tr>- </tbody>-</table>--<h3>{% translate "Entries" %}</h3>-<table class="table table-condensed">- <thead>- <tr>- <th>{% translate "Time" %}</th>- <th>{% translate "Ingredient" %}</th>- <th class="align-right">{% translate "Energy" %}</th>- {% if is_owner %}- <th></th>- {% endif %}- </tr>- </thead>- <tbody>-{% for entry in log_entries %}- <tr>- <td>{{ entry.datetime|time }}</td>- <td>- {% if entry.weight_unit %}- {{ entry.amount|floatformat:"0" }} × {{ entry.weight_unit.unit.name }}- {% else %}- {{ entry.amount|floatformat:"0" }}{% translate "g" %}- {% endif %}- {{ entry.ingredient }}- <p class="small text-muted">- {% translate "Protein" %}: {{entry.get_nutritional_values.protein|floatformat:"1"}} <br>- {% translate "Carbohydrates" %}: {{entry.get_nutritional_values.carbohydrates|floatformat:"1"}} ({{entry.get_nutritional_values.carbohydrates_sugar|floatformat:"1"}})<br>- {% translate "Fat" %}: {{entry.get_nutritional_values.fat|floatformat:"1"}} ({{entry.get_nutritional_values.fat|floatformat:"1"}})<br>- {% if entry.get_nutritional_values.fibres %}- {% translate "Fibres" %}: {{entry.get_nutritional_values.fibres|floatformat:"1"}}<br>- {% endif %}- {% if entry.get_nutritional_values.sodium %}- {% translate "Sodium" %}: {{entry.get_nutritional_values.sodium|floatformat:"1"}}<br>- {% endif %}- </p>- </td>-- <td class="align-right">- {{ entry.get_nutritional_values.energy|floatformat:0 }} {% translate "kcal" %}- </td>- {% if is_owner %}- <td>- <div class="dropdown">- <button type="button" class="btn btn-default dropdown-toggle btn-xs" data-bs-toggle="dropdown">- </button>- <ul class="dropdown-menu dropdown-menu-right" role="menu">- <li>- <a href="{% url 'nutrition:log:delete' entry.pk %}" class="wger-modal-dialog dropdown-item">- {% translate 'Delete' %}- </a>- </li>- </ul>- </div>- </td>- {% endif %}- </tr>-{% endfor %}- </tbody>-</table>-{% endblock %}---{# #}-{# Side bar #}-{# #}-{% block sidebar%}-{% endblock %}diff --git a/wger/nutrition/templates/log/overview.html b/wger/nutrition/templates/log/overview.htmldeleted file mode 100644index 4aab92c3e..000000000--- a/wger/nutrition/templates/log/overview.html+++ /dev/null@@ -1,66 +0,0 @@-{% extends "base.html" %}-{% load i18n static wger_extras django_bootstrap_breadcrumbs %}--{# #}-{# Title #}-{# #}-{% block title %}{% translate "Nutrition diary" %} - {{ log_data.0.planned_calories|floatformat:0 }} {% translate "kcal" %}{% endblock %}----{# #}-{# Breadcrumbs #}-{# #}-{% block breadcrumbs %}- {{ block.super }}-- {% breadcrumb "Nutrition plans" "nutrition:plan:overview" %}- {% breadcrumb plan plan.get_absolute_url %}- {% breadcrumb "Nutrition diary" "nutrition:log:overview" plan.pk %}-{% endblock %}---{# #}-{# Content #}-{# #}-{% block content %}-<table class="table table-condensed">- <thead>- <tr>- <th>{% translate "Date" %}</th>- <th class="align-right">{% translate "Logged" %}</th>- <th class="align-right">{% translate "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.logged_calories|floatformat:0 }} {% translate "kcal" %}- </td>- <td class="align-right">- {{ entry.difference|floatformat:0 }}- </td>- </tr>- {% empty %}- <tr>- <td colspan="4">- <em>{% translate "nothing found" %}</em>- </td>- </tr>- {% endfor %}- </tbody>-</table>-{% endblock %}---{# #}-{# Side bar #}-{# #}-{% block sidebar%}-{% endblock %}diff --git a/wger/nutrition/templates/plan/overview.html b/wger/nutrition/templates/plan/overview.htmldeleted file mode 100644index 96c5cb08c..000000000--- a/wger/nutrition/templates/plan/overview.html+++ /dev/null@@ -1,38 +0,0 @@-{% extends "base.html" %}-{% load i18n %}-{% load static %}--{% block title %}{% translate "Your nutrition plans" %}{% endblock %}---{% block content %}- <div class="list-group">- {% for plan in plans %}- <a href="{{ plan.get_absolute_url }}" class="list-group-item list-group-item-action">- <span class="glyphicon glyphicon-chevron-right float-end"></span>-- <p class="list-group-item-heading h5">{{ plan }}</p>- <p class="list-group-item-text">- {{ plan.creation_date }} –- {{ plan.get_nutritional_values.total.energy|floatformat }} {% translate "kcal" %}- </p>- </a>- {% empty %}- <a href="{% url 'nutrition:plan:add' %}" class="list-group-item list-group-item-action">- {% translate "No nutrition plans." %}<br>- {% translate "Add one now." %}- </a>- {% endfor %}- </div>-{% endblock %}----{# #}-{# Options #}-{# #}-{% block options %}- <a href="{% url 'nutrition:plan:add' %}" class="btn btn-success btn-sm">- {% translate "Add nutrition plan" %}- </a>-{% endblock %}diff --git a/wger/nutrition/templates/plan/view.html b/wger/nutrition/templates/plan/view.htmldeleted file mode 100644index 357c6e61e..000000000--- a/wger/nutrition/templates/plan/view.html+++ /dev/null@@ -1,441 +0,0 @@-{% extends "base.html" %}-{% load i18n %}-{% load static %}-{% load wger_extras %}--{# #}-{# Opengraph #}-{# #}-{% block opengraph %}- {{ block.super }}- <meta property="og:title" content="{% translate 'Nutrition plan' %}">- <meta property="og:description" content="{{ plan }} / {{ owner_user.username }}">-{% endblock %}---{# #}-{# Title #}-{# #}-{% block title %}{% translate "Nutrition plan" %}{% endblock %}---{# #}-{# Header #}-{# #}-{% block header %}- <script>- $(document).ready(function () {- wgerDrawNutritionDiaryChart({{ plan.pk }});- });-- function wgerCustomModalInit() {- // Init the autocompleter after loading the modal dialog- wgerInitIngredientAutocompleter();- }- </script>-{% endblock %}----{# #}-{# Content #}-{# #}-{% block content %}- {% if plan.description %}- <h4>{{ plan.description }}</h4>- {% endif %}-- <div class="table-responsive">- <table class="table table-bordered">- <thead>- <tr style="background: #E0E0E0;">- <th>{% translate "Contents" %}</th>- <th class="align-right">{% translate "Energy" %}</th>- <th class="align-right">{% translate "Protein" %}</th>- <th class="align-right">{% translate "Carbohydrates" %}</th>- <th class="align-right">{% translate "Fat" %}</th>- </tr>- </thead>- <tbody>- <tr>- <td colspan="1"></td>- <td class="align-right">{% translate 'kcal' %} / {% translate 'kJ' %}</td>- <td class="align-right">{% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">{% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">{% trans_weight_unit 'g' owner_user %}</td>- </tr>- {% for meal in plan.meal_set.select_related %}- <tr>- <td colspan="6">- {% if is_owner %}- <div class="dropdown float-end">- <button type="button"- class="btn btn-link btn-block dropdown-toggle btn-xs"- data-bs-toggle="dropdown"></button>- <div class="dropdown-menu dropdown-menu-right" role="menu">- <a href="{% url 'nutrition:log:log_meal' meal.id %}"- class="dropdown-item">- <span class="{% fa_class 'chart-line' %}"></span>- {% translate 'Log this meal' %}- </a>- <a href="{% url 'nutrition:meal_item:add' meal.id %}"- class="wger-modal-dialog edit-meal dropdown-item">- <span class="{% fa_class 'plus' %}"></span>- {% translate 'Add ingredient to meal' %}- </a>- <a href="{% url 'nutrition:meal:edit' meal.id %}"- class="wger-modal-dialog dropdown-item">- <span class="{% fa_class 'edit' %}"></span>- {% translate 'Edit' %}- </a>- <div class="dropdown-divider"></div>- <a href="{% url 'nutrition:meal:delete' meal.id %}"- class="dropdown-item">- <span class="{% fa_class 'trash' %}"></span>- {% translate 'Delete' %}- </a>- </div>- </div>- {% endif %}-- <h4>{% if meal.name %}{{ meal.name }}{% endif %}</h4>- <h5>{% if meal.time %}{{ meal.time|time:"H:i" }}{% endif %}</h5>-- </td>- </tr>- <tr>-- {% for item in meal.mealitem_set.select_related %}- <td>- {% if item.ingredient.image %}- <a href="{{ item.ingredient.off_link }}"><img src="{{ item.ingredient.image.image.url }}" class="img-thumbnail rounded" width="48"></a>- {% endif %}- {% if item.get_unit_type == MEALITEM_WEIGHT_GRAM %}- {{ item.amount|floatformat:"0" }}g- {% else %}- {{ item.amount|floatformat:"0" }} × {{ item.weight_unit.unit.name }}- {% endif %}- {{ item.ingredient.name }}-- {% if is_owner %}- <div class="dropdown float-end">- <button type="button"- class="btn btn-link dropdown-toggle btn-xs"- data-bs-toggle="dropdown"></button>- <div class="dropdown-menu dropdown-menu-right" role="menu">- <a href="{% url 'nutrition:meal_item:edit' item.id %}"- class="wger-modal-dialog edit-meal edit-mealitem dropdown-item">- <span class="{% fa_class 'edit' %}"></span>- {% translate 'Edit' %}- </a>- <div class="dropdown-divider"></div>- <a href="{% url 'nutrition:meal_item:delete' item.id %}"- class="delete-mealitem dropdown-item">- <span class="{% fa_class 'trash' %}"></span>- {% translate 'Delete' %}- </a>- </div>- </div>- <span class="editoptions float-end"></span>- {% endif %}- </td>- <td class="align-right">{{ item.get_nutritional_values.energy|floatformat:1 }}- /- {{ item.get_nutritional_values.energy_kilojoule|floatformat:1 }}</td>- <td class="align-right">{{ item.get_nutritional_values.protein|floatformat:1 }}</td>- <td class="align-right">{{ item.get_nutritional_values.carbohydrates|floatformat:1 }}</td>- <td class="align-right">{{ item.get_nutritional_values.fat|floatformat:1 }}</td>- </tr>- {% empty %}- {% if is_owner %}- <td colspan="6">- <a href="{% url 'nutrition:meal_item:add' meal.id %}"- title="{% translate 'Add one now.' %}"- class="wger-modal-dialog edit-meal btn btn-link btn-block">- {% translate "No items for this meal." %}- {% translate "Add one now." %}- </a>- </td>- {% endif %}- {% endfor %}-- <tr>- <td class="align-right">Σ</td>- <td class="align-right">- <span class="text-muted">- {{ meal.get_nutritional_values.energy|floatformat:1 }} /- {{ meal.get_nutritional_values.energy_kilojoule|floatformat:1 }}- </span>- </td>-- <td class="align-right">- <span class="text-muted">- {{ meal.get_nutritional_values.protein|floatformat:1 }}- </span>- </td>- <td class="align-right">- <span class="text-muted">- {{ meal.get_nutritional_values.carbohydrates|floatformat:1 }}- </span>- </td>- <td class="align-right">- <span class="text-muted">- {{ meal.get_nutritional_values.fat|floatformat:1 }}- </span>- </td>- </tr>- {% empty %}- {% if is_owner %}- <tr>- <td colspan="6">- <a href="{% url 'nutrition:meal:add' plan.id %}"- class="wger-modal-dialog btn btn-link btn-block">- {% translate "No meals for this plan." %}- {% translate "Add one now." %}- </a>- </td>- </tr>- {% endif %}- {% endfor %}- {% if is_owner %}- <tr>- <td colspan="6" class="py-0"><a- href="{% url 'nutrition:log:log_plan' plan.id %}"- class="btn btn-link btn-block">- {% translate "Log this Plan" %}</a></td>- </tr>- <tr>- <td colspan="6" class="py-0">- <a href="{% url 'nutrition:meal:add' plan.id %}"- class="wger-modal-dialog btn btn-link btn-block">- {% translate "Add a new meal" %}- </a>- </td>- <tr>- {% endif %}- </tbody>- </table>- </div>--- <h4>{% translate "Nutritional data" %}</h4>- {% if weight_entry %}- <h6>- {% blocktranslate with date=weight_entry.date weight=weight_entry.weight trimmed %}- Based on the weight entry dated {{ date }} ({{ weight }})- {% endblocktranslate %}- </h6>- {% endif %}- <table class="table table-sm">- <thead>- <tr>- <th>{% translate "Macronutrients" %}</th>- <th class="align-right">{% translate "Total" %}</th>- <th class="align-right">{% translate "Percent of energy" %}</th>- <th class="align-right">- {% if owner_user.userprofile.use_metric %}- {% translate "g per body kg" %}- {% else %}- {% translate "oz per body lb" %}- {% endif %}- </th>- </tr>- </thead>- <tbody>- <tr>- <td>{% translate "Energy" %}</td>- <td class="align-right">{{ nutritional_data.total.energy|floatformat:0 }} {% translate "kcal" %}- /- {{ nutritional_data.total.energy_kilojoule|floatformat:0 }} {% translate "kJ" %}</td>- <td></td>- <td></td>- </tr>- <tr>- <td>{% translate "Protein" %}</td>- <td class="align-right">{{ nutritional_data.total.protein|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">{{ nutritional_data.percent.protein|floatformat:1 }} %</td>- <td class="align-right">{{ nutritional_data.per_kg.protein|floatformat:2 }}</td>- </tr>- <tr>- <td>{% translate "Carbohydrates" %}</td>- <td class="align-right">{{ nutritional_data.total.carbohydrates|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">{{ nutritional_data.percent.carbohydrates|floatformat:1 }} %- </td>- <td class="align-right">{{ nutritional_data.per_kg.carbohydrates|floatformat:2 }}</td>- </tr>- <tr>- <td class="pl-4">{% translate "Sugar content in carbohydrates" %}</td>- <td class="align-right">{{ nutritional_data.total.carbohydrates_sugar|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>- <td></td>- <td></td>- </tr>- <tr>- <td>{% translate "Fat" %}</td>- <td class="align-right">{{ nutritional_data.total.fat|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>- <td class="align-right">{{ nutritional_data.percent.fat|floatformat:1 }} %</td>- <td class="align-right">{{ nutritional_data.per_kg.fat|floatformat:2 }}</td>- </tr>- <tr>- <td class="pl-4">{% translate "Saturated fat content in fats" %}</td>- <td class="align-right">{{ nutritional_data.total.fat_saturated|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>- <td></td>- <td></td>- </tr>--- <tr>- <th colspan="4">{% translate "Others" %}</th>- </tr>- <tr>- <td>{% translate "Fibres" %}</td>- <td class="align-right">{{ nutritional_data.total.fibres|floatformat }} {% trans_weight_unit 'g' owner_user %}</td>- <td></td>- <td></td>- </tr>- <tr>- <td>{% translate "Sodium" %}</td>- <td class="align-right">{{ nutritional_data.total.sodium|floatformat }} {% trans_weight_unit 'g' owner_user %}</td>- <td></td>- <td></td>- </tr>- </tbody>- </table>--- <h4>{% translate "Nutrition diary" %} -- {{ nutritional_data.total.energy|floatformat:0 }}{% translate "kcal" %}</h4>- <div id="nutrition_diary_chart"></div>-- <table class="table table-condensed">- <thead>- <tr>- <th>{% translate "Date" %}</th>- <th class="align-right">{% translate "Logged" %}</th>- <th class="align-right">{% translate "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.logged_calories|floatformat:0 }} {% translate "kcal" %}- </td>- <td class="align-right">- {{ entry.difference|floatformat:0 }}- </td>- </tr>- {% empty %}- <tr>- <td colspan="4">- <em>{% translate "nothing found" %}</em>- </td>- </tr>- {% endfor %}- {% if log_data %}- <tr>- <td colspan="4">- <a href="{% url 'nutrition:log:overview' plan.pk %}"- class="btn btn-link btn-block">{% translate "View complete nutrition log" %}</a>- </td>- </tr>- {% endif %}- </tbody>- </table>-- {% if is_owner %}- <p>- <a href="{% url 'nutrition:log:add' plan.pk %}"- class="btn btn-success btn-sm wger-modal-dialog">{% translate "Add custom diary entry" %}</a>- </p>- {% endif %}-{% endblock %}---{# #}-{# Side bar #}-{# #}-{% block sidebar %}- <h4>{% translate "Energy" %}</h4>- <table class="table table-sm" id="nutritional-data-energy">- <thead>- <tr>- <th>{% translate "Energy" %}</th>- <th class="align-right">{{ nutritional_data.total.energy|floatformat:0 }} {% translate "kcal" %}</th>- </tr>- </thead>- <tbody>-- {% if is_owner and owner_user.userprofile.calories and plan.has_goal_calories %}- {% with total=plan.get_calories_approximation %}- <tr class="table-{% if total == 1 %}default{% elif total == 2 %}success{% elif total == 3 %}warning{% elif total > 3 %}danger{% endif %}">- <td>{% translate "Goal" %}</td>- <td class="align-right">- <strong>{{ owner_user.userprofile.calories }} {% translate "kcal" %}</strong>- </td>- </tr>- {% endwith %}- {% endif %}- </tbody>- </table>-- {% if is_owner and plan.has_goal_calories %}- <p>{% blocktranslate %}You have selected that this nutritional plan has a- goal amount of calories. Use the calculator or enter the value- yourself.{% endblocktranslate %}- <a href="{% url 'nutrition:calories:view' %}">{% translate "That's done here" %}</a>- </p>- {% endif %}--- {% if language.short_name != 'en' and is_owner %}- <p>- {% translate "If you find the ingredient list too short, you might want to activate the preference to also show English ingredients." %}- <a href="{% url 'core:user:preferences' %}"- id="ajax-english-ingredients">{% translate "That's done here" %}</a>.- </p>- {% endif %}-{% endblock %}----{# #}-{# Options #}-{# #}-{% block options %}- <div class="btn-group">- <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-bs-toggle="dropdown"- aria-haspopup="true" aria-expanded="false">- <span class="{% fa_class 'cog' %}"></span>- {% translate "Options" %}- </button>- <div class="dropdown-menu">- <a href="{% url 'nutrition:plan:export-pdf' plan.id uid token %}" target="_blank"- class="dropdown-item">- <span class="{% fa_class 'download' %}"></span>- {% translate "Download as PDF" %}- </a>- {% if is_owner %}- <a href="{% url 'nutrition:plan:edit' plan.id %}"- class="wger-modal-dialog dropdown-item">- <span class="{% fa_class 'edit' %}"></span>- {% translate "Edit nutrition plan" %}- </a>- <a href="{% url 'nutrition:plan:copy' plan.id %}" class="dropdown-item">- <span class="{% fa_class 'clone' %}"></span>- {% translate "Make a copy of this nutrition plan" %}- </a>- <div role="separator" class="divider"></div>- <a href="{% url 'nutrition:plan:delete' plan.id %}"- class="wger-modal-dialog dropdown-item">- <span class="{% fa_class 'trash' %}"></span>- {% translate "Delete nutrition plan" %}- </a>- {% endif %}- </div>- </div>-{% endblock %}diff --git a/wger/nutrition/tests/test_meal.py b/wger/nutrition/tests/test_meal.pyindex 12c283c49..bab427d62 100644--- a/wger/nutrition/tests/test_meal.py+++ b/wger/nutrition/tests/test_meal.py@@ -16,115 +16,13 @@# Standard Libraryimport datetime-# Django-from django.urls import reverse-# wgerfrom wger.core.tests import api_base_test-from wger.core.tests.base_testcase import (- WgerAddTestCase,- WgerEditTestCase,- WgerTestCase,-)from wger.nutrition.models import (Meal,- NutritionPlan,)-class MealRepresentationTestCase(WgerTestCase):- """- Test the representation of a model- """-- def test_representation(self):- """- Test that the representation of an object is correct- """- self.assertEqual("{0}".format(Meal.objects.get(pk=1)), '1 Meal')---class EditMealTestCase(WgerEditTestCase):- """- Tests editing a meal- """-- object_class = Meal- url = 'nutrition:meal:edit'- pk = 5- data = {'time': datetime.time(8, 12)}---class AddMealTestCase(WgerAddTestCase):- """- Tests adding a Meal- """-- object_class = Meal- url = reverse('nutrition:meal:add', kwargs={'plan_pk': 4})- data = {'time': datetime.time(9, 2)}- user_success = 'test'- user_fail = 'admin'---class PlanOverviewTestCase(WgerTestCase):- """- Tests the nutrition plan overview- """-- def get_plan_overview(self):- """- Helper function to test the nutrition plan overview- """-- response = self.client.get(reverse('nutrition:plan:overview'))-- # Page exists- self.assertEqual(response.status_code, 200)- self.assertEqual(len(response.context['plans']), 3)-- def test_dashboard_logged_in(self):- """- Test the nutrition plan as a logged in user- """- self.user_login()- self.get_plan_overview()---class PlanDetailTestCase(WgerTestCase):- """- Tests the nutrition plan detail view- """-- def get_plan_detail_page(self, fail=False):- """- Helper function to test the plan detail view- """-- response = self.client.get(reverse('nutrition:plan:view', kwargs={'id': 1}))-- # Page exists- if fail:- self.assertIn(response.status_code, (302, 403, 404))- else:- self.assertEqual(response.status_code, 200)- plan = NutritionPlan.objects.get(pk=1)- self.assertEqual(response.context['plan'], plan)-- def test_dashboard_owner(self):- """- Test the nutrition plan as the owner user- """- self.user_login('test')- self.get_plan_detail_page(fail=False)-- def test_dashboard_other(self):- """- Test the nutrition plan as a differnt user- """- self.user_login('admin')- self.get_plan_detail_page(fail=True)-class MealApiTestCase(api_base_test.ApiBaseResourceTestCase):"""diff --git a/wger/nutrition/tests/test_meal_item.py b/wger/nutrition/tests/test_meal_item.pyindex 980e17638..a9cfb3bc2 100644--- a/wger/nutrition/tests/test_meal_item.py+++ b/wger/nutrition/tests/test_meal_item.py@@ -13,67 +13,11 @@# You should have received a copy of the GNU Affero General Public License# along with Workout Manager. If not, see <http://www.gnu.org/licenses/>.-# Django-from django.urls import reverse-# wgerfrom wger.core.tests import api_base_test-from wger.core.tests.base_testcase import (- WgerAddTestCase,- WgerEditTestCase,-)from wger.nutrition.models import MealItem-class EditMealItemUnitTestCase(WgerEditTestCase):- """- Tests editing a meal, set the amount using a unit- """-- object_class = MealItem- url = 'nutrition:meal_item:edit'- pk = 4- data = {- 'amount': 1,- 'ingredient': 1,- 'weight_unit': 1,- }---class EditMealItemWeightTestCase(WgerEditTestCase):- """- Tests editing a meal, set the amount using weight- """-- object_class = MealItem- url = 'nutrition:meal_item:edit'- pk = 4- data = {'amount': 100, 'ingredient': 1}---class AddMealItemUnitTestCase(WgerAddTestCase):- """- Tests adding a meal, set the amount using a unit- """-- object_class = MealItem- url = reverse('nutrition:meal_item:add', kwargs={'meal_id': 3})- data = {- 'amount': 1,- 'ingredient': 1,- 'weight_unit': 1,- }---class AddMealItemWeightTestCase(WgerAddTestCase):- """- Tests adding a meal, set the amount using weight- """-- object_class = MealItem- url = reverse('nutrition:meal_item:add', kwargs={'meal_id': 3})- data = {'amount': 100, 'ingredient': 1}-class MealItemApiTestCase(api_base_test.ApiBaseResourceTestCase):"""diff --git a/wger/nutrition/tests/test_plan.py b/wger/nutrition/tests/test_plan.pyindex bf6abbf9b..aba234a70 100644--- a/wger/nutrition/tests/test_plan.py+++ b/wger/nutrition/tests/test_plan.py@@ -13,173 +13,11 @@# You should have received a copy of the GNU Affero General Public License# along with Workout Manager. If not, see <http://www.gnu.org/licenses/>.-# Django-from django.urls import reverse-# wgerfrom wger.core.tests import api_base_test-from wger.core.tests.base_testcase import (- WgerDeleteTestCase,- WgerEditTestCase,- WgerTestCase,-)from wger.nutrition.models import NutritionPlan-class PlanRepresentationTestCase(WgerTestCase):- """- Test the representation of a model- """-- def test_representation(self):- """- Test that the representation of an object is correct- """- p = NutritionPlan.objects.get(pk=5)- self.assertEqual("{0}".format(p), 'Description 1')-- p.description = ''- p.save()- self.assertEqual("{0}".format(p), 'Nutrition plan')---class PlanShareButtonTestCase(WgerTestCase):- """- Test that the share button is correctly displayed and hidden- """-- def test_share_button(self):- plan = NutritionPlan.objects.get(pk=5)- url = plan.get_absolute_url()-- response = self.client.get(url)- self.assertFalse(response.context['show_shariff'])-- self.user_login('admin')- response = self.client.get(url)- self.assertTrue(response.context['show_shariff'])-- self.user_login('test')- response = self.client.get(url)- self.assertFalse(response.context['show_shariff'])---class PlanAccessTestCase(WgerTestCase):- """- Test accessing the workout page- """-- def test_access_shared(self):- """- Test accessing the URL of a shared workout- """- plan = NutritionPlan.objects.get(pk=5)-- self.user_login('admin')- response = self.client.get(plan.get_absolute_url())- self.assertEqual(response.status_code, 200)-- self.user_login('test')- response = self.client.get(plan.get_absolute_url())- self.assertEqual(response.status_code, 200)-- self.user_logout()- response = self.client.get(plan.get_absolute_url())- self.assertEqual(response.status_code, 200)-- def test_access_not_shared(self):- """- Test accessing the URL of a private workout- """- plan = NutritionPlan.objects.get(pk=4)-- self.user_login('admin')- response = self.client.get(plan.get_absolute_url())- self.assertEqual(response.status_code, 403)-- self.user_login('test')- response = self.client.get(plan.get_absolute_url())- self.assertEqual(response.status_code, 200)-- self.user_logout()- response = self.client.get(plan.get_absolute_url())- self.assertEqual(response.status_code, 403)---class DeletePlanTestCase(WgerDeleteTestCase):- """- Tests deleting a nutritional plan- """-- object_class = NutritionPlan- url = 'nutrition:plan:delete'- pk = 2---class EditPlanTestCase(WgerEditTestCase):- """- Tests editing an ingredient- """-- object_class = NutritionPlan- url = 'nutrition:plan:edit'- pk = 2- data = {'description': 'My new description'}---class PlanDailyCaloriesTestCase(WgerTestCase):- """- Tests the handling of the daily calories in the plan page- """-- def test_overview_no_calories(self):- """- Tests the overview page with no daily calories set- """-- self.user_login('test')-- # Can't find goal calories text- response = self.client.get(reverse('nutrition:plan:view', kwargs={'id': 1}))- self.assertFalse(response.context['plan'].has_goal_calories)-- self.assertEqual(response.status_code, 200)- self.assertNotContains(response, 'goal amount of calories')-- def test_overview_calories(self):- """- Tests the overview page with no daily calories set- """-- # Plan has daily calories goal- self.user_login('test')- plan = NutritionPlan.objects.get(pk=1)- plan.has_goal_calories = True- plan.save()-- # Can find goal calories text- response = self.client.get(reverse('nutrition:plan:view', kwargs={'id': 1}))- self.assertTrue(response.context['plan'].has_goal_calories)- self.assertEqual(response.status_code, 200)- self.assertContains(response, 'goal amount of calories')-- def test_meal_overview(self):- """- Tests the meal overview row- """-- # Plan has daily calories goal- self.user_login('test')- plan = NutritionPlan.objects.get(pk=1)- plan.has_goal_calories = True- plan.save()-- # Can find goal calories text- response = self.client.get(reverse('nutrition:plan:view', kwargs={'id': 1}))- meal = response.context['plan'].meal_set.select_related()[0]- self.assertTrue(meal.get_nutritional_values()['energy'])--class PlanApiTestCase(api_base_test.ApiBaseResourceTestCase):"""Tests the nutritional plan overview resourcediff --git a/wger/nutrition/urls.py b/wger/nutrition/urls.pyindex 618aa62d5..1af3c2812 100644--- a/wger/nutrition/urls.py+++ b/wger/nutrition/urls.py@@ -29,9 +29,6 @@ from wger.nutrition.views import (bmi,calculator,ingredient,- log,- meal,- meal_item,plan,unit,unit_ingredient,@@ -66,44 +63,6 @@ patterns_plan = [),]-# sub patterns for meals-patterns_meal = [- path(- '<int:plan_pk>/meal/add/',- login_required(meal.MealCreateView.as_view()),- name='add',- ),- path(- '<int:pk>/edit/',- login_required(meal.MealEditView.as_view()),- name='edit',- ),- path(- '<int:id>/delete/',- meal.delete_meal,- name='delete',- ),-]--# sub patterns for meal items-patterns_meal_item = [- path(- '<int:meal_id>/item/add/',- login_required(meal_item.MealItemCreateView.as_view()),- name='add',- ),- path(- '<int:pk>/edit/',- login_required(meal_item.MealItemEditView.as_view()),- name='edit',- ),- path(- '<int:item_id>/delete/',- meal_item.delete_meal_item,- name='delete',- ),-]-# sub patterns for ingredientpatterns_ingredient = [path(@@ -234,53 +193,11 @@ patterns_calories = [), # JS]-# sub patterns for calories dairy-patterns_diary = [- path(- '<int:pk>',- ReactView.as_view(login_required=True),- name='overview',- ),- re_path(- r'^(?P<pk>\d+)/(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})$',- log.detail,- name='detail',- ),- path(- 'entry/<int:pk>/delete',- log.LogDeleteView.as_view(),- name='delete',- ),- path(- 'plan/<int:plan_pk>/add',- log.LogCreateView.as_view(),- name='add',- ),- path(- 'log-meal/<int:meal_pk>',- log.log_meal,- name='log_meal',- ),- path(- 'log-plan/<int:plan_pk>',- log.log_plan,- name='log_plan',- )-]-urlpatterns = [path('', include((patterns_plan, "plan"),namespace="plan",)),- path('meal/', include(- (patterns_meal, "meal"),- namespace="meal",- )),- path('meal/item/', include(- (patterns_meal_item, "meal_item"),- namespace="meal_item",- )),path('ingredient/', include((patterns_ingredient, "ingredient"),namespace="ingredient",@@ -304,8 +221,4 @@ urlpatterns = [(patterns_calories, "calories"),namespace="calories",)),- path('diary/', include(- (patterns_diary, "log"),- namespace="log",- )),]diff --git a/wger/nutrition/views/log.py b/wger/nutrition/views/log.pydeleted file mode 100644index 96a16644d..000000000--- a/wger/nutrition/views/log.py+++ /dev/null@@ -1,246 +0,0 @@-# -*- coding: utf-8 -*---# This file is part of wger Workout Manager.-#-# wger Workout Manager is free software: you can redistribute it and/or modify-# it under the terms of the GNU Affero General Public License as published by-# the Free Software Foundation, either version 3 of the License, or-# (at your option) any later version.-#-# wger Workout Manager is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU Affero General Public License--# Standard Library-import datetime-import logging--# Django-from django.http import (- HttpResponseForbidden,- HttpResponseRedirect,-)-from django.shortcuts import (- get_object_or_404,- render,-)-from django.urls import reverse-from django.utils.translation import gettext_lazy-from django.views.generic import (- CreateView,- DeleteView,-)--# wger-from wger.nutrition.forms import MealLogItemForm-from wger.nutrition.models import (- LogItem,- Meal,- NutritionPlan,-)-from wger.utils.generic_views import (- WgerDeleteMixin,- WgerFormMixin,- WgerPermissionMixin,-)---logger = logging.getLogger(__name__)---def overview(request, pk):- """- Shows an overview of diary entries for the given plan- """-- # Check read permission- plan = get_object_or_404(NutritionPlan, pk=pk)- user = plan.user- is_owner = request.user == user-- if not is_owner and not user.userprofile.ro_access:- return HttpResponseForbidden()-- log_data = []- planned_calories = plan.get_nutritional_values()['total']['energy']- for item in plan.get_log_overview():- log_data.append(- {- 'date': item['date'],- 'planned_calories': planned_calories,- 'logged_calories': item['energy'],- 'difference': item['energy'] - planned_calories- }- )-- context = {'plan': plan, 'show_shariff': is_owner, 'is_owner': is_owner, 'log_data': log_data}-- return render(request, 'log/overview.html', context)---def detail(request, pk, year, month, day):- """- Shows an overview of the log for the given date- """-- # Check read permission- plan = get_object_or_404(NutritionPlan, pk=pk)- user = plan.user- is_owner = request.user == user-- if not is_owner and not user.userprofile.ro_access:- return HttpResponseForbidden()-- try:- date = datetime.date(year=int(year), month=int(month), day=int(day))- except ValueError:- date = datetime.date.today()- return HttpResponseRedirect(- reverse(- 'nutrition:log:detail',- kwargs={- 'pk': pk,- 'year': date.year,- 'month': date.month,- 'day': date.day- }- )- )-- context = {- 'plan': plan,- 'date': date,- 'show_shariff': is_owner,- 'is_owner': is_owner,- 'log_summary': plan.get_log_summary(date),- 'log_entries': plan.get_log_entries(date),- 'nutritional_data': plan.get_nutritional_values()- }-- return render(request, 'log/detail.html', context)---def log_meal(request, meal_pk):- """- Copy the requested meal item and logs its nutritional values- """-- # Check read permission- meal = get_object_or_404(Meal, pk=meal_pk)- mealUser = meal.plan.user- is_owner = request.user == mealUser-- if not is_owner and not mealUser.userprofile.ro_access:- return HttpResponseForbidden()-- _logMealPlan([meal])- date = datetime.date.today()- return HttpResponseRedirect(- reverse(- 'nutrition:log:detail',- kwargs={- 'pk': meal.plan_id,- 'year': date.year,- 'month': date.month,- 'day': date.day- }- )- )---def log_plan(request, plan_pk):- """- Copy the requested plan item and log all of the meals within it- """- plan = get_object_or_404(NutritionPlan, pk=plan_pk)- planUser = plan.user- is_owner = request.user == planUser- if not is_owner and not planUser.userprofile.ro_access:- return HttpResponseForbidden()-- _logMealPlan(plan.meal_set.select_related())- return HttpResponseRedirect(reverse('nutrition:log:overview', kwargs={'pk': plan_pk}))---def _logMealPlan(meals):- """- Helper method to log a collection of meals- """-- for meal in meals:- for item in meal.mealitem_set.select_related():- log_item = LogItem(- plan=item.meal.plan,- meal=meal,- ingredient=item.ingredient,- weight_unit=item.weight_unit,- amount=item.amount- )- log_item.save()---class LogCreateView(WgerFormMixin, CreateView):- """- Generic view to create a new meal diary entry- """-- model = LogItem- form_class = MealLogItemForm- custom_js = 'wgerInitIngredientAutocompleter();'- plan = None-- def dispatch(self, request, *args, **kwargs):- """- Check that the user owns the meal- """- plan = get_object_or_404(NutritionPlan, pk=kwargs['plan_pk'])- if plan.user == request.user:- self.plan = plan- return super(LogCreateView, self).dispatch(request, *args, **kwargs)- else:- return HttpResponseForbidden()-- def get_success_url(self):- return reverse('nutrition:plan:view', kwargs={'id': self.plan.id})-- def get_context_data(self, **kwargs):- """- Send some additional data to the template- """- context = super(LogCreateView, self).get_context_data(**kwargs)- context['ingredient_searchfield'] = self.request.POST.get('ingredient_searchfield', '')- return context-- def form_valid(self, form):- """- Manually set the corresponding meal- """- form.instance.plan = self.plan- return super(LogCreateView, self).form_valid(form)---class LogDeleteView(WgerDeleteMixin, DeleteView, WgerPermissionMixin):- """- Delete a nutrition diary entry- """- model = LogItem- title = gettext_lazy('Delete?')- form_action_urlname = 'nutrition:log:delete'- login_required = True-- def get_success_url(self):- """- Return to the nutrition diary detail page- """- return reverse(- 'nutrition:log:detail',- kwargs={- 'pk': self.object.plan.pk,- 'year': self.object.datetime.year,- 'month': self.object.datetime.month,- 'day': self.object.datetime.day- }- )diff --git a/wger/nutrition/views/meal.py b/wger/nutrition/views/meal.pydeleted file mode 100644index 71499c8bb..000000000--- a/wger/nutrition/views/meal.py+++ /dev/null@@ -1,101 +0,0 @@-# -*- coding: utf-8 -*---# This file is part of wger Workout Manager.-#-# wger Workout Manager is free software: you can redistribute it and/or modify-# it under the terms of the GNU Affero General Public License as published by-# the Free Software Foundation, either version 3 of the License, or-# (at your option) any later version.-#-# wger Workout Manager is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU Affero General Public License--# Standard Library-import logging--# Django-from django.contrib.auth.decorators import login_required-from django.http import (- HttpResponseForbidden,- HttpResponseRedirect,-)-from django.shortcuts import get_object_or_404-from django.utils.translation import gettext_lazy-from django.views.generic import (- CreateView,- UpdateView,-)--# wger-from wger.nutrition.models import (- Meal,- NutritionPlan,-)-from wger.utils.generic_views import WgerFormMixin---logger = logging.getLogger(__name__)--# ************************-# Meal functions-# ************************---class MealCreateView(WgerFormMixin, CreateView):- """- Generic view to add a new meal to a nutrition plan- """-- model = Meal- fields = ['time', 'name']- title = gettext_lazy('Add new meal')- owner_object = {'pk': 'plan_pk', 'class': NutritionPlan}-- def form_valid(self, form):- plan = get_object_or_404(NutritionPlan, pk=self.kwargs['plan_pk'], user=self.request.user)- form.instance.plan = plan- form.instance.order = 1- return super(MealCreateView, self).form_valid(form)-- def get_success_url(self):- return self.object.plan.get_absolute_url()-- # Send some additional data to the template- def get_context_data(self, **kwargs):- context = super(MealCreateView, self).get_context_data(**kwargs)- return context---class MealEditView(WgerFormMixin, UpdateView):- """- Generic view to update an existing meal- """-- model = Meal- fields = ['time', 'name']- title = gettext_lazy('Edit meal')-- def get_success_url(self):- return self.object.plan.get_absolute_url()---@login_required-def delete_meal(request, id):- """- Deletes the meal with the given ID- """-- # Load the meal- meal = get_object_or_404(Meal, pk=id)- plan = meal.plan-- # Only delete if the user is the owner- if plan.user == request.user:- meal.delete()- return HttpResponseRedirect(plan.get_absolute_url())- else:- return HttpResponseForbidden()diff --git a/wger/nutrition/views/meal_item.py b/wger/nutrition/views/meal_item.pydeleted file mode 100644index cb1f6c7e6..000000000--- a/wger/nutrition/views/meal_item.py+++ /dev/null@@ -1,123 +0,0 @@-# -*- coding: utf-8 -*---# This file is part of wger Workout Manager.-#-# wger Workout Manager is free software: you can redistribute it and/or modify-# it under the terms of the GNU Affero General Public License as published by-# the Free Software Foundation, either version 3 of the License, or-# (at your option) any later version.-#-# wger Workout Manager is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU Affero General Public License--# Standard Library-import logging--# Django-from django.contrib.auth.decorators import login_required-from django.http import (- HttpResponseForbidden,- HttpResponseRedirect,-)-from django.shortcuts import get_object_or_404-from django.urls import reverse-from django.utils.translation import gettext_lazy-from django.views.generic import (- CreateView,- UpdateView,-)--# wger-from wger.nutrition.forms import MealItemForm-from wger.nutrition.models import (- Meal,- MealItem,-)-from wger.utils.generic_views import WgerFormMixin---logger = logging.getLogger(__name__)---@login_required-def delete_meal_item(request, item_id):- """- Deletes the meal ingredient with the given ID- """-- # Load the item- item = get_object_or_404(MealItem, pk=item_id)- plan = item.meal.plan-- # Only delete if the user is the owner- if plan.user == request.user:- item.delete()- return HttpResponseRedirect(reverse('nutrition:plan:view', kwargs={'id': plan.id}))- else:- return HttpResponseForbidden()---class MealItemCreateView(WgerFormMixin, CreateView):- """- Generic view to create a new meal item- """-- model = MealItem- form_class = MealItemForm- custom_js = 'wgerInitIngredientAutocompleter();'-- def dispatch(self, request, *args, **kwargs):- """- Check that the user owns the meal- """- meal = get_object_or_404(Meal, pk=kwargs['meal_id'])- if meal.plan.user == request.user:- self.meal = meal- return super(MealItemCreateView, self).dispatch(request, *args, **kwargs)- else:- return HttpResponseForbidden()-- def get_success_url(self):- return reverse('nutrition:plan:view', kwargs={'id': self.meal.plan.id})-- def get_context_data(self, **kwargs):- """- Send some additional data to the template- """- context = super(MealItemCreateView, self).get_context_data(**kwargs)- context['ingredient_searchfield'] = self.request.POST.get('ingredient_searchfield', '')- return context-- def form_valid(self, form):- """- Manually set the corresponding meal- """- form.instance.meal = self.meal- form.instance.order = 1- return super(MealItemCreateView, self).form_valid(form)---class MealItemEditView(WgerFormMixin, UpdateView):- """- Generic view to update an existing meal item- """-- model = MealItem- form_class = MealItemForm- custom_js = 'wgerInitIngredientAutocompleter();'- title = gettext_lazy('Edit meal item')-- def get_success_url(self):- return reverse('nutrition:plan:view', kwargs={'id': self.object.meal.plan.id})-- def get_context_data(self, **kwargs):- """- Send some additional data to the template- """- context = super(MealItemEditView, self).get_context_data(**kwargs)- context['ingredient_searchfield'] = self.object.ingredient.name- return contextdiff --git a/wger/nutrition/views/plan.py b/wger/nutrition/views/plan.pyindex cae8300ca..01a6f36bf 100644--- a/wger/nutrition/views/plan.py+++ b/wger/nutrition/views/plan.py@@ -26,22 +26,13 @@ from django.http import ()from django.shortcuts import (get_object_or_404,- render,)-from django.template.context_processors import csrffrom django.urls import (reverse,- reverse_lazy,)from django.utils.translation import (gettext as _,- gettext_lazy,)-from django.views.generic import (- DeleteView,- UpdateView,-)-# Third Partyfrom reportlab.lib import colorsfrom reportlab.lib.pagesizes import A4@@ -56,18 +47,11 @@ from reportlab.platypus import (# wgerfrom wger.nutrition.consts import (MEALITEM_WEIGHT_GRAM,- MEALITEM_WEIGHT_UNIT,)from wger.nutrition.models import NutritionPlan-from wger.utils.generic_views import (- WgerDeleteMixin,- WgerFormMixin,-)from wger.utils.helpers import (check_token,- make_token,)-from wger.utils.language import load_languagefrom wger.utils.pdf import (get_logo,header_colour,@@ -76,7 +60,6 @@ from wger.utils.pdf import (styleSheet,)-logger = logging.getLogger(__name__)# ************************@@ -84,119 +67,6 @@ logger = logging.getLogger(__name__)# ************************-@login_required-def overview(request):- template_data = {}- template_data.update(csrf(request))-- plans = NutritionPlan.objects.filter(user=request.user)- template_data['plans'] = plans-- return render(request, 'plan/overview.html', template_data)---@login_required-def add(request):- """- Add a new nutrition plan and redirect to its page- """-- plan = NutritionPlan()- plan.user = request.user- plan.language = load_language()- plan.save()-- return HttpResponseRedirect(reverse('nutrition:plan:view', kwargs={'id': plan.id}))---class PlanDeleteView(WgerDeleteMixin, DeleteView):- """- Generic view to delete a nutritional plan- """-- model = NutritionPlan- success_url = reverse_lazy('nutrition:plan:overview')- messages = gettext_lazy('Successfully deleted')-- def get_context_data(self, **kwargs):- """- Send some additional data to the template- """- context = super(PlanDeleteView, self).get_context_data(**kwargs)- context['title'] = _('Delete {0}?').format(self.object)- return context---class PlanEditView(WgerFormMixin, UpdateView):- """- Generic view to update an existing nutritional plan- """-- model = NutritionPlan- fields = ('description', 'has_goal_calories')-- def get_context_data(self, **kwargs):- """- Send some additional data to the template- """- context = super(PlanEditView, self).get_context_data(**kwargs)- context['title'] = _('Edit {0}').format(self.object)- return context---def view(request, id):- """- Show the nutrition plan with the given ID- """- template_data = {}-- plan = get_object_or_404(NutritionPlan, pk=id)- user = plan.user- is_owner = request.user == user-- if not is_owner and not user.userprofile.ro_access:- return HttpResponseForbidden()-- uid, token = make_token(user)-- # Process and show the last 5 diary entries- log_data = []- planned_calories = plan.get_nutritional_values()['total']['energy']- for item in plan.get_log_overview()[:5]:- log_data.append(- {- 'date': item['date'],- 'planned_calories': planned_calories,- 'logged_calories': item['energy'],- 'difference': item['energy'] - planned_calories- }- )-- # Load the language and pass it to the template- language = load_language()- template_data['language'] = language- template_data['MEALITEM_WEIGHT_GRAM'] = MEALITEM_WEIGHT_GRAM- template_data['MEALITEM_WEIGHT_UNIT'] = MEALITEM_WEIGHT_UNIT-- # Get the nutritional info- template_data['plan'] = plan- template_data['nutritional_data'] = \- plan.get_nutritional_values()-- # Get the weight entry used- template_data['weight_entry'] = plan.get_closest_weight_entry()-- # Tokens for the links- template_data['uid'] = uid- template_data['log_data'] = log_data- template_data['token'] = token- template_data['owner_user'] = user- template_data['is_owner'] = is_owner- template_data['show_shariff'] = is_owner-- return render(request, 'plan/view.html', template_data)--@login_requireddef copy(request, pk):"""