From cee6179416cc9f855cbbbed35aee1ff49e30fbca Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Fri, 17 Feb 2017 16:35:34 +0100 Subject: [PATCH] added comment functionality --- rowers/tasks.py | 29 ++++++++++++++++++++++++++ rowers/templates/workout_comments.html | 4 ---- rowers/templates/workout_form.html | 10 +++++++-- rowers/templates/workout_view.html | 6 ++++++ rowers/views.py | 24 +++++++++++++++++++-- 5 files changed, 65 insertions(+), 8 deletions(-) diff --git a/rowers/tasks.py b/rowers/tasks.py index 055dd524..e0367862 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -273,6 +273,35 @@ def handle_sendemail_invite(email,name,code,teamname,manager): return 1 +@app.task +def handle_sendemailnewcomment(first_name, + last_name, + email, + commenter_first_name, + commenter_last_name, + comment,workoutname, + workoutid): + fullemail = first_name+' '+last_name+' <'+email+'>' + subject = 'New comment on workout '+workoutname + message = 'Dear '+first_name+',\n\n' + message += commenter_first_name+' '+commenter_last_name + message += ' has written a new comment on your workout ' + message += workoutname+'\n\n' + message += comment + message += '\n\n' + message += 'You can read the comment here:\n' + message += 'https://rowsandall.com/rowers/workout/'+str(workoutid)+'/comment' + + email = EmailMessage(subject, message, + 'Rowsandall ', + [fullemail]) + + + res = email.send() + + return 1 + + @app.task def handle_sendemail_request(email,name,code,teamname,requestor,id): fullemail = name+' <'+email+'>' diff --git a/rowers/templates/workout_comments.html b/rowers/templates/workout_comments.html index fec9ab39..438388a5 100644 --- a/rowers/templates/workout_comments.html +++ b/rowers/templates/workout_comments.html @@ -6,10 +6,6 @@ {% block title %}Change Workout {% endblock %} {% block content %} - -
{% if form.errors %} diff --git a/rowers/templates/workout_form.html b/rowers/templates/workout_form.html index e47136e8..9c611295 100644 --- a/rowers/templates/workout_form.html +++ b/rowers/templates/workout_form.html @@ -54,8 +54,14 @@ Public link to this workout - https://rowsandall.com/rowers/workout/{{ workout.id }} - + https://rowsandall.com/rowers/workout/{{ workout.id }} + + + Comments + + Comment + + Public link to interactive chart diff --git a/rowers/templates/workout_view.html b/rowers/templates/workout_view.html index 3bbb4d4b..38f0687e 100644 --- a/rowers/templates/workout_view.html +++ b/rowers/templates/workout_view.html @@ -29,6 +29,12 @@ Weight Category:{{ workout.weightcategory }} + + Comments + + Comment + +

Workout Summary

diff --git a/rowers/views.py b/rowers/views.py index ae25f132..950e810f 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -59,7 +59,9 @@ from rest_framework.renderers import JSONRenderer from rest_framework.parsers import JSONParser from rowers.rows import handle_uploaded_file from rowers.tasks import handle_makeplot,handle_otwsetpower,handle_sendemailtcx,handle_sendemailcsv -from rowers.tasks import handle_sendemail_unrecognized +from rowers.tasks import ( + handle_sendemail_unrecognized,handle_sendemailnewcomment + ) from scipy.signal import savgol_filter from django.shortcuts import render_to_response @@ -3328,13 +3330,31 @@ def workout_comment_view(request,id=0): # ok we're permitted if request.method == 'POST': + r = w.user form = WorkoutCommentForm(request.POST) if form.is_valid(): cd = form.cleaned_data comment = cd['comment'] c = WorkoutComment(workout=w,user=request.user,comment=comment) c.save() - + if settings.DEBUG: + res = handle_sendemailnewcomment.delay(r.user.first_name, + r.user.last_name, + r.user.email, + c.user.first_name, + c.user.last_name, + comment,w.name, + w.id) + + else: + res = queuehigh.enqueue(handle_sendemailnewcomment,r.user.first_name, + r.user.last_name, + r.user.email, + r.user.first_name, + r.user.last_name, + comment,w.name,w.id) + + comments = WorkoutComment.objects.filter(workout=w).order_by("created") form = WorkoutCommentForm()