本文整理汇总了Python中models.Post.user_id方法的典型用法代码示例。如果您正苦于以下问题:Python Post.user_id方法的具体用法?Python Post.user_id怎么用?Python Post.user_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.user_id方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: publish
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import user_id [as 别名]
def publish(user_id):
form = PublishBlogForm()
posts = Post()
if form.validate_on_submit():
blog_body = request.form.get("body")
if not len(strip(blog_body)):
flash("The content is necessray!")
return redirect(url_for("publish", user_id=user_id))
posts.body = blog_body
posts.timestamp = datetime.datetime.now()
posts.user_id = user_id
try:
db.session.add(posts)
db.session.commit()
except:
flash("Database error!")
return redirect(url_for("publish", user_id=user_id))
flash("Publish Successful!", "success")
return redirect(url_for("publish", user_id=user_id))
return render_template(
"publish.html",
form=form)
示例2: create_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import user_id [as 别名]
def create_post():
form = forms.PostForm(request.form)
if request.method=='POST':
post = Post()
post.title = form.title.data
post.content = form.content.html
post.toc = form.content.toc
post.time_stamp = datetime.now()
post.user_id = current_user.id
tags = form.tags.data.split(',')
post.tags = form.tags.data
ids = []
for tag in tags:
t = Tag.query.filter_by(name=tag).first()
if not t:
db.session.add(Tag(name=tag))
db.session.commit()
t = Tag.query.filter_by(name=tag).first()
ids.append(t.id)
db.session.add(post)
db.session.commit()
p = current_user.posts.order_by(Post.id.desc()).first()
for id in ids:
db.session.add(TagMap(id,p.id))
db.session.commit()
#flash('Your post have been accepted.')
return redirect(url_for('post',id=p.id))
else:
return render_template('create_post.html',form=form)
示例3: publishs
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import user_id [as 别名]
def publishs(user_id):
form = PublishBlogForm()
if form.validate_on_submit():
post_title = request.form.get("title")
post_body = request.form.get("body")
if not len(strip(post_body)) or not len(strip(post_title)):
flash("不能提交空内容!")
return redirect(url_for("publish", user_id=user_id))
post = Post()
post.body = post_body
post.title = post_title
post.timestamp = datetime.datetime.now()
post.user_id = user_id
try:
db.session.add(post)
db.session.commit()
except:
flash("DataBase error!")
return redirect(url_for("publish", user_id=user_id))
return redirect(url_for("user", user_id=user_id))
return render_template(
"publish.html",
form = form)
示例4: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import user_id [as 别名]
def post():
form = PostForm()
if form.validate_on_submit():
post_obj = Post(post_title=form.post_title.data)
post_obj.description = form.description.data
post_obj.user_id = g.user
post_obj.save()
flash('Created')
return redirect(url_for('main.post'))
return render_template('post.html', form=form)
示例5: write_process
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import user_id [as 别名]
def write_process():
if not session['logged_in']:
return redirect(url_for('index'))
u = User.query.filter_by(email=session['user_name']).first()
p = Post()
p.title = request.form['post_title']
p.body = request.form['post_body']
p.timestamp = datetime.datetime.utcnow()
p.user_id = u.id
db.session.add(p)
db.session.commit()
return redirect(url_for('index'))
示例6: create
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import user_id [as 别名]
def create():
post = Post()
form = PostCreateForm()
if request.method == 'POST' and form.validate_on_submit():
form.populate_obj(post)
post.created = datetime.datetime.now()
post.user_id = g.user.id
db.session.add(post)
db.session.commit()
flash('Your changes have been saved.')
return redirect(url_for('index'))
return render_template('edit.html',
form = form)
示例7: User
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import user_id [as 别名]
from models import User, Post
User.create(name='Amy', email='[email protected]') # return an instance of User
User.create(User.name == 'Join', User.email == '[email protected]')
user = User(name='Mark', email='[email protected]')
user.save()
post = Post()
post.name = 'Hello World'
post.user_id = 1
post.save()
示例8: save_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import user_id [as 别名]
def save_post(post_id=None):
"""Save Post to database
If post_id is None a new Post will be inserted in the database. Otherwise
the existing Post will be updated.
"""
message = 'Post updated'
orig_tags = []
post_form = PostForm(request.form)
if not post_form.validate():
flash('ERROR: errors detected. Post NOT saved!', category='error')
return edit_post(post_id=post_id, post_form=post_form)
# test if we're creating a new post, or updating an existing one
if post_id is None:
post = Post()
post.status_id = 1
post.user_id = session['user_id']
post.createdate = datetime.now()
else:
post = get_post(post_id)
orig_tags = [tag for tag in post.tags]
post_form.populate_obj(post)
post.lastmoddate = datetime.now()
# compile input to html
post.compile(app.config['REPL_TAGS'])
# update pubdate if post's pubdate is None and its status is set
# to public
if request.form['status'] == 'public' and \
unicode(post.status) != 'public' and \
post.pubdate is None:
post.pubdate = datetime.now()
post.status = get_status(request.form['status'])
if post.slug is None:
post.slug = slugify(post.title)
if post_id is None:
db_session.add(post)
message = 'New post was successfully added'
db_session.commit()
for tag in orig_tags:
recalculate_tagcount(tag)
for tag in post.tags:
if tag not in orig_tags:
recalculate_tagcount(tag)
db_session.commit()
flash(message, category='info')
return redirect(url_for('edit_post', post_id=post.id))