User action logging for discussions

This commit is contained in:
Evert Prants 2018-03-05 14:04:20 +02:00
parent 5d3e81fe78
commit ed696a99f5
Signed by: evert
GPG Key ID: 1688DA83D222D0B5

View File

@ -28,7 +28,7 @@ from django.utils.text import slugify
from guardian.decorators import permission_required_or_403
from LandingPage.models import Show, DiscussionBoard, DiscussionReply, DiscussionVote, Ban, Report
from LandingPage.models import Show, DiscussionBoard, DiscussionReply, DiscussionVote, Ban, Report, UserAction
from . import forms
import datetime
@ -176,6 +176,9 @@ def BoardForm(req, abbr):
new_post = DiscussionReply(user=user,board=new_board,body=form_data['body'])
new_post.save()
act = UserAction(user=user,show=show,act_type=0,url='%s/discuss/board/%d-%s'%(show.url(), new_board.pk, slugify(form_data['title'])))
act.save()
return HttpResponseRedirect(show.url() + '/discuss/board/%d-%s'%(new_board.pk, slugify(form_data['title'])))
else:
ctx['error'] = 'Invalid fields!'
@ -227,13 +230,15 @@ def BoardReplyForm(req, abbr, bid):
if err_res:
return render(req, "board_reply.html", ctx)
print(form_data['body'])
new_reply = form.save(commit=False)
new_reply.user = user
new_reply.board = board
new_reply.save()
act = UserAction(user=user,show=show,act_type=1,url='%s/discuss/board/%d-%s?findReply=%d'%(show.url(), new_board.pk, slugify(form_data['title']), new_reply.pk))
act.save()
return HttpResponseRedirect(show.url() + '/discuss/board/%d-%s?findReply=%d'%(board.pk, slugify(board.title), new_reply.pk))
else:
ctx['error'] = 'Invalid fields!'
@ -273,6 +278,10 @@ class BoardVoteSubmit(LoginRequiredMixin, View):
if not vote.positive == pos_bool:
vote.positive = pos_bool
vote.save()
act = UserAction(user=user,show=show,act_type=6 + int(positive),url='%s/discuss/board/%d-%s?findReply=%d'%(showurl,
reply.board.pk, slugify(reply.board.title), reply.pk))
act.save()
else:
vote.delete()
else:
@ -283,6 +292,10 @@ class BoardVoteSubmit(LoginRequiredMixin, View):
)
new_vote.save()
act = UserAction(user=user,show=show,act_type=6 + int(positive),url='%s/discuss/board/%d-%s?findReply=%d'%(showurl, reply.board.pk,
slugify(reply.board.title), reply.pk))
act.save()
return HttpResponseRedirect('%s/discuss/board/%d-%s?findReply=%d'%(showurl, reply.board.pk, slugify(reply.board.title), reply.pk))
@login_required
@ -368,6 +381,9 @@ def BoardDelete(req, abbr, bid):
board = get_object_or_404(DiscussionBoard, pk=bid)
showurl = get_show_url(abbr)
act = UserAction(user=req.user,show=board.show,act_type=4,url='#%s by %s'%(board.title, board.user.display_name))
act.save()
DiscussionBoard.objects.filter(pk=board.pk).delete()
return HttpResponseRedirect('%s/discuss' % (board.show.url()))
@ -376,8 +392,12 @@ def BoardDelete(req, abbr, bid):
def BoardDeleteReply(req, abbr, rid):
reply = get_object_or_404(DiscussionReply, pk=rid)
act = UserAction(user=req.user,show=reply.board.show,act_type=4,url='%s/discuss/board/%d-%s?findReply=%d'%(reply.board.show.url(),
reply.board.pk, slugify(reply.board.title), reply.pk))
act.save()
delete = not reply.deleted
DiscussionReply.objects.filter(pk=reply.pk).update(deleted=delete)
return HttpResponseRedirect('%s/discuss/board/%d-%s'%(reply.show.url(), reply.board.pk, slugify(reply.board.title)))
return HttpResponseRedirect('%s/discuss/board/%d-%s'%(reply.board.show.url(), reply.board.pk, slugify(reply.board.title)))