コード例 #1
0
def edit():
    return_msg = ReturnMsg()
    if request.method and request.method == 'POST':
        args = request.values.to_dict()
    else:
        args = request.args.to_dict()

    try:
        id = args.get('id', type='int')
        article = Article.get_article(id)
        article.uid = args.get('uid')
        article.title = args.get('title')
        article.content = args.get('content')
        article.like = args.get('like')
        article.tread = args.get('tread')
        article.view = args.get('view')
        article.reply = args.get('reply', type='int', default=0)
        article.share = args.get('share', type='int', default=0)
        article.mtime = datetime.now()

        Tag

        article.update()
    except Exception as e:
        logger.error('更新文章出现错误, %s' % e)
        return_msg.isSuccess = False
        return_msg.messege = '更新文章错误'

    return jsonify(return_msg.__dict__)
コード例 #2
0
def create_tag():
    '''
        更新文章
    :return:
    '''
    return_msg = ReturnMsg()
    if request.method and request.method == 'POST':
        args = request.values.to_dict()
    else:
        args = request.args.to_dict()

    try:
        tag = Tag()

        tag.name = args.get('name')
        tag.mtime = datetime.now()

        tag.ctime = datetime.now()
        tag.add()
        return_msg.messege = '添加数据成功'

    except Exception as e:
        logger.error('添加数据出现错误, %s' % e)
        return_msg.isSuccess = False
        return_msg.messege = '添加数据错误'

    return jsonify(return_msg.__dict__)
コード例 #3
0
def detail(id):
    return_msg = ReturnMsg()

    article = Article.get_article(id)

    return_msg.messege = 'sucess'
    return_msg.result = article
    return jsonify(return_msg.__dict__)
コード例 #4
0
def search():
    '''
        检索文章
    :return:
    '''
    return_msg = ReturnMsg()

    return_msg.messege = 'sucess'
    return_msg.result = {}
    return jsonify(return_msg.__dict__)
コード例 #5
0
def update_love():
    '''
        更新文章的喜欢字段
    :return:
    '''
    return_msg = ReturnMsg()

    return_msg.messege = 'sucess'
    return_msg.result = {}
    return jsonify(return_msg.__dict__)
コード例 #6
0
def get_one():
    '''
        获取文章
    :return:
    '''
    if request.method and request.method == 'POST':
        args = request.values.to_dict()
    else:
        args = request.args.to_dict()

    # 从request中获取文章id
    id = args.get('id')

    return_msg = ReturnMsg()
    if not id:
        return_msg.messege = '缺少参数id'
        return_msg.isSuccess = False
        return jsonify(return_msg.__dict__)

    try:
        # 根据ID检索文章
        result = Article.get_article(id)
        return_msg.messege = '获取文章成功'
        return_msg.isSuccess = True
    except Exception as e:
        logger.error('获取文章失败')
        return_msg.isSuccess = False
        return_msg.messege = '获取文章失败'

    return_msg.result = result.to_dict()
    return jsonify(return_msg.__dict__)
コード例 #7
0
def get_comment_list():
    if request.method and request.method == 'POST':
        args = request.values.to_dict()
    else:
        args = request.args.to_dict()
    return_msg = ReturnMsg()

    id = args.get('id')

    if not id:
        return_msg.isSuccess = False
        return_msg.messege = '缺少参数id'
    else:

        try:
            # 根据ID检索文章
            result = Comment.get_comment_list(id)
            return_msg.messege = '获取评论成功'
            return_msg.isSuccess = True
        except Exception as e:
            logger.error('获取评论失败')
            return_msg.isSuccess = False
            return_msg.messege = '获取评论失败'
        return_msg.result = result
    return jsonify(return_msg.__dict__)
コード例 #8
0
def get_one_tag():
    if request.method and request.method == 'POST':
        args = request.values.to_dict()
    else:
        args = request.args.to_dict()

    # 从request中获取文章id
    id = args.get('id')

    return_msg = ReturnMsg()
    if not id:
        return_msg.messege = '缺少参数id'
        return_msg.isSuccess = False
        return jsonify(return_msg.__dict__)

    try:
        result = Tag.get_one(id)
        return_msg.messege = '获取标签成功'
        return_msg.isSuccess = True
    except Exception as e:
        logger.error('获取标签失败, %s' % e)
        return_msg.isSuccess = False
        return_msg.messege = '获取标签失败'

    return_msg.result = result.to_dict()
    return jsonify(return_msg.__dict__)
コード例 #9
0
def delete_tag():
    if request.method and request.method == 'POST':
        args = request.values.to_dict()
    else:
        args = request.args.to_dict()

    # 从request中获取文章id
    ids = args.get('ids')

    return_msg = ReturnMsg()
    if not ids:
        return_msg.messege = '缺少参数id'
        return_msg.isSuccess = False
        return jsonify(return_msg.__dict__)

    try:
        Tag.delete(ids.split(','))
        return_msg.isSuccess = True
        return_msg.messege = '删除数据成功'
    except Exception as e:
        logger.error('获取标签失败, %s' % e)
        return_msg.isSuccess = False
        return_msg.messege = '获取标签失败'

    return jsonify(return_msg.__dict__)
