Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add description to plan, edit form

Roland Geider000b0ea5cf83
diff --git a/nutrition/models.py b/nutrition/models.py
index a593072e1..75510dc8b 100644
--- a/nutrition/models.py
+++ b/nutrition/models.py
@@ -29,6 +29,10 @@ class NutritionPlan(models.Model):
user = models.ForeignKey(User, verbose_name = _('User'))
language = models.ForeignKey(Language, verbose_name = _('Language'))
creation_date = models.DateField(_('Creation date'), auto_now_add=True)
+ description = models.TextField(max_length = 2000,
+ blank = True,
+ verbose_name = _('Description'),
+ help_text = _('A description of the goal of the plan, e.g. "Gain mass" or "Prepare for summer"'))
def __unicode__(self):
"""Return a more human-readable representation
diff --git a/nutrition/templates/edit_plan.html b/nutrition/templates/edit_plan.html
new file mode 100644
index 000000000..edf41a2b6
--- /dev/null
+++ b/nutrition/templates/edit_plan.html
@@ -0,0 +1,28 @@
+{% extends "base.html" %}
+{% load i18n %}
+{% load staticfiles %}
+
+{% block title %}{% trans "Edit meal" %}{% endblock %}
+
+
+{% block content %}
+
+<h2>{% trans "Edit meal" %}</h2>
+
+<form action="{% url nutrition.views.edit_plan plan.id %}"
+ method="post"
+ class="ym-form">
+{% csrf_token %}
+{{ form.non_field_errors }}
+<table>
+ {% include "form_snippet.html" with field=form.description %}
+ <tr>
+ <td><input type="submit" value="{% trans "Save" %}" /></td>
+ <td></td>
+ </tr>
+</table>
+</form>
+
+
+
+{% endblock %}
diff --git a/nutrition/templates/view_nutrition_plan.html b/nutrition/templates/view_nutrition_plan.html
index 7bc5b6144..69067d78c 100644
--- a/nutrition/templates/view_nutrition_plan.html
+++ b/nutrition/templates/view_nutrition_plan.html
@@ -22,6 +22,10 @@ $(document).ready(function() {
<h2>{% trans "Details for nutrition plan" %}</h2>
+{% if plan.description %}
+<p class="dimmed">{{plan.description}}</p>
+{% endif %}
+
<table>
<thead>
<tr>
@@ -33,7 +37,7 @@ $(document).ready(function() {
<tr>
<td>
{{ forloop.counter }}
- {% if meal.time %}<br>{{meal.time|time:"H:i"}}{% endif %}
+ {% if meal.time %} &ndash; {{meal.time|time:"H:i"}}{% endif %}
<div class="editoptions">
<a href="{% url nutrition.views.delete_meal meal.id %}"
@@ -88,6 +92,7 @@ $(document).ready(function() {
{% trans "No items for this meal." %} {% trans "Use link to add one." %}
</div>
{% endfor %}
+ <div class="editoptions">
<a href="{% url nutrition.views.edit_meal_item plan.id meal.id None %}"
title="{% trans 'Add' %}"
class="modal-dialog">
@@ -97,6 +102,7 @@ $(document).ready(function() {
alt="{% trans 'Add' %}">
{% trans "Add item to meal" %}
</a>
+ </div>
</ul>
</td>
</tr>
@@ -110,6 +116,26 @@ $(document).ready(function() {
</tbody>
</table>
-<a href="{% url nutrition.views.add_meal plan.id %}">{% trans "Add a new meal" %}</a>
+<a href="{% url nutrition.views.add_meal plan.id %}">
+ <img src="{% static 'images/icons/edit.svg' %}"
+ width="16"
+ height="16"
+ alt="{% trans 'Add' %}">
+ {% trans "Add a new meal" %}
+</a>
{% endblock %}
+
+
+
+{% block sidebar %}
+<h3>{% trans "Options" %}</h3>
+<a href="{% url nutrition.views.edit_plan plan.id %}"
+ class="modal-dialog">
+ <img src="{% static 'images/icons/edit.svg' %}"
+ width="32"
+ height="32"
+ alt="{% trans 'Edit nutrition plan' %}">
+ {% trans "Edit nutrition plan" %}
+</a>
+{% endblock %}
\ No newline at end of file
diff --git a/nutrition/urls.py b/nutrition/urls.py
index 6690aac09..746799114 100644
--- a/nutrition/urls.py
+++ b/nutrition/urls.py
@@ -4,6 +4,7 @@ urlpatterns = patterns('nutrition.views',
url(r'^nutrition/overview/$', 'overview'),
url(r'^nutrition/add/$', 'add'),
url(r'^nutrition/(?P<id>\d+)/view/$', 'view'),
+ url(r'^nutrition/(?P<id>\d+)/edit/plan/$', 'edit_plan'),
url(r'^nutrition/(?P<id>\d+)/edit/meal/(?P<meal_id>\w*)$', 'edit_meal'),
url(r'^nutrition/(?P<id>\d+)/add/meal/$', 'add_meal'),
url(r'^nutrition/(?P<id>\d+)/edit/meal/(?P<meal_id>\d+)/item/(?P<item_id>\w*)$', 'edit_meal_item'),
diff --git a/nutrition/views.py b/nutrition/views.py
index 19fd8656b..e4b5e7d56 100644
--- a/nutrition/views.py
+++ b/nutrition/views.py
@@ -32,6 +32,11 @@ from exercises.views import load_language
logger = logging.getLogger('workout_manager.custom')
+class PlanForm(ModelForm):
+ class Meta:
+ model = NutritionPlan
+ exclude=('user', 'language', )
+
@login_required
def overview(request):
template_data = {}
@@ -72,6 +77,39 @@ def view(request, id):
template_data,
context_instance=RequestContext(request))
+@login_required
+def edit_plan(request, id):
+ """Edits a nutrition plan
+ """
+ template_data = {}
+ template_data['active_tab'] = 'nutrition'
+
+ # Load the plan
+ plan = get_object_or_404(NutritionPlan, pk=id, user=request.user)
+ template_data['plan'] = plan
+
+ # Process request
+ if request.method == 'POST':
+ form = PlanForm(request.POST, instance=plan)
+
+ # If the data is valid, save and redirect
+ if form.is_valid():
+ plan = form.save(commit=False)
+ #plan.language = load_language()
+ plan.save()
+
+ return HttpResponseRedirect('/nutrition/%s/view/' % id)
+ else:
+ form = PlanForm(instance=plan)
+ template_data['form'] = form
+
+
+ return render_to_response('edit_plan.html',
+ template_data,
+ context_instance=RequestContext(request))
+
+
+
# ************************
# Meal functions
# ************************