Ejemplo n.º 1
0
def create_dongtan():
    """"""
    blog_form = BlogForm(**request.json)
    blog_form.csrf_enabled = False
    del blog_form.captcha

    if blog_form.validate_on_submit():
        blog = api_blog.create(user=current_user, **request.json)
        return jsonres(rv=dict(id=blog.id, title=blog.title, content=blog.content))

    return jsonres(metacode=400, code=400, msg=blog_form.errors)
Ejemplo n.º 2
0
def create_blog2(category):
    # 此处category并没有使用,只是传递一下。用在界面上
    blog_form = BlogForm(category=category)
    if blog_form.validate_on_submit():
        payload = json.dumps(blog_form.data)
        r = requests.post('http://127.0.0.1:5000/api/blog/create', json=payload)
        res = r.json()
        print res[u'method']
        flash(u'创建成功')
        return redirect(url_for('.list_blog', category=category))
    if request.method == 'POST':
        flash(u'创建失败,请检查', category='danger')
    return render_template('blog/create.html', blog_form=blog_form, category=category,
                           action_url=url_for('.create_blog', category=category))
Ejemplo n.º 3
0
def create_blog(category):
    # 此处category并没有使用,只是传递一下。用在界面上
    blog_form = BlogForm(category_id=category)
    cate_name = api_category.get(category)
    if blog_form.validate_on_submit():
        can_publish = 1
        if cate_name.name == u'通知通告':
            can_publish = 1
            flash(u'请等待审核')
        blog = api_blog.create(user=current_user, can_publish=can_publish, **blog_form.data)
        flash(u'创建成功')
        return redirect(url_for('.list_blog', category=category))
    if request.method == 'POST':
        flash(u'创建失败,请检查', category='danger')

    return render_template('blog/create.html', blog_form=blog_form, category=category,
                           action_url=url_for('.create_blog', category=category))
Ejemplo n.º 4
0
def change_blog(blog_id, category):
    """Edit the blog.
    :param id: blog id.
    """
    blog = api_blog.get(blog_id)
    if blog.user != current_user:
        flash(gettext('This is not your blog'), category='error')
        abort(403)

    blog_form = BlogForm(obj=blog)
    if blog_form.validate_on_submit():
        flash(u'更新成功')
        api_blog.update(blog, **blog_form.data)
        return redirect(url_for('.detail_blog', blog_id=blog_id, category=category))
    if request.method == 'POST':
        flash(u'更新失败,请检查', category='danger')
    return render_template('blog/create.html', blog_form=blog_form, category=category,
                           action_url=url_for('.change_blog', blog_id=blog_id, category=category))