예제 #1
0
def list_article():
    # page_num =
    if request.method == 'GET':
        type_id = request.args.get('typeId')
        print('**********', type_id)
        results = databaes.query_all('select * from t_article_type')
        return render_template('list_article.html',
                               typies=results,
                               nowTypeid=type_id)
    else:
        now_type_id = request.form.get('typeId')
        print('---------', now_type_id)
        if now_type_id != '0':
            sql = 'select art.*, type.* from ' \
                  't_article art, t_article_type type ' \
                  'where art.type_id=type.type_id '\
                  'and type.type_id=%s'
            articles = databaes.query_all(sql, (now_type_id, ))
            # print(type_id)
            # print(articles)
            return jsonify(articles)
        else:
            sql_2 = 'select art.*, type.* from ' \
                  't_article art, t_article_type type ' \
                  'where art.type_id=type.type_id '
            articles = databaes.query_all(sql_2)
            print('/////////', articles)
            return jsonify(articles)
예제 #2
0
def article():
    article_id_1 = request.args.get('articleId')
    article_id = request.form.get('articleId')
    types = databaes.query_all('select * from t_article_type')
    sql = 'select art.*, type.type_name from ' \
          't_article art, t_article_type type ' \
          'where art.type_id=type.type_id ' \
          'and art.article_id=%s'
    article = databaes.query_one(sql, (article_id_1, ))
    sql2 = "select comm.*, usr.username,usr.portrait from t_comment comm, t_user usr " \
           "where comm.user_id=usr.user_id " \
           "and comm.article_id=%s"
    comments = databaes.query_all(sql2, (article_id_1, ))
    comments_num = len(comments)
    if request.method == 'GET':
        return render_template('article.html',
                               article_id=article_id_1,
                               comments_num=comments_num,
                               comments=comments,
                               types=types,
                               article=article)
        # print('************', jsonify(article, comments, types))
        # return render_template('article.html', allinfo=jsonify(article, comments, types))
        # return jsonify(article, comments, types)
    else:
        article = databaes.query_one(sql, (article_id, ))
        # print(jsonify(article))
        return jsonify(article)
예제 #3
0
def index():
    results = databaes.query_all('select * from t_article_type')
    #try:
    #    return render_template('index.html', username=session['username'], typies=results)
    #except KeyError:
    #    return render_template('index.html', typies=results)
    return render_template('index.html', typies=results)
예제 #4
0
def change_article():
    if request.method == 'GET':
        article_id = request.args.get('articleId')
        show = request.args.get('show')
        sql = 'select art.*, type.type_name from ' \
              't_article art, t_article_type type ' \
              'where art.type_id=type.type_id ' \
              'and art.article_id=%s'
        article = databaes.query_one(sql, (article_id, ))
        types = databaes.query_all('select * from t_article_type')
        if show:
            return jsonify(article)
        return render_template('change_article.html',
                               article=article,
                               types=types)
    else:
        article_id = request.form.get('articleId')
        title = request.form.get('title')
        article = request.form.get('article')
        type = request.form.get('type')
        print(type)
        print(article)
        sql = 'update t_article set title=%s, content=%s, type_id=%s where article_id=%s'
        row = databaes.update(sql, (title, article, type, article_id))
        print(row)
        if row > 0:
            return 'ok'
        else:
            return 'error'
예제 #5
0
def mgr_comment():
    sql = 'select art.article_id, art.title, com.*, usr.username ' \
          'from t_article art, t_comment com, t_user usr ' \
          'where com.article_id = art.article_id ' \
          'and com.user_id = usr.user_id'
    result = databaes.query_all(sql)
    print(result)
    return render_template('mgr_comment.html', results=result)
예제 #6
0
def get_articles():
    page_num = int(request.args.get('pageNum'))

    sql = 'select art.*, type.type_name ' \
          'from t_article art, t_article_type type ' \
          'where art.type_id=type.type_id ' \
          'limit %s, 3'

    result = databaes.query_all(sql, (page_num * 3))

    return jsonify(result)
예제 #7
0
def edit_article():
    if request.method == 'POST':
        title = request.form.get('title')
        article = request.form.get('article')
        type = request.form.get('type')
        sql = 'insert into t_article(title, content, type_id) values(%s, %s, %s)'
        row = databaes.update(sql, (title, article, type))
        if row > 0:
            return 'ok'
        else:
            return 'error'
    else:
        types = databaes.query_all('select * from t_article_type')
        return render_template('edit_article.html', types=types)
예제 #8
0
def mge_article():
    sql = 'select art.*, type.type_name ' \
          'from t_article art, t_article_type type ' \
          'where art.type_id=type.type_id '
    result = databaes.query_all(sql)
    return render_template('mgr_article.html', articles=result)