Ejemplo n.º 1
0
 def test_post_comment(self):
     ct = ContentType.objects.get_for_model(self.user1)
     pk = self.user1.pk
     p = api.post_comment(content_type_id=ct.id,
                          object_pk=pk,
                          user_id=pk,
                          comment="Root message")
     self.assertEqual(p.path, u'1'.zfill(settings.STEPLEN))
     c = api.post_comment(content_type_id=ct.id,
                          object_pk=pk,
                          user_id=pk,
                          comment="Reply",
                          parent_id=p.id)
     self.assertEqual(
         c.path,
         u'1'.zfill(settings.STEPLEN) + u'2'.zfill(settings.STEPLEN))
     self.assertEqual(c.get_parents()[0].id, p.id)
     self.assertEqual(len(p.get_parents()), 0)
     self.assertEqual(p.get_replies()[0].id, c.id)
     self.assertEqual(len(c.get_replies()), 0)
     self.assertEqual(api.get_comment_replies(p.id)[0].id, c.id)
     self.assertEqual(api.get_comment_parents(c.id)[0].id, p.id)
     tp = api.get_comment_thread(p.id)
     tc = api.get_comment_thread(c.id)
     self.assertEqual(len(tp), 2)
     self.assertEqual(len(tc), 2)
     # Non existing parent
     c = api.post_comment(content_type_id=ct.id,
                          object_pk=pk,
                          user_id=pk,
                          comment="Reply",
                          parent_id=-1)
     self.assertEqual(c, None)
Ejemplo n.º 2
0
   def test_post_reply(self):
       ct = ContentType.objects.get_for_model(self.user1)
       pk = self.user1.pk
       p = api.post_comment(content_type_id=ct.id, object_pk=pk,
                            user_id=pk, comment="Root message")
       self.assertEqual(p.path,  u'1'.zfill(settings.STEPLEN))
       c = api.post_reply(user_id=pk, comment="Reply", parent_id=p.id)
       self.assertEqual(c.path,  u'1'.zfill(settings.STEPLEN)+u'2'.zfill(settings.STEPLEN))
       self.assertEqual(c.get_parents()[0].id, p.id)
       self.assertEqual(p.get_replies()[0].id, c.id)
       tp = api.get_comment_thread(p.id)
       tc = api.get_comment_thread(c.id)
       self.assertEqual(len(tp), 2)
       self.assertEqual(len(tc), 2)
 # Non existing parent
       c = api.post_reply(user_id=pk, comment="Reply", parent_id=-1)
       self.assertEqual(c, None)
Ejemplo n.º 3
0
def thread(request, thread_id):
    # thead_id here should be the root_id of the thread (even though
    # any comment_id will work) so the entire thread can cached *and*
    # invalidated with one entry
    comments = api.get_comment_thread(thread_id)
    if not comments:
        raise Http404()
    rootcomment = comments[0]
    form = _get_comment_form(rootcomment.content_type_id, rootcomment.object_pk)
    context = RequestContext(request, {"comments": comments, "form": form})
    return render_to_response("tcc/index.html", context)
Ejemplo n.º 4
0
def thread(request, thread_id):
  # thead_id here should be the root_id of the thread (even though
  # any comment_id will work) so the entire thread can cached *and*
  # invalidated with one entry
    comments = api.get_comment_thread(thread_id)
    if not comments:
        raise Http404()
    else:
        comments = comments.order_by('-sort_date', 'path')
    rootcomment = comments[0]
    form = _get_comment_form(rootcomment.content_type_id, rootcomment.object_pk)
    context = RequestContext(request, {'comments': comments, 'form': form})
    return render_to_response('tcc/index.html', context)
Ejemplo n.º 5
0
def thread(request, thread_id):
    # thead_id here should be the root_id of the thread (even though
    # any comment_id will work) so the entire thread can cached *and*
    # invalidated with one entry
    comments = api.get_comment_thread(thread_id)
    if not comments:
        raise Http404()
    else:
        comments = comments.order_by('-sort_date', 'path')
    rootcomment = comments[0]
    form = _get_comment_form(rootcomment.content_type_id,
                             rootcomment.object_pk)
    context = RequestContext(request, {'comments': comments, 'form': form})
    return render_to_response('tcc/index.html', context)
Ejemplo n.º 6
0
def get_comments_for_object(context, object, next=None):
    ct = ContentType.objects.get_for_model(object)
    request = context['request']
    initial = {'content_type': ct.id,
               'object_pk': object.pk,
               'next': next,
               }
    form = CommentForm(object, initial=initial)
    thread_id = request.GET.get('cpermalink', None)
    if thread_id:
        comments = api.get_comment_thread(thread_id)
    else:
        comments = api.get_comments_limited(ct.id, object.pk)
    if not comments:
        comments = []
    else:
        comments = comments.order_by('-sort_date', 'path')
    context.update({'comments': comments, 'form': form})
    return render_to_string('tcc/list-comments.html',
                            context_instance=context)
Ejemplo n.º 7
0
def get_comments_for_object(context, object, next=None):
    ct = ContentType.objects.get_for_model(object)
    request = context['request']
    initial = {
        'content_type': ct.id,
        'object_pk': object.pk,
        'next': next,
    }
    form = CommentForm(object, initial=initial)
    thread_id = request.GET.get('cpermalink', None)
    if thread_id:
        comments = api.get_comment_thread(thread_id)
    else:
        comments = api.get_comments_limited(ct.id, object.pk)
    if not comments:
        comments = []
    else:
        comments = comments.order_by('-sort_date', 'path')
    context.update({'comments': comments, 'form': form})
    return render_to_string('tcc/list-comments.html', context_instance=context)