def article_detail(article_id): user = session.get('user_name') focus_id = sql_select_user_id(user) list_a = sql_select_web_with_article_id(article_id) comments = sql_select_comments_with_article_id(article_id) reply_lists, praise_replys = replys_comment_dic(comments) focused_id = sql_select_user_id(list_a[0][4]) focus_group_list = sql_group_list(user) if request.method == 'POST': group_id = request.form['focus_group'] time = str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) sql_commit("insert focus(focus_id, focused_id, group_id, focus_time) " "values(%s, %s, %s, '%s') " % (focus_id, focused_id, group_id, time, )) focus = if_focus(focused_id, focus_id) return render_template('detail.html', user=user, types=sql_article_type(), list=list_a[0], praise=if_praise_with_message_id(list_a, 8), praise_comment=if_praise_with_message_id(comments, 1), focus=focus, focus_groups=focus_group_list, comments=comments, reply_lists=reply_lists, praise_replys=praise_replys)
def reply_action(comment_id, article_id): user = session.get('user_name') if request.method == 'GET': list_a = sql_select_web_with_article_id(article_id) return render_template('makeReply.html', user=user, types=sql_article_type(), list=list_a[0], praise=if_praise_with_message_id(list_a, 8), comment_id=comment_id) else: reply_text = request.form['content'] if len(reply_text) == 0: return redirect(url_for('reply_action', comment_id=comment_id, article_id=article_id)) user_id = sql_select_user_id(user) time = str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) sql_commit("insert into out_message(user_id, message_time, message_newtime, message_flag) " "values (%d, '%s', '%s', %d) " % (user_id, time, time, 1,)) message_id = sql_identity_id() sql_commit("insert into reply(message_id, comment_id, reply_text) " "values(%d, %s, '%s') " % (message_id, comment_id, reply_text, )) return redirect(url_for('article_detail', article_id=article_id))
def if_praise_with_message_id(lists, location): praise_dict = {} for list_a in lists: praise_do = sql_praise(sql_select_user_id(session.get('user_name')), list_a[location]) if praise_do: praise_dict[list_a[location]] = 1 else: praise_dict[list_a[location]] = 0 return praise_dict
def praise_action(message_id): user_id = sql_select_user_id(session.get('user_name')) sql_commit("insert praise(message_id, user_id) " "values(%s, %s) " % (message_id, user_id, )) return
def user_detail(user_name, choose): if choose is None: choose = 'detail' if choose == 'detail': # 显示用户信息 detail = sql_select_user_detail(user_name) focused_id = sql_select_user_id(user_name) focus_id = sql_select_user_id(session.get('user_name')) if request.method == 'POST': group_id = request.form['focus_group'] time = str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) sql_commit("insert focus(focus_id, focused_id, group_id, focus_time) " "values(%s, %s, %s, '%s') " % (focus_id, focused_id, group_id, time,)) focus = if_focus(focused_id, focus_id) focus_groups = sql_group_list(session.get('user_name')) if detail: return render_template('user_detail.html', user=session.get('user_name'), types=sql_article_type(), host=user_name, choose='detail', user_sex=detail[0][2], user_birthday=detail[0][3] if detail[0][3] else "无", user_email=detail[0][4] if detail[0][4] else "无", user_address=detail[0][5] if detail[0][5] else "无", user_text=detail[0][6] if detail[0][6] else "无", focus=focus, focus_groups=focus_groups) else: return render_template('user_detail.html', user=session.get('user_name'), types=sql_article_type(), host=user_name, choose='detail', user_sex='男', user_birthday='无', user_email='无', user_address='无', user_text='无', focus=focus, focus_groups=focus_groups ) if choose == 'remake': # 修改用户信息 if request.method == 'GET': if user_name != session.get('user_name'): redirect(url_for('user_detail', user_name=user_name, choose='detail')) detail = sql_select_user_detail(user_name) if detail: return render_template('user_detail.html', user=session.get('user_name'), types=sql_article_type(), host=user_name, choose='remake', user_sex=detail[0][2], user_birthday=detail[0][3] if detail[0][3] else "", user_email=detail[0][4] if detail[0][4] else "", user_address=detail[0][5] if detail[0][5] else "", user_text=detail[0][6] if detail[0][6] else "") else: return render_template('user_detail.html', user=session.get('user_name'), types=sql_article_type(), host=user_name, choose='remake', user_sex='男') else: user_id = sql_first_one("user_id", "userinfo", "user_name='" + user_name + "'") user_sex = request.form['user_sex'] user_birthday = request.form['user_birthday'] user_email = request.form['user_email'] user_address = request.form['user_address'] user_text = request.form['user_text'] sql_commit_userdetail(user_id, user_sex, user_birthday, user_email, user_address, user_text) return render_template('user_detail.html', user=session.get('user_name'), types=sql_article_type(), host=user_name, choose='detail', user_sex=user_sex, user_birthday=user_birthday, user_email=user_email, user_address=user_address, user_text=user_text) if choose == 'focus': if request.method == 'GET': focus_groups = sql_group_list(user_name) focus_lists = focus_user_group_dict(focus_groups) return render_template('user_detail.html', user=session.get('user_name'), types=sql_article_type(), host=user_name, choose=choose, focus_groups=focus_groups, focus_lists=focus_lists) else: group_name = request.form['group_name'] user_id = sql_select_user_id(user_name) sql_commit("insert group_user(user_id, group_name) " "value(%d, '%s') " % (user_id, group_name, )) focus_groups = sql_group_list(user_name) focus_lists = focus_user_group_dict(focus_groups) return render_template('user_detail.html', user=session.get('user_name'), types=sql_article_type(), host=user_name, choose=choose, focus_groups=focus_groups, focus_lists=focus_lists) lists = [] if choose == 'web': lists = sql_select_user_web(user_name) if choose == 'praise': lists = sql_select_user_praise_web(user_name) if choose == 'comment': lists = sql_select_user_comment_web(user_name) if choose == 'reply': lists = sql_select_user_reply_web(user_name) return render_template('user_detail.html', user=session.get('user_name'), lists=lists, praise=if_praise_with_message_id(lists, 8), choose=choose, types=sql_article_type(), host=user_name)