コード例 #1
0
def blog_edit(blog_id):
    """
    博客编辑
    """
    # return "Hello, World!\nBlog Edit!"
    form = BlogEditForm(request.form)
    if request.method == 'GET':
        from blog import get_blog_row_by_id
        blog_info = get_blog_row_by_id(blog_id)
        if blog_info:
            form.author.data = blog_info.author
            form.title.data = blog_info.title
            form.pub_date.data = blog_info.pub_date
        else:
            return redirect(url_for('index'))
    if request.method == 'POST':
        if form.validate_on_submit():
            from blog import edit_blog
            from datetime import datetime
            blog_info = {
                'author': form.author.data,
                'title': form.title.data,
                'pub_date': form.pub_date.data,
                'edit_time': datetime.utcnow(),
            }
            result = edit_blog(blog_id, blog_info)
            if result == 1:
                flash(u'Edit Success', 'success')
                return redirect(request.args.get('next') or url_for('blog_list'))
            if result == 0:
                flash(u'Edit Failed', 'warning')
        flash(form.errors, 'warning')  # 调试打开
    flash(u'Hello, %s' % current_user.email, 'info')  # 测试打开
    return render_template('blog/edit.html', title='blog_edit', blog_id=blog_id, form=form)
コード例 #2
0
ファイル: views.py プロジェクト: zhanghe06/flask_project
def blog_edit(blog_id):
    """
    博客编辑
    """
    # return "Hello, World!\nBlog Edit!"
    form = BlogEditForm(request.form)
    if request.method == 'GET':
        from blog import get_blog_row_by_id
        blog_info = get_blog_row_by_id(blog_id)
        if blog_info:
            form.author.data = blog_info.author
            form.title.data = blog_info.title
            form.pub_date.data = blog_info.pub_date
        else:
            return redirect(url_for('index'))
    if request.method == 'POST':
        if form.validate_on_submit():
            from blog import edit_blog
            from datetime import datetime
            blog_info = {
                'author': form.author.data,
                'title': form.title.data,
                'pub_date': form.pub_date.data,
                'edit_time': datetime.utcnow(),
            }
            result = edit_blog(blog_id, blog_info)
            if result == 1:
                flash(u'Edit Success', 'success')
                return redirect(request.args.get('next') or url_for('blog_list'))
            if result == 0:
                flash(u'Edit Failed', 'warning')
        flash(form.errors, 'warning')  # 调试打开
    flash(u'Hello, %s' % current_user.email, 'info')  # 测试打开
    return render_template('blog/edit.html', title='blog_edit', blog_id=blog_id, form=form)
コード例 #3
0
def blog_ajax_list_edit():
    """
    博客编辑
    """
    if request.method == 'POST' and request.is_xhr:
        form = request.form
        from blog import edit_blog
        from datetime import datetime
        blog_id = form.get('id', 0, type=int)
        blog_info = {
            'author': form.get('author'),
            'title': form.get('title'),
            'pub_date': datetime.strptime(form.get('pub_date'), "%Y-%m-%d").date(),
            'edit_time': datetime.utcnow(),
        }
        result = edit_blog(blog_id, blog_info)
        if result == 1:
            return json.dumps({'success': u'Edit Success'})
        if result == 0:
            return json.dumps({'error': u'Edit Error'})
    abort(404)
コード例 #4
0
ファイル: views.py プロジェクト: zhanghe06/flask_project
def blog_ajax_list_edit():
    """
    博客编辑
    """
    if request.method == 'POST' and request.is_xhr:
        form = request.form
        from blog import edit_blog
        from datetime import datetime
        blog_id = form.get('id', 0, type=int)
        blog_info = {
            'author': form.get('author'),
            'title': form.get('title'),
            'pub_date': datetime.strptime(form.get('pub_date'), "%Y-%m-%d").date(),
            'edit_time': datetime.utcnow(),
        }
        result = edit_blog(blog_id, blog_info)
        if result == 1:
            return json.dumps({'success': u'Edit Success'})
        if result == 0:
            return json.dumps({'error': u'Edit Error'})
    abort(404)