Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Edit/add forms for days for workout

Roland Geiderd18e151dff46
diff --git a/manager/templates/workout/view.html b/manager/templates/workout/view.html
index 4fa5814ed..e92b8ce75 100644
--- a/manager/templates/workout/view.html
+++ b/manager/templates/workout/view.html
@@ -14,7 +14,7 @@
<th>{{ day.description }} (Day-ID: {{ day.id }})</th>
<th style="text-align:right">
<a href="">[x]</a>
- <a href="">[e]</a>
+ <a href="/workout/{{ workout.id}}/edit/day/{{ day.id }}">[e]</a>
</th>
</tr>
</thead>
@@ -75,6 +75,21 @@
{% trans "No days for this workout, use link to add one." %}
</p>
{% endfor %}
-<p><a href="#">{% trans "Add training day" %}</a></p>
+<p><a href="/workout/{{ workout.id}}/edit/day">{% trans "Add training day" %}</a></p>
+
+{% endblock %}
+
+
+<!--
+ Side bar
+-->
+{% block sidebar %}
+<h3>{% trans "Steps" %}</h3>
+<ol>
+ <li>{% trans "Days" %}</li>
+ <li>{% trans "Sets on days" %}</li>
+ <li>{% trans "Exercises on set" %}</li>
+ <li>{% trans "Settings for set" %}</li>
+</ol>
{% endblock %}
\ No newline at end of file
diff --git a/manager/urls.py b/manager/urls.py
index b8ad47f53..9df4c2e91 100644
--- a/manager/urls.py
+++ b/manager/urls.py
@@ -3,10 +3,8 @@ from django.conf.urls import patterns, include, url
urlpatterns = patterns('manager.views',
url(r'^$', 'index'),
url(r'^workout/add$', 'add'),
- url(r'^workout/add/(?P<id>\d+)/step/2$', 'add_step_2'),
- url(r'^workout/add/(?P<id>\d+)/step/3$', 'add_step_3'),
- url(r'^workout/add/(?P<id>\d+)/step/4$', 'add_step_4'),
url(r'^workout/(?P<id>\d+)/view/$', 'view_workout'),
+ url(r'^workout/(?P<id>\d+)/edit/day/(?P<day_id>\d*)$', 'edit_day'),
url(r'^exercise/overview/$', 'exercise_overview'),
url(r'^exercise/view/(?P<id>\d+)$', 'exercise_view'),
url(r'^exercise/view/(?P<id>\d+)/edit/comment/(?P<comment_id>\d+)$', 'exercise_view'),
diff --git a/manager/views.py b/manager/views.py
index 35fc1f575..423f934e6 100644
--- a/manager/views.py
+++ b/manager/views.py
@@ -41,11 +41,6 @@ class WorkoutForm(ModelForm):
class Meta:
model = TrainingSchedule
-class DayForm(ModelForm):
- class Meta:
- model = Day
-
-
def view_workout(request, id):
p = get_object_or_404(TrainingSchedule, pk=id)
return render_to_response('workout/view.html', {'workout': p})
@@ -85,22 +80,45 @@ def add(request):
return render_to_response('workout/add.html', template_data)
-def add_step_2(request):
- template_data = {}
-
- return render_to_response('workout/add.html', template_data)
-def add_step_3(request):
- template_data = {}
-
- return render_to_response('workout/add.html', template_data)
-def add_step_4(request):
+# ************************
+# Day functions
+# ************************
+class DayForm(ModelForm):
+ class Meta:
+ model = Day
+ exclude=('training',)
+
+def edit_day(request, id, day_id=None):
template_data = {}
+ template_data.update(csrf(request))
+
+ # Load workout
+ workout = get_object_or_404(TrainingSchedule, pk=id)
+ template_data['workout'] = workout
+
+ # Load day
+ if not day_id:
+ day = Day()
+ else:
+ day = get_object_or_404(Day, pk=day_id)
+ template_data['day'] = day
+
+ # Process request
+ if request.method == 'POST':
+ day_form = DayForm(request.POST, instance=day)
+ day = day_form.save(commit=False)
+ day.training = workout
+ day.save()
+
+ return HttpResponseRedirect('/workout/%s/view/' % id)
+ else:
+ day_form = DayForm(instance=day)
+ template_data['day_form'] = day_form
+
+ return render_to_response('day/edit.html', template_data)
- return render_to_response('workout/add.html', template_data)
-
-
# ************************
# Exercise comment functions
# ************************
@@ -132,7 +150,6 @@ def exercise_overview(request):
"""Overview with all exercises
"""
-
template_data = {}
ex_data = {}
@@ -167,7 +184,6 @@ def exercise_view(request, id, comment_id=None):
if request.method == 'POST' and not comment_id:
comment_form = ExerciseCommentForm(request.POST)
comment_form.exercise = exercise
- #logger.debug(comment_form.errors)
new_comment = comment_form.save(commit=False)
new_comment.exercise = exercise
new_comment.save()
@@ -207,11 +223,9 @@ def exercise_edit(request, id=None):
exercise = get_object_or_404(Exercise, pk=id)
template_data['exercise'] = exercise
- logger.debug(exercise)
if request.method == 'POST':
exercise_form = ExerciseForm(request.POST, instance=exercise)
exercise = exercise_form.save()
- logger.debug(exercise)
id = exercise.id
return HttpResponseRedirect('/exercise/view/%s' % id)
else: