comment notifications
This commit is contained in:
@@ -891,6 +891,7 @@ class WorkoutComment(models.Model):
|
|||||||
comment = models.TextField(max_length=300)
|
comment = models.TextField(max_length=300)
|
||||||
created = models.DateTimeField(default=timezone.now)
|
created = models.DateTimeField(default=timezone.now)
|
||||||
read = models.BooleanField(default=False)
|
read = models.BooleanField(default=False)
|
||||||
|
notification = models.BooleanField(default=False,verbose_name="Send me notifications")
|
||||||
user = models.ForeignKey(User)
|
user = models.ForeignKey(User)
|
||||||
workout = models.ForeignKey(Workout)
|
workout = models.ForeignKey(Workout)
|
||||||
|
|
||||||
@@ -905,7 +906,7 @@ class WorkoutComment(models.Model):
|
|||||||
class WorkoutCommentForm(ModelForm):
|
class WorkoutCommentForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = WorkoutComment
|
model = WorkoutComment
|
||||||
fields = ['comment',]
|
fields = ['comment','notification']
|
||||||
widgets = {
|
widgets = {
|
||||||
'comment': forms.Textarea,
|
'comment': forms.Textarea,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -273,6 +273,37 @@ def handle_sendemail_invite(email,name,code,teamname,manager):
|
|||||||
|
|
||||||
return 1
|
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
|
@app.task
|
||||||
def handle_sendemailnewcomment(first_name,
|
def handle_sendemailnewcomment(first_name,
|
||||||
last_name,
|
last_name,
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
<div id="form" class="grid_6 alpha">
|
<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%>
|
<table width=100%>
|
||||||
{{ form.as_table }}
|
{{ form.as_table }}
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -151,6 +151,7 @@ urlpatterns = [
|
|||||||
url(r'^workout/upload/(.+.*)$',views.workout_upload_view),
|
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+)/histo$',views.workout_histo_view),
|
||||||
url(r'^workout/(?P<id>\d+)/forcecurve$',views.workout_forcecurve_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+.*)/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/c/(?P<message>\w+.*)$',views.workout_export_view),
|
||||||
url(r'^workout/(?P<id>\d+)/export/s/(?P<successmessage>\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.rows import handle_uploaded_file
|
||||||
from rowers.tasks import handle_makeplot,handle_otwsetpower,handle_sendemailtcx,handle_sendemailcsv
|
from rowers.tasks import handle_makeplot,handle_otwsetpower,handle_sendemailtcx,handle_sendemailcsv
|
||||||
from rowers.tasks import (
|
from rowers.tasks import (
|
||||||
handle_sendemail_unrecognized,handle_sendemailnewcomment
|
handle_sendemail_unrecognized,handle_sendemailnewcomment,
|
||||||
|
handle_sendemailnewresponse,
|
||||||
)
|
)
|
||||||
|
|
||||||
from scipy.signal import savgol_filter
|
from scipy.signal import savgol_filter
|
||||||
@@ -3586,6 +3587,37 @@ def workout_export_view(request,id=0, message="", successmessage=""):
|
|||||||
'successmessage':successmessage,
|
'successmessage':successmessage,
|
||||||
'c2userid':c2userid,
|
'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
|
# list of comments to a workout
|
||||||
@login_required()
|
@login_required()
|
||||||
@@ -3597,6 +3629,8 @@ def workout_comment_view(request,id=0):
|
|||||||
|
|
||||||
if w.privacy == 'private' and w.user.user != request.user:
|
if w.privacy == 'private' and w.user.user != request.user:
|
||||||
return HttpResponseForbidden("Permission error")
|
return HttpResponseForbidden("Permission error")
|
||||||
|
|
||||||
|
comments = WorkoutComment.objects.filter(workout=w).order_by("created")
|
||||||
|
|
||||||
# ok we're permitted
|
# ok we're permitted
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
@@ -3604,7 +3638,9 @@ def workout_comment_view(request,id=0):
|
|||||||
form = WorkoutCommentForm(request.POST)
|
form = WorkoutCommentForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
cd = form.cleaned_data
|
cd = form.cleaned_data
|
||||||
comment = cd['comment']
|
comment = cd['comment']
|
||||||
|
notification = cd['notification']
|
||||||
|
c = WorkoutComment(workout=w,user=request.user,comment=comment,
|
||||||
notification=notification)
|
notification=notification)
|
||||||
c.save()
|
c.save()
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
@@ -3615,6 +3651,7 @@ def workout_comment_view(request,id=0):
|
|||||||
request.user.last_name,
|
request.user.last_name,
|
||||||
comment,w.name,
|
comment,w.name,
|
||||||
w.id)
|
w.id)
|
||||||
|
|
||||||
|
|
||||||
elif request.user != r.user:
|
elif request.user != r.user:
|
||||||
res = queuehigh.enqueue(handle_sendemailnewcomment,r.user.first_name,
|
res = queuehigh.enqueue(handle_sendemailnewcomment,r.user.first_name,
|
||||||
@@ -3623,8 +3660,29 @@ def workout_comment_view(request,id=0):
|
|||||||
request.user.first_name,
|
request.user.first_name,
|
||||||
request.user.last_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)
|
c.id)
|
||||||
|
|
||||||
form = WorkoutCommentForm()
|
form = WorkoutCommentForm()
|
||||||
|
|||||||
@@ -799,9 +799,10 @@ a.wh:hover {
|
|||||||
|
|
||||||
/* talk bubble contents */
|
/* talk bubble contents */
|
||||||
.talktext{
|
.talktext{
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
line-height: 1.5em;
|
line-height: 1.5em;
|
||||||
|
word-wrap: break-word;
|
||||||
}
|
}
|
||||||
.talktext p{
|
.talktext p{
|
||||||
/* remove webkit p margins */
|
/* remove webkit p margins */
|
||||||
|
|||||||
Reference in New Issue
Block a user