コード例 #10
0
def delete():
    '''
        删除文章
    :return:
    '''
    if request.method and request.method == 'POST':
        args = request.values.to_dict()
    else:
        args = request.args.to_dict()
    return_msg = ReturnMsg()

    ids = args.get('ids')
    try:
        Article.delete(ids.split(','))
        return_msg.messege = '删除文章成功'
    except Exception as e:
        logger.error(e)
        return_msg.isSuccess = False
        return_msg.messege = '删除文章失败'

    return jsonify(return_msg.__dict__)
コード例 #11
0
def create():
    '''
        更新文章
    :return:
    '''
    return_msg = ReturnMsg()
    if request.method and request.method == 'POST':
        try:
            args = request.form
            article = Article()

            article.uid = args.get('uid')
            article.title = args.get('title')
            article.content = args.get('content')
            article.like = args.get('like', type=int, default=0)
            article.tread = args.get('tread', type=int, default=0)
            article.view = args.get('view', type=int, default=0)
            article.reply = args.get('reply', type=int, default=0)
            article.share = args.get('share', type=int, default=0)

            article.ctime = datetime.now()
            article.mtime = datetime.now()

            tag = Tag()
            tag_id = args.get('tag_id')
            if tag_id:
                tag.id = tag_id
            tag.name = args.get('tag_name')
            article.tags.append(tag)
            article.save()
            return_msg.messege = '添加数据成功'

        except Exception as e:
            logger.error('添加数据出现错误, %s' % e)
            return_msg.isSuccess = False
            return_msg.messege = '添加数据错误'

    return jsonify(return_msg.__dict__)
コード例 #12
0
def get_article_list():
    '''
        获取文章列表
    :return:
    '''

    if request.method and request.method == 'POST':
        args = request.values.to_dict()
    else:
        args = request.args.to_dict()

    page_index = args.get('page')

    if page_index:
        page_index = int(page_index)

    page_size = args.get('pageSize')
    if page_size:
        page_size = int(page_size)

    return_msg = ReturnMsg()
    try:
        pagination = Article.get_article_list(page_index=page_index,
                                              page_size=page_size)

        # 上一页
        prev = None
        if pagination.has_prev:
            prev = url_for('api.get_article_list',
                           pageIndex=page_index - 1,
                           pageSize=page_size,
                           _external=True)

        # 下一页
        next = None
        if pagination.has_next:
            next = url_for('api.get_article_list',
                           pageIndex=page_index + 1,
                           pageSize=page_size,
                           _external=True)

        return_msg.messege = 'sucess'
        return_msg.result = {
            'data': [article.to_dict() for article in pagination.items],
            'prev': prev,
            'next': next,
            'total': pagination.total,
            'pages': pagination.pages
        }
    except Exception as e:
        logger.error('获取文章列表出现错误, %s' % e)
        return_msg.isSuccess = False
        return_msg.messege = '获取文章列表失败'
    return jsonify(return_msg.__dict__)
コード例 #13
0
def edit_tag():
    return_msg = ReturnMsg()
    if request.method and request.method == 'POST':
        args = request.values.to_dict()
    else:
        args = request.args.to_dict()

    if 'id' not in args or 'name' not in args:
        return_msg.isSuccess = False
        return_msg.messege = '参数有误,请检查是否存在参数id, name'
    else:
        try:
            id = args.get('id')
            tag = Tag.get_one(id)

            tag.name = args.get('name')
            tag.update()
            return_msg.isSuccess = True
            return_msg.messege = '修改标签数据成功'
        except Exception as e:
            logger.error('修改标签数据失败, %s' % e)
            return_msg.messege = '修改标签数据失败'

    return jsonify(return_msg.__dict__)
コード例 #14
0
def create_comment():
    if request.method and request.method == 'POST':
        args = request.form
        return_msg = ReturnMsg()
        try:
            comment = Comment()
            comment.aid = args.get('aid', type=int)
            comment.uid = args.get('uid', type=int)
            comment.content = args.get('content')
            comment.like = args.get('like', type=int, default=0)
            comment.tread = args.get('tread', type=int, default=0)
            comment.ctime = datetime.now()
            comment.mtime = datetime.now()
            comment.add()
            return_msg.isSuccess = True
            return_msg.messege = '保存评论成功'
        except Exception as e:
            logger.error('保存评论出现错误')
            return_msg.isSuccess = False
            return_msg.messege = '保存评论出现错误'
        return jsonify(return_msg.__dict__)
コード例 #15
0
ファイル: other_controller.py プロジェクト: panpanYU/blog
def upload():
    return_msg = ReturnMsg()
    if request.method and request.method == 'POST':
        if 'file' not in request.files:
            return_msg.isSuccess = False
            return_msg.messege = '上传文件不能为空'
            return jsonify(return_msg.__dict__)
        file = request.files['file']

        if not file:
            return_msg.isSuccess = False
            return_msg.messege = '上传文件不能为空'
            return jsonify(return_msg.__dict__)

        filename = file.filename

        upload_path = os.path.join(os.getcwd(), 'app/static/uploads')
        file_path = os.path.join(upload_path, filename)
        file.save(file_path)

        return_msg.isSuccess = True
        return_msg.messege = '文件上传成功'
        return_msg.result = os.path.join('/static/uploads', filename)

        return jsonify(return_msg.__dict__)
    return_msg.isSuccess = False
    return_msg.messege = '文件上传失败'
    return jsonify(return_msg.__dict__)