From 7ffaf1837970840641b03848565ec18edd69dc97 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Fri, 17 Feb 2017 10:27:45 +0100 Subject: [PATCH] created WorkoutComment model --- rowers/models.py | 16 +++ rowers/templates/workout_comments.html | 192 +++++++++++++++++++++++++ rowers/templates/workout_form.html | 2 +- rowers/templates/workout_view.html | 2 +- rowers/urls.py | 1 + rowers/views.py | 23 ++- 6 files changed, 233 insertions(+), 3 deletions(-) create mode 100644 rowers/templates/workout_comments.html diff --git a/rowers/models.py b/rowers/models.py index cc8883d9..af9aa4ff 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -855,6 +855,22 @@ class RowerForm(ModelForm): if an>=max: raise forms.ValidationError("AN should be lower than Max") +# A comment by a user on a training +class WorkoutComment(models.Model): + created = models.DateField(default=timezone.now) + comment = models.TextField(max_length=300) + read = models.BooleanField(default=False) + user = models.ForeignKey(User) + workout = models.ForeignKey(Workout) + +class WorkoutCommentForm(ModelForm): + class Meta: + model = WorkoutComment + fields = ['comment'] + widgets = { + 'comment': forms.Textarea, + } + # An announcement that goes to the right of the workouts list # optionally sends a tweet to our twitter account class SiteAnnouncement(models.Model): diff --git a/rowers/templates/workout_comments.html b/rowers/templates/workout_comments.html new file mode 100644 index 00000000..d87b5cf2 --- /dev/null +++ b/rowers/templates/workout_comments.html @@ -0,0 +1,192 @@ +{% extends "base.html" %} +{% load staticfiles %} +{% load rowerfilters %} +{% load tz %} + +{% block title %}Change Workout {% endblock %} + +{% block content %} +
+ + {% if form.errors %} +

+ Please correct the error{{ form.errors|pluralize }} below. +

+ {% endif %} + +

Comments {{ workout.name }}

+ +{% localtime on %} + + + + + + + + + + + + + + +
Rower:{{ first_name }} {{ last_name }}
Date/Time:{{ workout.startdatetime }}
Distance:{{ workout.distance }}m
Duration:{{ workout.duration |durationprint:"%H:%M:%S.%f" }}
Public link to this workout + https://rowsandall.com/rowers/workout/{{ workout.id }} + +
Public link to interactive chart + https://rowsandall.com/rowers/workout/{{ workout.id }}/interactiveplot + +
+{% endlocaltime %} +
+ + {{ form.as_table }} +
+ {% csrf_token %} +
+ +
+
+
+
+

Images linked to this workout

+
+
+

+ Add Time Plot +

+
+ +
+

+ Add Pie Chart +

+
+
+ +
+

+ Power Pie Chart +

+
+
+

Generating images takes roughly 1 second per minute + of your workout's duration. Please reload after a minute or so.

+
+
+ {% if graphs1 %} + + {% for graph in graphs1 %} + {% if forloop.counter == 1 %} +
+ + {{ graph.filename }} +
+ {% elif forloop.counter == 3 %} +
+ + {{ graph.filename }} +
+ + {% else %} +
+ + {{ graph.filename }} +
+ {% endif %} + {% endfor %} + + + {% for graph in graphs2 %} + {% if forloop.counter == 1 %} +
+ + {{ graph.filename }} +
+ {% elif forloop.counter == 3 %} +
+ + {{ graph.filename }} +
+ + {% else %} +
+ + {{ graph.filename }} +
+ {% endif %} + {% endfor %} + + + + + {% else %} +

No graphs found

+ {% endif %} +
+ + + +
+

Workout Summary

+ +

+

+{{ workout.summary }}
+
+

+ + +
+ + + +
+ + + + {{ gmscript |safe }} + + +
+ {{ gmdiv|safe }} +
+
+ +{% endblock %} diff --git a/rowers/templates/workout_form.html b/rowers/templates/workout_form.html index 356a245a..e47136e8 100644 --- a/rowers/templates/workout_form.html +++ b/rowers/templates/workout_form.html @@ -14,7 +14,7 @@

{% endif %} -

Edit Workout Data

+

Edit Workout {{ workout.name }}

diff --git a/rowers/templates/workout_view.html b/rowers/templates/workout_view.html index 2bee8359..3bbb4d4b 100644 --- a/rowers/templates/workout_view.html +++ b/rowers/templates/workout_view.html @@ -8,7 +8,7 @@

-

Workout Data

+

{{ workout.name }}

diff --git a/rowers/urls.py b/rowers/urls.py index 37ec074b..e54bbac2 100644 --- a/rowers/urls.py +++ b/rowers/urls.py @@ -148,6 +148,7 @@ urlpatterns = [ url(r'^workout/(?P\d+)/export/c/(?P\w+.*)$',views.workout_export_view), url(r'^workout/(?P\d+)/export/s/(?P\w+.*)$',views.workout_export_view), url(r'^workout/(?P\d+)/export$',views.workout_export_view), + url(r'^workout/(?P\d+)/comment$',views.workout_comment_view), url(r'^workout/(\d+)/emailtcx$',views.workout_tcxemail_view), url(r'^workout/(\d+)/emailcsv$',views.workout_csvemail_view), url(r'^workout/compare/(\d+)/$',views.workout_comparison_list), diff --git a/rowers/views.py b/rowers/views.py index 9250f6c0..43cfea8b 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -32,7 +32,8 @@ from rowers.models import Workout, User, Rower, WorkoutForm,FavoriteChart from rowers.models import ( RowerPowerForm,RowerForm,GraphImage,AdvancedWorkoutForm, RowerPowerZonesForm,AccountRowerForm,UserForm,StrokeData, - Team,TeamForm,TeamInviteForm,TeamInvite,TeamRequest + Team,TeamForm,TeamInviteForm,TeamInvite,TeamRequest, + WorkoutComment,WorkoutCommentForm ) from rowers.models import FavoriteForm,BaseFavoriteFormSet,SiteAnnouncement from django.forms.formsets import formset_factory @@ -3314,6 +3315,26 @@ def workout_export_view(request,id=0, message="", successmessage=""): 'successmessage':successmessage, }) +# list of comments to a workout +@login_required() +def workout_comment_view(request,id=0): + try: + w = Workout.objects.get(id=id) + except Workout.DoesNotExist: + raise Http404("Workout doesn't exist") + + if w.privacy == 'private' and w.user.user != request.user: + return HttpResponseForbidden("Permission error") + + # ok we're permitted + comments = WorkoutComment.objects.filter(workout=w) + + return render(request, + 'workout_comments.html', + {'workout':w, + 'comments':comments, + }) + # The basic edit page @login_required() def workout_edit_view(request,id=0,message="",successmessage=""):
Rower:{{ first_name }} {{ last_name }}