def comment_publish(request, topic_id, pk=None): topic = get_object_or_404(Topic.objects.for_access_open(request.user), pk=topic_id) if request.method == 'POST': form = CommentForm(user=request.user, topic=topic, data=request.POST) if not request.is_limited and form.is_valid(): comment = form.save() comment_posted.send(sender=comment.__class__, comment=comment, mentions=form.mentions) return redirect( request.POST.get('next', comment.get_absolute_url())) else: initial = None if pk: comment = get_object_or_404(Comment.objects.for_all(), pk=pk) quote = markdown.quotify(comment.comment, comment.user.username) initial = { 'comment': quote, } form = CommentForm(initial=initial) return render(request, 'spirit/comment/comment_publish.html', { 'form': form, 'topic': topic })
def test_markdown_quote(self): """ markdown quote """ comment = u"text\nnew line" quote = quotify(comment, self.user) self.assertListEqual(quote.splitlines(), (u"@%s\n> text\n> new line\n\n" % self.user.username).splitlines())
def test_comment_publish_quote(self): """ create comment quote """ utils.login(self) comment = utils.create_comment(topic=self.topic) response = self.client.get(reverse('spirit:comment-publish', kwargs={'topic_id': self.topic.pk, 'pk': comment.pk})) self.assertEqual(response.context['form'].initial['comment'], markdown.quotify(comment.comment, comment.user.username))
def test_markdown_quote_header_language(self): """ markdown quote "@user said:" should keep the default language (settings.LANGUAGE_CODE) """ comment = "" quote = quotify(comment, self.user) with translation.override('es'): self.assertListEqual(quote.splitlines(), ("> @%s said:\n> \n\n" % self.user.username).splitlines())
def comment_publish(request, topic_id, pk=None): topic = Topic.objects.for_access_or_404(pk=topic_id, user=request.user) if request.method == 'POST': form = CommentForm(user=request.user, topic=topic, data=request.POST) if not request.is_limited and form.is_valid(): comment = form.save() comment_posted.send(sender=comment.__class__, comment=comment, mentions=form.mentions) return redirect(request.POST.get('next', comment.get_absolute_url())) else: initial = None if pk: comment = get_object_or_404(Comment.objects.for_all(), pk=pk) quote = markdown.quotify(comment.comment, comment.user.username) initial = {'comment': quote, } form = CommentForm(initial=initial) return render(request, 'spirit/comment/comment_publish.html', {'form': form, 'topic': topic})