comment notifications
This commit is contained in:
@@ -891,6 +891,7 @@ class WorkoutComment(models.Model):
|
||||
comment = models.TextField(max_length=300)
|
||||
created = models.DateTimeField(default=timezone.now)
|
||||
read = models.BooleanField(default=False)
|
||||
notification = models.BooleanField(default=False,verbose_name="Send me notifications")
|
||||
user = models.ForeignKey(User)
|
||||
workout = models.ForeignKey(Workout)
|
||||
|
||||
@@ -905,7 +906,7 @@ class WorkoutComment(models.Model):
|
||||
class WorkoutCommentForm(ModelForm):
|
||||
class Meta:
|
||||
model = WorkoutComment
|
||||
fields = ['comment',]
|
||||
fields = ['comment','notification']
|
||||
widgets = {
|
||||
'comment': forms.Textarea,
|
||||
}
|
||||
|
||||
@@ -273,6 +273,37 @@ def handle_sendemail_invite(email,name,code,teamname,manager):
|
||||
|
||||
return 1
|
||||
|
||||
@app.task
|
||||
def handle_sendemailnewresponse(first_name,last_name,
|
||||
email,
|
||||
commenter_first_name,
|
||||
commenter_last_name,
|
||||
comment,
|
||||
workoutname,workoutid,commentid):
|
||||
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 the 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'
|
||||
message += '\n\n'
|
||||
message += 'You are receiving this email because you are subscribed '
|
||||
message += 'to comments on this workout. To unsubscribe, follow this link:\n'
|
||||
message += 'https://rowsandall.com/rowers/workout/unsubscribe/'+str(workoutid)+'/'
|
||||
|
||||
email = EmailMessage(subject, message,
|
||||
'Rowsandall <info@rowsandall.com>',
|
||||
[fullemail])
|
||||
|
||||
|
||||
res = email.send()
|
||||
|
||||
return 1
|
||||
|
||||
@app.task
|
||||
def handle_sendemailnewcomment(first_name,
|
||||
last_name,
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
{% endfor %}
|
||||
|
||||
<div id="form" class="grid_6 alpha">
|
||||
<form enctype="multipart/form-data" action="" method="post">
|
||||
<form enctype="multipart/form-data" action="/rowers/workout/{{ workout.id }}/comment" method="post">
|
||||
<table width=100%>
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
|
||||
@@ -151,6 +151,7 @@ urlpatterns = [
|
||||
url(r'^workout/upload/(.+.*)$',views.workout_upload_view),
|
||||
url(r'^workout/(?P<id>\d+)/histo$',views.workout_histo_view),
|
||||
url(r'^workout/(?P<id>\d+)/forcecurve$',views.workout_forcecurve_view),
|
||||
url(r'^workout/(?P<id>\d+)/unsubscribe$',views.workout_unsubscribe_view),
|
||||
url(r'^workout/(?P<id>\d+)/export/c/(?P<message>\w+.*)/s/(?P<successmessage>\w+.*)$',views.workout_export_view),
|
||||
url(r'^workout/(?P<id>\d+)/export/c/(?P<message>\w+.*)$',views.workout_export_view),
|
||||
url(r'^workout/(?P<id>\d+)/export/s/(?P<successmessage>\w+.*)$',views.workout_export_view),
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -799,9 +799,10 @@ a.wh:hover {
|
||||
|
||||
/* talk bubble contents */
|
||||
.talktext{
|
||||
padding: 1em;
|
||||
text-align: left;
|
||||
line-height: 1.5em;
|
||||
padding: 1em;
|
||||
text-align: left;
|
||||
line-height: 1.5em;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
.talktext p{
|
||||
/* remove webkit p margins */
|
||||
|
||||
Reference in New Issue
Block a user