Example #1
0
def load_answer_evluation_by_evluations(answer_id, evluations):
    if not question_client.exists(ANSWER_EVALUATION_PREFIX + str(answer_id)):
        user_id = [evluation.user.id for evluation in evluations]
        user_id.append(-1)
        question_client.sadd(ANSWER_EVALUATION_PREFIX + str(answer_id),
                             *user_id)
        for evluation in evluations:
            evluation_dict = {
                "id": evluation.id,
                "edittime": evluation.edittime.strftime(TIME_STRF),
                "status": evluation.status,
                "user_id": evluation.user.id
            }
            question_client.hmset(
                ANSWEREVALUATION_PRFIX + "a:" + str(answer_id) + "u:" +
                str(evluation.user.id), evluation_dict)
            if evluation.status == 1:
                question_client.sadd(
                    FAVOUR_ANSWEREVALUATION_PRFIX + str(answer_id),
                    evluation.user.id)
            else:
                question_client.sadd(
                    OPPOSE_ANSWEREVALUATION_PRFIX + str(answer_id),
                    evluation.user.id)
            load_user(evluation.user)
Example #2
0
def load_question_by_question(question):
    if not question_client.exists(QUESTION_PRFIX+str(question.id)):
        question_dict={"id":question.id,"title":question.title.encode('utf-8'),"content":question.content.encode('utf-8'),"answercount":question.answercount,\
                "addtime":question.addtime.strftime(TIME_STRF),"user_id":question.user.id}
        question_client.hmset(QUESTION_PRFIX+str(question.id),question_dict)
        load_user(question.user)
        load_question_follower(question.id)
        load_question_answer_by_answers(question.id,question.answer_set.select_related("user").all())
Example #3
0
def load_answer_by_answer(answer):
    if not question_client.exists(QUESTION_ANSWER_PREFIX+str(answer.question_id)):
        load_question_by_id(answer.question_id)
    else:
        question_client.rpush(QUESTION_ANSWER_PREFIX+str(answer.question_id),answer.id)
        answer_dict={"id":answer.id,"question_id":answer.question_id,"content":answer.content,"addtime":answer.addtime.strftime(TIME_STRF),\
                "user_id":answer.user.id,"commentcount":answer.commentcount,"favorcount":answer.favorcount,"opposecount":answer.opposecount}
        question_client.hmset(ANSWER_PRFIX+str(answer.id),answer_dict)
        load_user(answer.user)
Example #4
0
def load_comment_by_comment(comment):
    if not question_client.exists(ANSWER_COMMENT_PREFIX+str(comment.answer_id)):
        load_comment_by_answer_id(comment.answer_id)
    question_client.rpush(ANSWER_COMMENT_PREFIX+str(comment.answer_id),comment.id)
    comment_dict={"id":comment.id,"answer_id":comment.answer_id,"content":comment.content,"addtime":comment.addtime,"user":comment.user.id,\
                    "touser":comment.touser.id,"favorcount":comment.favorcount}
    load_user(comment.user)
    load_user(comment.touser)
    question_client.hmset(COMMENT_PRFIX+str(comment.id),comment_dict)
Example #5
0
def load_question_by_question(question):
    if not question_client.exists(QUESTION_PRFIX + str(question.id)):
        question_dict={"id":question.id,"title":question.title.encode('utf-8'),"content":question.content.encode('utf-8'),"answercount":question.answercount,\
                "addtime":question.addtime.strftime(TIME_STRF),"user_id":question.user.id}
        question_client.hmset(QUESTION_PRFIX + str(question.id), question_dict)
        load_user(question.user)
        load_question_follower(question.id)
        load_question_answer_by_answers(
            question.id,
            question.answer_set.select_related("user").all())
Example #6
0
def load_comment_by_comments(answer_id,comments):
    if not question_client.exists(ANSWER_COMMENT_PREFIX+str(answer_id)):
        comment_id=[comment.id for comment in comments]
        comment_id.insert(-1,0)
        question_client.rpush(ANSWER_COMMENT_PREFIX+str(answer_id),*comment_id)
        for comment in comments:
            comment_dict={"id":comment.id,"answer_id":answer_id,"content":comment.content,"addtime":comment.addtime,"user":comment.user.id,\
                    "touser":comment.touser.id,"favorcount":comment.favorcount}
            load_user(comment.user)
            load_user(comment.touser)
            question_client.hmset(COMMENT_PRFIX+str(comment.id),comment_dict)
Example #7
0
def load_answer_by_answer(answer):
    if not question_client.exists(QUESTION_ANSWER_PREFIX +
                                  str(answer.question_id)):
        load_question_by_id(answer.question_id)
    else:
        question_client.rpush(QUESTION_ANSWER_PREFIX + str(answer.question_id),
                              answer.id)
        answer_dict={"id":answer.id,"question_id":answer.question_id,"content":answer.content,"addtime":answer.addtime.strftime(TIME_STRF),\
                "user_id":answer.user.id,"commentcount":answer.commentcount,"favorcount":answer.favorcount,"opposecount":answer.opposecount}
        question_client.hmset(ANSWER_PRFIX + str(answer.id), answer_dict)
        load_user(answer.user)
