Example #1
0
def comment_to_dict(comment):
    return {'id':comment.id,
            'creator_name':comment.creator.user.username,
            'creator_id':comment.creator.id,
            'text':comment.text,
            'time':pretty_time(int(comment.time_created)),
            'net_vote':comment.up-comment.down}
Example #2
0
def get_comment_fields(subthread):
    """
    aux function to return the extracted fields of a comment subthread
    """
    out = []
    for comment in subthread:
        out.append({'id':comment.id,
                    'creator_name':comment.creator.user.username,
                    'creator_id':comment.creator.id,
                    'time':pretty_time(int(comment.time_created)),
                    'text':comment.text,
                    'net_vote':comment.up-comment.down})
    return out
Example #3
0
def get_best_subthread(tid):
    """
        returns the best comment subthread of the given thread
        for main page display purposes
        Sorting logic: Return the parent comment with the highest up vote
        and return the child of this comment with the highest up vote
        """    
    try:
        all_thread_comments = get_thread_comments(tid)
        comment_headers = get_comments(all_thread_comments)
        primer_comments = []
        non_primers = []
        for c in zip(comment_headers,all_thread_comments):
            if c[0]['pid']==-1:
                primer_comments.append(c)
            else:
                non_primers.append(c)
        primer_comments.sort(key=lambda l: l[0]['up'], reverse=True)
        #get a single None thread with the hightest up vote
        sub = []
        if(len(primer_comments) > 0):
            # there is at least a single comment about the thread
            # Therefore top_primer_comment is well defined
            # try to get the child with the highest up vote
            top_primer_comment = primer_comments[0]
            sub.append(top_primer_comment)
            secondary_comments = []
            for c in non_primers:
                if c[0]['pid']==top_primer_comment[1]:
                    secondary_comments.append(c)
            secondary_comments.sort(key=lambda l: l[0]['up'], reverse=True)
            if(len(secondary_comments) > 0):
                # there is at least a single child
                # There top_secondary_comment is well defined
                # Append it to the list
                top_secondary_comment = secondary_comments[0]
                sub.append(top_secondary_comment)
            out = []
            for comment in sub:
                out.append({'id':comment[1],
                            'creator_name':comment[0]['cname'],
                            'creator_id':comment[0]['cid'],
                            'time':pretty_time(int(comment[0]['time'])),
                            'text':comment[0]['text'],
                            'net_vote':comment[0]['up']-comment[0]['down']})
        return (True,out)
    except:
        return (False,str(traceback.format_exc()))
Example #4
0
File: thread.py Project: paganre/lc
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()))
Example #5
0
File: thread.py Project: paganre/lc
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()))