def test_comment_history_comment_pre_update_handler(self): """ comment_pre_update_handler signal """ comment = utils.create_comment(topic=self.topic) comment_pre_update.send(sender=comment.__class__, comment=comment) self.assertEqual(CommentHistory.objects.get(comment_fk=comment.pk).comment_html, comment.comment_html) self.assertEqual(len(CommentHistory.objects.filter(comment_fk=comment.pk)), 1) comment_pre_update.send(sender=comment.__class__, comment=comment) self.assertEqual(len(CommentHistory.objects.filter(comment_fk=comment.pk)), 1)
def comment_update(request, pk): comment = Comment.objects.for_update_or_404(pk, request.user) if request.method == 'POST': form = CommentForm(data=request.POST, instance=comment) if form.is_valid(): comment_pre_update.send(sender=comment.__class__, comment=Comment.objects.get(pk=comment.pk)) comment = form.save() comment_post_update.send(sender=comment.__class__, comment=comment) return redirect(request.POST.get('next', comment.get_absolute_url())) else: form = CommentForm(instance=comment) return render(request, 'spirit/comment/comment_update.html', {'form': form, })
def comment_update(request, pk): comment = Comment.objects.for_update_or_404(pk, request.user) if request.method == 'POST': form = CommentForm(data=request.POST, instance=comment) if form.is_valid(): comment_pre_update.send(sender=comment.__class__, comment=Comment.objects.get(pk=comment.pk)) comment = form.save() comment_post_update.send(sender=comment.__class__, comment=comment) return redirect( request.POST.get('next', comment.get_absolute_url())) else: form = CommentForm(instance=comment) return render(request, 'spirit/comment/comment_update.html', { 'form': form, })