Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add functionality to add comments to exercises

Roland Geider25f549661c9c
diff --git a/manager/templates/exercise/edit.html b/manager/templates/exercise/edit.html
index cdd9ebbd9..e4949a22c 100644
--- a/manager/templates/exercise/edit.html
+++ b/manager/templates/exercise/edit.html
@@ -13,9 +13,9 @@
-->
{% block content %}
-<h2>{% trans "Edit" %} {{ exersise.name }}</h2>
+<h2>{% trans "Edit" %} {{ exercise.name }}</h2>
-<p>Edit exersise</p>
+<p>Edit exercise</p>
{% endblock %}
diff --git a/manager/templates/exercise/view.html b/manager/templates/exercise/view.html
index 803d57e67..3de4fa810 100644
--- a/manager/templates/exercise/view.html
+++ b/manager/templates/exercise/view.html
@@ -13,19 +13,28 @@
-->
{% block content %}
-<h2>{{ exersise.name }}</h2>
+<h2>{{ exercise.name }}</h2>
-<p><a href="/exercise/edit/{{ exersise.id }}">{% trans "Edit" %}</a></p>
+<p><a href="/exercise/edit/{{ exercise.id }}">{% trans "Edit" %}</a></p>
-<p>{% trans "All comments for this exersise" %}</p>
+<p>{% trans "All comments for this exercise" %}</p>
+
+<form action="/exercise/view/{{ exercise.id }}" method="post">
+<div style="display:none">
+ <input type="hidden" value="{{ exercise.id }}" name="exercise">
+</div>
+{% csrf_token %}
+{{ comment_form.as_p }}
+<input type="submit" value="Submit" />
+</form>
<p><em>Form to add comment goes here</em></p>
<ul>
-{% for comment in exersise.exercisecomment_set.all %}
+{% for comment in exercise.exercisecomment_set.all %}
<li>{{ comment }}</li>
{% empty %}
- <li>{% trans "Sorry, no comments for this exersise yet!" %}</li>
+ <li>{% trans "Sorry, no comments for this exercise yet!" %}</li>
{% endfor %}
</ul>
diff --git a/manager/views.py b/manager/views.py
index a828a708d..de77fbdbf 100644
--- a/manager/views.py
+++ b/manager/views.py
@@ -23,6 +23,7 @@ from django.core.context_processors import csrf
from manager.models import TrainingSchedule
from manager.models import Exercise
+from manager.models import ExerciseComment
logger = logging.getLogger('workout_manager.custom')
@@ -86,10 +87,15 @@ def add_step_4(request):
# Exercise functions
# ************************
+class ExerciseCommentForm(ModelForm):
+ class Meta:
+ model = ExerciseComment
+
def exercise_overview(request):
"""Overview with all exercises
"""
+
template_data = {}
ex_data = {}
@@ -107,9 +113,35 @@ def exercise_overview(request):
def exercise_view(request, id):
- exersise = get_object_or_404(Exercise, pk=id)
- return render_to_response('exercise/view.html', {'exersise': exersise})
+ """ Detail view for an exercise
+ """
+ template_data = {}
+
+ # Load the exercise itself
+ exercise = get_object_or_404(Exercise, pk=id)
+ template_data['exercise'] = exercise
+
+ # We can create comments from this page, so look for Posts
+ template_data.update(csrf(request))
+ if request.method == 'POST':
+
+ comment_form = ExerciseCommentForm(request.POST)
+ comment_form.exercise = exercise
+ #logger.debug(comment_form)
+ #logger.debug(comment_form.errors)
+ new_comment = comment_form.save(commit=False)
+ new_comment.exercise = exercise
+ new_comment.save()
+ return HttpResponseRedirect('/exercise/view/%s' % id)
+ else:
+ comment_form = WorkoutForm()
+
+ template_data['comment_form'] = comment_form
+
+ # Render
+ return render_to_response('exercise/view.html', template_data)
+
def exercise_edit(request, id):
- exersise = get_object_or_404(Exercise, pk=id)
- return render_to_response('exercise/edit.html', {'exersise': exersise})
\ No newline at end of file
+ exercise = get_object_or_404(Exercise, pk=id)
+ return render_to_response('exercise/edit.html', {'exercise': exercise})
\ No newline at end of file