Beispiel #1
0
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))
Beispiel #2
0
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 article_type(message):  # 文章类型初始化定义
    sql_commit("insert into article_type(type_name) "
               "values ('%s') "
               "ON DUPLICATE KEY UPDATE type_name='%s'" % (
                   message,
                   message,
               ))
    return
Beispiel #4
0
def regist():
    if request.method == 'GET':
        return render_template('regist.html')
    else:
        user = request.form.get('username')
        pw = request.form.get('password1')

        if len(user) == 0 | len(pw) == 0:
            return redirect(url_for('login'))

        if pw != request.form.get('password2'):
            return render_template('regist.html', text="密码不一致", username=user)

        if sql_first_one("user_name", "userinfo", "user_name='"+user+"'"):
            return render_template('regist.html', text="用户名已存在")
        else:
            # 把注册信息加入test表
            sql_commit("insert into userinfo(user_name, user_password, user_state, user_register)\
                           values ('%s', '%s', %s, '%s')"
                       % (user, pw, 1, str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")),))
            return render_template('login.html', text="注册成功,请重新登陆")
Beispiel #5
0
def make_article():
    if request.method == 'GET':
        return render_template('makeArticle.html', user=session.get('user_name'), types=sql_article_type())
    else:
        title = request.form['title']
        content = request.form['content']
        type_name = request.form['article_type']
        if len(content) == 0:
            return render_template('makeArticle.html',
                                   user=session.get('user_name'),
                                   types=sql_article_type(),
                                   text="内容为空")
        type_id = sql_first_one("type_id", "article_type", "type_name='"+type_name+"'")
        username = session.get('user_name')
        user_id = sql_first_one("user_id", "userinfo", "user_name='"+username+"'")
        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 article(message_id, type_id, article_title, article_text) "
                   "values(%d, %d, '%s', '%s') "
                   % (message_id, type_id, title, content))
    return redirect(url_for('index', choose='all'))
Beispiel #6
0
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
Beispiel #7
0
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)