Beispiel #1
0
def get_thread_header(tid):
    try:
        # check cache
        
        t = Thread.objects.get(pk = int(tid))
        return (True,{'id':t.id,
                      'url':t.url,
                      'title':t.title,
                      'summary':t.summary,
                      'domain':t.domain.name,
                      'creator_name':t.creator.user.username,
                      'creator_id':t.creator.id,
                      'net_vote':t.up-t.down,
                      'time':pretty_time(int(t.time_created)),
                      'tags':tagger.get_tags(int(tid)),
                      'num_comment':len(Comment.objects.filter(thread = t))})
    except:
        connection._rollback()
        return (False,str(traceback.format_exc()))
Beispiel #2
0
def get_full_thread(tid):
    try:
        t = Thread.objects.get(pk = int(tid))
        all_comments = Comment.objects.filter(thread = t).order_by('time_created') # old-to-new ordering: should preserve subthreading logic
        ids = []
        subs = []
        # create the subthread trees here
        for c in all_comments:
            ids.append(c.id)
            if c.parent == None:
                subs.append(Subthread(c,[]))
            else:
                for s in subs:
                    if(s.insertChildTo(c.parent.id,Subthread(c,[]))):
                        break

        if not alfred.subthread_list_sort(subs):
            return (False,str(traceback.format_exc()))
        # convert trees to traversed lists
        comments = []
        for s in subs:
            comments.append(s.toList(0,[]))

        return (True,{'id':t.id,
                      'url':t.url,
                      'title':t.title,
                      'summary':t.summary,
                      'domain':t.domain.name,
                      'creator_name':t.creator.user.username,
                      'creator_id':t.creator.id,
                      'net_vote':t.up-t.down,
                      'time':pretty_time(int(t.time_created)),
                      'num_comment':len(Comment.objects.filter(thread = t)),
                      'tags':tagger.get_tags(int(tid))
                      },comments,ids)
    except:
        connection._rollback()
        return (False,str(traceback.format_exc()))