Example #8
0
def load_comment_by_comment(comment):
    if not question_client.exists(ANSWER_COMMENT_PREFIX +
                                  str(comment.answer_id)):
        load_comment_by_answer_id(comment.answer_id)
    question_client.rpush(ANSWER_COMMENT_PREFIX + str(comment.answer_id),
                          comment.id)
    comment_dict={"id":comment.id,"answer_id":comment.answer_id,"content":comment.content,"addtime":comment.addtime,"user":comment.user.id,\
                    "touser":comment.touser.id,"favorcount":comment.favorcount}
    load_user(comment.user)
    load_user(comment.touser)
    question_client.hmset(COMMENT_PRFIX + str(comment.id), comment_dict)
Example #9
0
def load_question_answer_by_answers(question_id,answers):
    if not question_client.exists(QUESTION_ANSWER_PREFIX+str(question_id)):
        #answer_id=[(answers[i].id,i) for i in range(len(answers))]
        answer_id=[answer.id for answer in answers]
        answer_id.insert(0,-1)
        question_client.rpush(QUESTION_ANSWER_PREFIX+str(question_id),*answer_id)
        for answer in answers:
            answer_dict={"id":answer.id,"content":answer.content,"addtime":answer.addtime.strftime(TIME_STRF),"user_id":answer.user.id,\
                    "commentcount":answer.commentcount,"favorcount":answer.favorcount,"opposecount":answer.opposecount,"question_id":answer.question_id}
            question_client.hmset(ANSWER_PRFIX+str(answer.id),answer_dict)
            load_user(answer.user)
            load_answer_evluation_by_evluations(answer.id,answer.answerevaluation_set.select_related('user').all())
Example #10
0
def load_answer_evluation_by_evluations(answer_id,evluations):
    if not question_client.exists(ANSWER_EVALUATION_PREFIX+str(answer_id)):
        user_id=[evluation.user.id for evluation in evluations]
        user_id.append(-1)
        question_client.sadd(ANSWER_EVALUATION_PREFIX+str(answer_id),*user_id)
        for evluation in evluations:
            evluation_dict={"id":evluation.id,"edittime":evluation.edittime.strftime(TIME_STRF),"status":evluation.status,"user_id":evluation.user.id}
            question_client.hmset(ANSWEREVALUATION_PRFIX+"a:"+str(answer_id)+"u:"+str(evluation.user.id),evluation_dict)
            if evluation.status==1:
                question_client.sadd(FAVOUR_ANSWEREVALUATION_PRFIX+str(answer_id),evluation.user.id)
            else:
                question_client.sadd(OPPOSE_ANSWEREVALUATION_PRFIX+str(answer_id),evluation.user.id)
            load_user(evluation.user)
Example #11
0
def load_comment_by_comments(answer_id, comments):
    if not question_client.exists(ANSWER_COMMENT_PREFIX + str(answer_id)):
        comment_id = [comment.id for comment in comments]
        comment_id.insert(-1, 0)
        question_client.rpush(ANSWER_COMMENT_PREFIX + str(answer_id),
                              *comment_id)
        for comment in comments:
            comment_dict={"id":comment.id,"answer_id":answer_id,"content":comment.content,"addtime":comment.addtime,"user":comment.user.id,\
                    "touser":comment.touser.id,"favorcount":comment.favorcount}
            load_user(comment.user)
            load_user(comment.touser)
            question_client.hmset(COMMENT_PRFIX + str(comment.id),
                                  comment_dict)
Example #12
0
def load_question_answer_by_answers(question_id, answers):
    if not question_client.exists(QUESTION_ANSWER_PREFIX + str(question_id)):
        #answer_id=[(answers[i].id,i) for i in range(len(answers))]
        answer_id = [answer.id for answer in answers]
        answer_id.insert(0, -1)
        question_client.rpush(QUESTION_ANSWER_PREFIX + str(question_id),
                              *answer_id)
        for answer in answers:
            answer_dict={"id":answer.id,"content":answer.content,"addtime":answer.addtime.strftime(TIME_STRF),"user_id":answer.user.id,\
                    "commentcount":answer.commentcount,"favorcount":answer.favorcount,"opposecount":answer.opposecount,"question_id":answer.question_id}
            question_client.hmset(ANSWER_PRFIX + str(answer.id), answer_dict)
            load_user(answer.user)
            load_answer_evluation_by_evluations(
                answer.id,
                answer.answerevaluation_set.select_related('user').all())