def get_comments_for_object(context, object, next=None): ct = ContentType.objects.get_for_model(object) if ct.id not in CONTENT_TYPES: return "Not supported" comments = api.get_comments(ct.id, object.pk) comments = comments.order_by("-submit_date") initial = {"content_type": ct.id, "object_pk": object.pk, "next": next} form = CommentForm(object, initial=initial) context.update({"comments": comments, "form": form}) return render_to_string("tcc/list-comments.html", context_instance=context)
def test_basic(self): ct = ContentType.objects.get_for_model(self.user1) pk = self.user1.pk c = api.post_comment(content_type_id=ct.id, object_pk=pk, user_id=pk, comment="Root message") self.assertTrue(c is not None) comments = api.get_comments(ct.id, pk) self.assertEqual(len(comments), 1) comment = api.get_comment(c.id) self.assertTrue(comment is not None) self.assertEqual(comment.id, c.id) comment = api.get_comment(-1) self.assertTrue(comment is None)