示例#1
0
def post_from_draft(draft_id):
    db = g.db
    user = g.user
    title = request.values.get('title')
    body = request.values.get('body')
    theme = request.values.get('theme-id')
    now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    abstext = get_abstract(html_strip(body))
    post = Post(title=title,
                time_post=now,
                time_update=now,
                body=body,
                theme=theme,
                author_id=user.id,
                abstract=abstext)
    post.save()
    draft = Draft(id=draft_id,
                  title=title,
                  time_update=now,
                  body=body,
                  author_id=user.id,
                  abstract=abstext)
    draft.update()
    add_moment(operation='发表了文章',
               context=abstext,
               url_name=title,
               user_id=user.id,
               url='/topic/%s' % post.id)
    return redirect('/topic/%s' % post.id)
示例#2
0
def update_draft(draft_id):
    db = g.db
    user = g.user
    title = request.values.get('title')
    body = request.values.get('body')
    now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    abstext = get_abstract(html_strip(body))
    draft = Draft(id=draft_id,
                  title=title,
                  time_update=now,
                  body=body,
                  author_id=user.id,
                  abstract=abstext)
    draft.update()
    return redirect_back()
示例#3
0
def edit_post(postid):
    db = g.db
    user = g.user
    body = request.values.get('body')
    abstext = get_abstract(html_strip(body))
    now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    post = Post(id=postid,
                body=body,
                time_post=now,
                time_update=now,
                abstract=abstext)
    post.update()
    p = db.session.query(Post).filter(Post.id == postid).one()
    add_moment(operation='编辑了文章',
               url_name=p.title,
               user_id=user.id,
               url='/topic/%s' % postid)
    return redirect('/topic/%s' % postid)