Self hosted FLOSS fitness/workout, nutrition and weight tracker
Merge branch 'master' into nutrition-diary
Roland Geidercff54bc888f2
diff --cc extras/scripts/filter-fixtures.pyindex 8d489b354,615b3ab3f..a8e1deb13--- a/extras/scripts/filter-fixtures.py+++ b/extras/scripts/filter-fixtures.py@@@ -26,14 -26,14 +26,15 @@@ import jsodef filter_dump(data, model_list, filename):- '''+ """Helper function- '''+ """filter_data = [i for i in data if i['model'] in model_list]- with open(filename, 'w') as outfile:- json.dump(filter_data, outfile, indent=4)+ if filter_data:+ with open(filename, 'w') as outfile:+ json.dump(filter_data, outfile, indent=4)+# This is a full dump of the DBfixture = open('data.json')data = json.load(fixture)diff --cc wger/nutrition/api/views.pyindex 8145c4353,82094a94e..592ace11b--- a/wger/nutrition/api/views.py+++ b/wger/nutrition/api/views.py@@@ -15,23 -15,22 +15,24 @@@# 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/>.-# Third Party+import datetime++from django.shortcuts import get_object_or_404from rest_framework import viewsets- from rest_framework.response import Responsefrom rest_framework.decorators import (- detail_route,+ action,api_view)+ from rest_framework.response import Response+ # wgerfrom wger.nutrition.api.serializers import (- NutritionPlanSerializer,+ IngredientSerializer,IngredientWeightUnitSerializer,- WeightUnitSerializer,MealItemSerializer,MealSerializer,- IngredientSerializer+ NutritionPlanSerializer,+ WeightUnitSerializer)from wger.nutrition.forms import UnitChooserFormfrom wger.nutrition.models import (@@@ -191,48 -193,23 +195,48 @@@ class NutritionPlanViewSet(viewsets.Modreturn NutritionPlan.objects.filter(user=self.request.user)def perform_create(self, serializer):- '''+ """Set the owner- '''+ """serializer.save(user=self.request.user, language=load_language())- @detail_route()+ @action(detail=True)def nutritional_values(self, request, pk):- '''+ """Return an overview of the nutritional plan's values- '''+ """return Response(NutritionPlan.objects.get(pk=pk).get_nutritional_values())- @detail_route()++ @action(detail=True)+ def get_log_overview(self, request, pk):+ '''+ Return a list of log diary entries for the nutrition plan+ '''+ plan = get_object_or_404(NutritionPlan, pk=pk, user=request.user)+ return Response(plan.get_log_overview())+- @detail_route()++ @action(detail=True)+ def log_summary(self, request, pk):+ '''+ Return a summary of the nutrition diary for a given date+ '''+ today = datetime.date.today()+ year = request.GET.get('year', today.year)+ month = request.GET.get('month', today.month)+ day = request.GET.get('day', today.day)+ plan = get_object_or_404(NutritionPlan, pk=pk, user=request.user)++ try:+ date = datetime.date(year=int(year), month=int(month), day=int(day))+ except ValueError:+ date = today+ return Response(plan.get_log_summary(date))+class MealViewSet(WgerOwnerObjectModelViewSet):- '''+ """API endpoint for meal objects- '''+ """serializer_class = MealSerializeris_private = Trueordering_fields = '__all__'diff --cc wger/nutrition/models.pyindex 268c31818,d156777be..2072b961f--- a/wger/nutrition/models.py+++ b/wger/nutrition/models.py@@@ -10,37 -10,43 +10,44 @@@# 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---# Standard Library+# GNU General Public License for more details.+## 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/>.+++# Standard Libraryimport logging-# GNU General Public License for more details.-#+import datetimefrom decimal import Decimal+from collections import OrderedDict- from django.db import models-- from django.template.loader import render_to_string- from django.template.defaultfilters import slugify # django.utils.text.slugify in django 1.5!- from django.core.validators import MaxValueValidator, MinValueValidator- from django.core.exceptions import ValidationError- from django.core.urlresolvers import reverse- from django.core import mail- from django.core.cache import cache+ # Django+ from django.conf import settingsfrom django.contrib.auth.models import Userfrom django.contrib.sites.models import Site- from django.utils.encoding import python_2_unicode_compatible- from django.utils.translation import ugettext_lazy as _+ from django.core import mail+ from django.core.cache import cache+ from django.core.exceptions import ValidationError+ from django.core.validators import (+ MaxValueValidator,+ MinValueValidator+ )+ from django.db import models+ from django.template.defaultfilters import slugify # django.utils.text.slugify in django 1.5!+ from django.template.loader import render_to_string+ from django.urls import reversefrom django.utils import translation- from django.conf import settings+ from django.utils.translation import ugettext_lazy as _+ # wgerfrom wger.core.models import Language- from wger.utils.constants import TWOPLACESfrom wger.utils.cache import cache_mapper+ from wger.utils.constants import TWOPLACESfrom wger.utils.fields import Html5TimeField- from wger.utils.models import AbstractLicenseModel, AbstractSubmissionModel+ from wger.utils.models import (+ AbstractLicenseModel,+ AbstractSubmissionModel+ )from wger.utils.units import AbstractWeightfrom wger.weight.models import WeightEntry@@@ -202,64 -209,17 +210,63 @@@ class NutritionPlan(models.Model)else:return 4+ def get_log_overview(self):+ '''+ Returns an overview for all logs available for this plan+ '''+ result = []+ for date in self.logitem_set.datetimes('datetime', 'day', order='DESC'):+ # TODO: in python 3.5 this can be simplified as z = {**x, **y}+ tmp = self.get_log_summary(date=date).copy()+ tmp.update({'date': date.date()})+ result.append(tmp)++ return result++ def get_log_entries(self, date=None):+ '''+ Convenience function that returns the log entries for a given date+ '''+ if not date:+ date = datetime.date.today()++ # TODO: in django 1.9 use __date=date here+ return self.logitem_set.filter(datetime__year=date.year,+ datetime__month=date.month,+ datetime__day=date.day).select_related()++ def get_log_summary(self, date=None):+ '''+ Sums the nutritional info of the items logged for the given date+ '''+ use_metric = self.user.userprofile.use_metric+ result = {'energy': 0,+ 'protein': 0,+ 'carbohydrates': 0,+ 'carbohydrates_sugar': 0,+ 'fat': 0,+ 'fat_saturated': 0,+ 'fibres': 0,+ 'sodium': 0}++ # Perform the sums+ for item in self.get_log_entries(date):+ values = item.get_nutritional_values(use_metric=use_metric)+ for key in result.keys():+ result[key] += values[key]+ return result+- @python_2_unicode_compatibleclass Ingredient(AbstractSubmissionModel, AbstractLicenseModel, models.Model):- '''+ """An ingredient, with some approximate nutrition values- '''+ """ENERGY_APPROXIMATION = 15- '''+ """How much the calculated energy from protein, etc. can deviate from theenergy amount given (in percent).- '''+ """# Metaclass to set some other propertiesclass Meta:@@@ -609,15 -583,47 +630,15 @@@ class Meal(models.Model)return nutritional_info-class MealItem(models.Model):- """- An item (component) of a meal+class BaseMealItem(object):- '''+ """+ Base class for an item (component) of a meal or log- meal = models.ForeignKey(Meal,- verbose_name=_('Nutrition plan'),- editable=False,- on_delete=models.CASCADE)- ingredient = models.ForeignKey(Ingredient,- verbose_name=_('Ingredient'),- on_delete=models.CASCADE)- weight_unit = models.ForeignKey(IngredientWeightUnit,- verbose_name=_('Weight unit'),- null=True,- blank=True,- on_delete=models.CASCADE)-- order = models.IntegerField(verbose_name=_('Order'),- blank=True,- editable=False)- amount = models.DecimalField(decimal_places=2,- max_digits=6,- verbose_name=_('Amount'),- validators=[MinValueValidator(1),- MaxValueValidator(1000)])-- def __str__(self):- """- Return a more human-readable representation- """- return u"{0}g ingredient {1}".format(self.amount, self.ingredient_id)-- def get_owner_object(self):- """- Returns the object that has owner information- """- return self.meal.plan+ This just provides some common helper functions- '''++ """def get_unit_type(self):- '''+ """Returns the type of unit used:- a value in grams- a 'human' unit like 'a cup' or 'a slice'@@@ -685,118 -691,3 +706,106 @@@nutritional_info[i] = Decimal(nutritional_info[i]).quantize(TWOPLACES)return nutritional_info++- @python_2_unicode_compatible+class MealItem(BaseMealItem, models.Model):- '''++ """+ An item (component) of a meal- '''++ """+++ meal = models.ForeignKey(Meal,+ verbose_name=_('Nutrition plan'),- editable=False)- ingredient = models.ForeignKey(Ingredient, verbose_name=_('Ingredient'))- '''- Ingredient- '''-++ editable=False,++ on_delete=models.CASCADE)++ ingredient = models.ForeignKey(Ingredient,++ verbose_name=_('Ingredient'),++ on_delete=models.CASCADE)+ weight_unit = models.ForeignKey(IngredientWeightUnit,+ verbose_name=_('Weight unit'),+ null=True,+ blank=True,- )- '''- Weight unit used (grams, slices, etc.)- '''++ on_delete=models.CASCADE)+++ order = models.IntegerField(verbose_name=_('Order'),++ blank=True,++ editable=False)+ amount = models.DecimalField(decimal_places=2,+ max_digits=6,+ verbose_name=_('Amount'),+ validators=[MinValueValidator(1),+ MaxValueValidator(1000)])- '''- The amount of units- '''-- order = models.IntegerField(verbose_name=_('Order'),- blank=True,- editable=False)- '''- The order of the ingredient within the meal- '''++ def __str__(self):- '''++ """+ Return a more human-readable representation- '''++ """+ return u"{0}g ingredient {1}".format(self.amount, self.ingredient_id)++ def get_owner_object(self):- '''++ """+ Returns the object that has owner information- '''++ """+ return self.meal.plan++- @python_2_unicode_compatible+class LogItem(BaseMealItem, models.Model):- '''++ """+ An item (component) of a log- '''++ """+ # Metaclass to set some other properties+ class Meta:+ ordering = ["datetime", ]++ plan = models.ForeignKey(NutritionPlan,+ verbose_name=_('Nutrition plan'),+ editable=False)+ '''+ The plan this log belongs to+ '''++ datetime = models.DateTimeField(auto_now=True)+ '''+ Time and date when the log was added+ '''++ comment = models.TextField(verbose_name=_('Comment'),+ blank=True,+ null=True)+ '''+ Comment field, for additional information+ '''++ ingredient = models.ForeignKey(Ingredient, verbose_name=_('Ingredient'))+ '''+ Ingredient+ '''++ weight_unit = models.ForeignKey(IngredientWeightUnit,+ verbose_name=_('Weight unit'),+ null=True,+ blank=True,+ )+ '''+ Weight unit used (grams, slices, etc.)+ '''++ amount = models.DecimalField(decimal_places=2,+ max_digits=6,+ verbose_name=_('Amount'),+ validators=[MinValueValidator(1),+ MaxValueValidator(1000)])+ '''+ The amount of units+ '''++ def __str__(self):+ '''+ Return a more human-readable representation+ '''+ return u"Diary entry for {}, plan {}".format(self.datetime, self.plan.pk)++ def get_owner_object(self):+ '''+ Returns the object that has owner information+ '''+ return self.plandiff --cc wger/nutrition/templates/mobile/plan/view.htmlindex 1bf39a0d3,000000000..0bda54188mode 100644,000000..100644--- a/wger/nutrition/templates/mobile/plan/view.html+++ b/wger/nutrition/templates/mobile/plan/view.html@@@ -1,387 -1,0 +1,384 @@@+{% extends "base.html" %}+{% load i18n staticfiles wger_extras %}+++{# #}+{# Opengraph #}+{# #}+{% block opengraph %}+ {{ block.super }}+ <meta property="og:title" content="{% trans 'Nutrition plan' %}">+ <meta property="og:description" content="{{ plan }} / {{owner_user.username}}">+{% endblock %}+++{# #}+{# Title #}+{# #}+{% block title %}{% trans "Nutrition plan" %} – {{ plan.creation_date}}{% endblock %}+++{# #}+{# Header #}+{# #}+{% block header %}+<script>+function wgerCustomModalInit()+{+ // Init the autocompleter after loading the modal dialog+ wgerInitIngredientAutocompleter();+}++$(document).ready(function() {++ // Check if the user wants to see ingredients in english+ init_english_ingredients();+});+</script>+{% endblock %}+++{# #}+{# Content #}+{# #}+{% block content %}+{% if plan.description %}+<p>+ <span class="text-muted">{{plan.description}}</span>+</p>+{% endif %}+++{% if is_owner %}+{% for meal in plan.meal_set.select_related %}+<div class="modal fade" id="editoptions-meal-{{ meal.id }}">+ <div class="modal-dialog">+ <div class="modal-content">+ <div class="modal-header">+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>+ <h4 class="modal-title">+ {% trans "Options" %} {% if meal.time %} – {{meal.time|time:"H:i"}}{% endif %}+ </h4>+ </div>+ <div class="modal-body">+ <a href="{% url 'nutrition:meal:delete' meal.id %}"+ title="{% trans 'Delete' %}"+ {% auto_link_css flavour %}>+ {% trans "Delete meal" %}+ </a>+ <a href="{% url 'nutrition:meal:edit' meal.id %}"+ title="{% trans 'Edit' %}"+ {% auto_link_css flavour "wger-modal-dialog" %}>+ {% trans "Edit meal" %}+ </a>+ <a href="{% url 'nutrition:meal_item:add' meal.id %}"+ title="{% trans 'Add' %}"+ {% auto_link_css flavour %}>+ {% trans "Add item to meal" %}+ </a>+ </div>+ <div class="modal-footer">+ <button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>+ </div>+ </div>+ </div>+</div>++++++{% for item in meal.mealitem_set.select_related %}+ <div class="modal fade" id="editoptions-item-{{ item.id }}">+ <div class="modal-dialog">+ <div class="modal-content">+ <div class="modal-header">+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>+ <h4 class="modal-title">+ {% trans "Options" %}+ </h4>+ </div>+ <div class="modal-body">+ <h4>{{item.ingredient}}</h4>+ <h4>+ {% if item.get_unit_type == MEALITEM_WEIGHT_GRAM %}{{ item.amount|floatformat:"0" }}g+ {% else %}+ {{ item.amount|floatformat:"0" }} × {{ item.weight_unit.unit.name }}+ {% endif %}+ </h4>++ <table class="table">+ <thead>+ <tr>+ <th colspan="2">{% trans "Nutritional data" %}</th>+ </tr>+ </thead>+ <tbody>+ <tr>+ <td>{% trans "Energy" %}</td>+ <td class="align-right">{{item.get_nutritional_values.energy|floatformat}} {% trans "kcal" %}</td>+ </tr>+ <tr>+ <td>{% trans "Protein" %}</td>+ <td class="align-right">{{item.get_nutritional_values.protein|floatformat}} {% trans_weight_unit 'g' owner_user %}</td>+ </tr>+ <tr>+ <td>{% trans "Carbohydrates" %}</td>+ <td class="align-right">{{item.get_nutritional_values.carbohydrates|floatformat}} {% trans_weight_unit 'g' owner_user %}</td>+ </tr>+ <tr>+ <td>{% trans "Fat" %}</td>+ <td class="align-right">{{item.get_nutritional_values.fat|floatformat}} {% trans_weight_unit 'g' owner_user %}</td>+ </tr>+ </tbody>+ </table>++ <a href="{% url 'nutrition:meal_item:delete' item.id %}"+ title="{% trans 'Delete' %}"+ {% auto_link_css flavour %}>+ {% trans "Delete" %}+ </a>+ <a href="{% url 'nutrition:meal_item:edit' item.id %}"+ title="{% trans 'Edit' %}"+ {% auto_link_css flavour %}>+ {% trans "Edit" %}+ </a>+ </div>+ <div class="modal-footer">+ <button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>+ </div>+ </div>+ </div>+ </div>++{% endfor %}++{% endfor %}+{% endif %}+++{% for meal in plan.meal_set.select_related %}+<div class="list-group">++ <a href="#editoptions-meal-{{ meal.id }}" class="list-group-item active" data-toggle="modal">+ {% if is_owner %}+ <span class="glyphicon glyphicon-cog pull-right"></span>+ {% endif %}+ {% trans "Nr."%} {{ forloop.counter }}+ {% if meal.time %} – {{meal.time|time:"H:i"}}{% endif %}+ </a>++ {% for item in meal.mealitem_set.select_related %}+ <a href="#editoptions-item-{{ item.id }}" data-toggle="modal" class="list-group-item wger-list-group-item">+ {% if is_owner %}+ <span class="glyphicon glyphicon-cog pull-right"></span>+ {% endif %}+ <h4>{{ item.ingredient.name }}</h4>+ <p>+ {% if item.get_unit_type == MEALITEM_WEIGHT_GRAM %}{{ item.amount|floatformat:"0" }}g+ {% else %}+ {{ item.amount|floatformat:"0" }} × {{ item.weight_unit.unit.name }}+ {% endif %}+ </p>+ </a>+ {% if forloop.last and is_owner %}+ <a href="{% url 'nutrition:meal_item:add' meal.id %}"+ class="list-group-item list-group-item-success">+ <span class="{% fa_class 'plus' %}"></span>+ {% trans "Add item to meal" %}+ </a>+ {% endif %}+ {% empty %}+ {% if is_owner %}+ <a href="{% url 'nutrition:meal_item:add' meal.id %}"+ title="{% trans 'Add one now.' %}"+ class="list-group-item list-group-item-success">+ {% trans "No items for this meal." %}<br>+ {% trans "Add one now." %}+ </a>+ {% endif %}+ {% endfor %}+</div>+{% empty %}+ {% if is_owner %}+ <a href="{% url 'nutrition:meal:add' plan.id %}"+ {% auto_link_css flavour "wger-modal-dialog" %}>+ {% trans "No meals for this plan." %}<br>+ {% trans "Add one now." %}+ </a>+ {% endif %}+{% endfor %}++{% if is_owner %}+<p style="margin-top:2em;">+ <a href="{% url 'nutrition:meal:add' plan.id %}"+ {% auto_link_css flavour "wger-modal-dialog" %}>{% trans "Add a new meal" %}</a>+</p>+{% endif %}+++{% if is_owner and language.short_name != 'en' %}+ <p>+ {% trans "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">{% trans "That's done here" %}</a>:+ {% if owner_user.userprofile.show_english_ingredients %}+ <span class="{% fa_class 'check' %}" data-show-ingredients="true"></span>+ {% else %}+ <span class="{% fa_class 'times' %}" data-show-ingredients="false"></span>+ {% endif %}+ </p>+{% endif %}++{% endblock %}+++{# #}+{# Side bar #}+{# #}+{% block sidebar %}---+<h4>{% trans "Energy" %}</h4>+<table id="nutritional-data-energy" class="table">+ <thead>+ <tr>+ <th>{% trans "Energy" %}</th>+ <th class="align-right">{{nutritional_data.total.energy|floatformat:"0"}} {% trans "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 style="background-color:{% if total == 1 %}#8ae234;{% elif total == 2 %}#fce94f;{% elif total == 3 %}#fcaf3e;{% elif total > 3 %}#ef2929;{% endif %}">+ <td>{% trans "Goal" %}</td>+ <td class="align-right">+ <strong>{{owner_user.userprofile.calories|floatformat:"0"}} {% trans "kcal" %}</strong>+ </td>+ </tr>+ {% endwith %}+ {% endif %}+ </tbody>+</table>+++{% if is_owner and plan.has_goal_calories %}+ <p>{% blocktrans %}You have selected that this nutritional plan has a+ goal amount of calories. Use the calculator or enter the value yourself.{% endblocktrans %}+ <a href="{% url 'nutrition:calories:view' %}">{% trans "That's done here" %}</a>+ </p>+{% endif %}++<h4>{% trans "Nutritional data" %}</h4>+<table class="table table-condensed">+ <thead>+ <tr style="height:4em;">+ <th>{% trans "Macronutrients" %}</th>+ <th class="align-right">{% trans "Total" %}</th>+ <th class="align-right">{% trans "Percent of energy" %}</th>+ <th class="align-right">+ {% if owner_user.userprofile.use_metric %}+ {% trans "g per body kg" %}+ {% else %}+ {% trans "oz per body lb" %}+ {% endif %}+ </th>+ </tr>+ </thead>+ <tbody>+ <tr>+ <td>{% trans "Energy" %}</td>+ <td class="align-right">{{nutritional_data.total.energy|floatformat}} {% trans "kcal" %}</td>+ <td></td>+ <td></td>+ </tr>+ <tr>+ <td>{% trans "Protein" %}</td>+ <td class="align-right">{{nutritional_data.total.protein|floatformat}} {% trans_weight_unit 'g' owner_user %}</td>+ <td class="align-right">{{nutritional_data.percent.protein|floatformat}} %</td>+ <td class="align-right">{{nutritional_data.per_kg.protein|floatformat:2}}</td>+ </tr>+ <tr>+ <td>{% trans "Carbohydrates" %}</td>+ <td class="align-right">{{nutritional_data.total.carbohydrates|floatformat}} {% trans_weight_unit 'g' owner_user %}</td>+ <td class="align-right">{{nutritional_data.percent.carbohydrates|floatformat}} %</td>+ <td class="align-right">{{nutritional_data.per_kg.carbohydrates|floatformat:2}}</td>+ </tr>+ <tr>+ <td style="padding-left: 2em;">{% trans "Sugar content in carbohydrates" %}</td>+ <td class="align-right">{{nutritional_data.total.carbohydrates_sugar|floatformat}} {% trans_weight_unit 'g' owner_user %}</td>+ <td></td>+ <td></td>+ </tr>+ <tr>+ <td>{% trans "Fat" %}</td>+ <td class="align-right">{{nutritional_data.total.fat|floatformat}} {% trans_weight_unit 'g' owner_user %}</td>+ <td class="align-right">{{nutritional_data.percent.fat|floatformat}} %</td>+ <td class="align-right">{{nutritional_data.per_kg.fat|floatformat:2}}</td>+ </tr>+ <tr>+ <td style="padding-left: 2em;">{% trans "Saturated fat content in fats" %}</td>+ <td class="align-right">{{nutritional_data.total.fat_saturated|floatformat}} {% trans_weight_unit 'g' owner_user %}</td>+ <td></td>+ <td></td>+ </tr>+++ <tr>+ <th colspan="4">{% trans "Others" %}</th>+ </tr>+ <tr>+ <td>{% trans "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>{% trans "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>+{% endblock %}++++{# #}+{# Options #}+{# #}+{% block options %}+<div class="btn-group">+ <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">+ <span class="{% fa_class 'cog' %}"></span>+ {% trans "Options" %}+ </button>+ <ul class="dropdown-menu">+ <li>`+ <a href="{% url 'nutrition:plan:export-pdf' plan.id uid token %}" target="_blank">+ <span class="{% fa_class 'download' %}"></span>+ {% trans "Download as PDF" %}+ </a>+ </li>+ {% if is_owner %}+ <li>+ <a href="{% url 'nutrition:plan:edit' plan.id %}" class="wger-modal-dialog">+ <span class="{% fa_class 'pencil-square-o' %}"></span>+ {% trans "Edit nutrition plan" %}+ </a>+ </li>+ <li>+ <a href="{% url 'nutrition:plan:copy' plan.id %}">+ <span class="{% fa_class 'clone' %}"></span>+ {% trans "Make a copy of this nutrition plan" %}+ </a>+ </li>+ <li role="separator" class="divider"></li>+ <li>+ <a href="{% url 'nutrition:plan:delete' plan.id %}" class="wger-modal-dialog">+ <span class="{% fa_class 'trash' %}"></span>+ {% trans "Delete nutrition plan" %}+ </a>+ </li>+ {% endif %}+ </ul>+</div>+{% endblock %}diff --cc wger/nutrition/urls.pyindex d2984c52f,893665a4c..7ab4efc6c--- a/wger/nutrition/urls.py+++ b/wger/nutrition/urls.py@@@ -15,25 -15,26 +15,27 @@@# 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/>.- from django.contrib.auth.decorators import login_required+ # Djangofrom django.conf.urls import (- patterns,- url,- include+ include,+ url)+ from django.contrib.auth.decorators import login_required+ # wgerfrom wger.nutrition.views import (- ingredient,bmi,calculator,- plan,+ ingredient,meal,meal_item,+ plan,unit,- unit_ingredient+ unit_ingredient,+ log)+# sub patterns for nutritional planspatterns_plan = [url(r'^overview/$',@@@ -181,28 -182,14 +183,28 @@@ patterns_calories =name='activities'), # JS]+# sub patterns for calories dairy+patterns_diary = [+ url(r'^(?P<pk>\d+)$',+ log.overview,+ name='overview'),+ url(r'^(?P<pk>\d+)/(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})$',+ log.detail,+ name='detail'),+ url(r'^entry/(?P<pk>\d+)/delete$',+ log.LogDeleteView.as_view(),+ name='delete'),+]+urlpatterns = [- url(r'^', include((patterns_plan, 'plan'), namespace="plan")),- url(r'^meal/', include((patterns_meal, 'meal'), namespace="meal")),- url(r'^meal/item/', include((patterns_meal_item, 'meal_item'), namespace="meal_item")),- url(r'^ingredient/', include((patterns_ingredient, 'ingredient'), namespace="ingredient")),- url(r'^unit/', include((patterns_weight_unit, 'weight_unit'), namespace="weight_unit")),- url(r'^unit-to-ingredient/', include((patterns_unit_ingredient, 'unit_ingredient'), namespace="unit_ingredient")),- url(r'^calculator/bmi/', include((patterns_bmi, 'bmi'), namespace="bmi")),- url(r'^calculator/calories/', include((patterns_calories, 'calories'), namespace="calories")),+ url(r'^', include(patterns_plan, namespace="plan")),+ url(r'^meal/', include(patterns_meal, namespace="meal")),+ url(r'^meal/item/', include(patterns_meal_item, namespace="meal_item")),+ url(r'^ingredient/', include(patterns_ingredient, namespace="ingredient")),+ url(r'^unit/', include(patterns_weight_unit, namespace="weight_unit")),+ url(r'^unit-to-ingredient/', include(patterns_unit_ingredient, namespace="unit_ingredient")),+ url(r'^calculator/bmi/', include(patterns_bmi, namespace="bmi")),+ url(r'^calculator/calories/', include(patterns_calories, namespace="calories")),- url(r'^diary/', include(patterns_diary, namespace="log")),++url(r'^diary/', include(patterns_diary, namespace="log")),]