# 评论信息
_common_logic = common_logic.CommonLogic('comment')
sql='select c.id_,c.user_id_,c.create_time_,c.content_,c.parent_id_,ua.name_ from comment as c join user_attribute as ua ' \
'on ua.id_=c.user_id_ where moments_id_=\"%s\"'
comment_result_list_ = _common_logic.select(sql % moments_id_)
comment_dict = {} # 所有评论字典集合
if comment_result_list_:
for comment_result_ in comment_result_list_:
comment_result_['child']=[]
comment_dict[comment_result_['id_']] = comment_result_
user_id_ = comment_result_.get("user_id_")
sql = 'select file_id_ from util_file_relevant where relevant_id_= \"%s\"'
user_picture_result_ = _common_logic.select(sql % user_id_)
file_id_ = user_picture_result_[0].get("file_id_")
picture_ = app_download_single(file_id_) # 头像
comment_result_['picture_'] = picture_
comment = [] # 没有子评论的评论
for comment_result_ in comment_result_list_:
pid = comment_result_["parent_id_"]
if pid:
comment_dict[pid]["child"].append(comment_result_)
else:
comment.append(comment_result_)
评论按树形结构显示