Private
Public Access
1
0

comment notifications

This commit is contained in:
Sander Roosendaal
2017-02-23 12:13:55 +01:00
parent edf9709fa2
commit 27acec196a
6 changed files with 101 additions and 9 deletions

View File

@@ -60,7 +60,8 @@ 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,handle_sendemailnewcomment
handle_sendemail_unrecognized,handle_sendemailnewcomment,
handle_sendemailnewresponse,
)
from scipy.signal import savgol_filter
@@ -3586,6 +3587,37 @@ def workout_export_view(request,id=0, message="", successmessage=""):
'successmessage':successmessage,
'c2userid':c2userid,
})
#
@login_required()
def workout_unsubscribe_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")
comments = WorkoutComment.objects.filter(workout=w,
user=request.user).order_by("created")
for c in comments:
c.notify = False
c.save()
form = WorkoutCommentForm()
message = 'You have been unsubscribed from new comment notifications for this workout'
return render(request,
'workout_comments.html',
{'workout':w,
'comments':comments,
'successmessage':message,
'form':form,
})
# list of comments to a workout
@login_required()
@@ -3597,6 +3629,8 @@ def workout_comment_view(request,id=0):
if w.privacy == 'private' and w.user.user != request.user:
return HttpResponseForbidden("Permission error")
comments = WorkoutComment.objects.filter(workout=w).order_by("created")
# ok we're permitted
if request.method == 'POST':
@@ -3604,7 +3638,9 @@ def workout_comment_view(request,id=0):
form = WorkoutCommentForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
comment = cd['comment']
comment = cd['comment']
notification = cd['notification']
c = WorkoutComment(workout=w,user=request.user,comment=comment,
notification=notification)
c.save()
if settings.DEBUG:
@@ -3615,6 +3651,7 @@ def workout_comment_view(request,id=0):
request.user.last_name,
comment,w.name,
w.id)
elif request.user != r.user:
res = queuehigh.enqueue(handle_sendemailnewcomment,r.user.first_name,
@@ -3622,9 +3659,30 @@ def workout_comment_view(request,id=0):
r.user.email,
request.user.first_name,
request.user.last_name,
comment,w.name,w.id)
comment,w.name,w.id)
commenters = {oc.user for oc in comments if oc.notification}
for u in commenters:
if settings.DEBUG:
res = handle_sendemailnewresponse.delay(u.first_name,
u.last_name,
u.email,
request.user.first_name,
request.user.last_name,
comment,
w.name,
w.id,
c.id)
else:
res = queuelow.enqueue(handle_sendemailnewresponse,
u.first_name,
u.last_name,
u.email,
request.user.first_name,
request.user.last_name,
comment,
w.name,
w.id,
c.id)
form = WorkoutCommentForm()