本文整理汇总了Python中models.Post.timestamp方法的典型用法代码示例。如果您正苦于以下问题:Python Post.timestamp方法的具体用法?Python Post.timestamp怎么用?Python Post.timestamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.timestamp方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: publish
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import timestamp [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: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import timestamp [as 别名]
def post(request, slug):
"""Adds a post to the chat identified by the given slug. Also
updates the current user's latest ping time, reflecting activity
in this chat.
This view will handle either normal POSTs or POSTs via Ajax (in
which case it returns a JSON response with the timestamp of the
created post and the post's HTML-escaped content."""
chat = get_object_or_404(Chat, slug=slug)
if request.POST:
content = request.POST.get('content', '')
post = Post(user=request.user, parent=chat, content=content)
post.save()
# Update the user's last ping value to reflect active
# participation in this chat.
user_ping(request.user)
# If we're processing an Ajax request, return the timestamp of
# the post we just created and its HTML-escaped content in
# JSON format.
if request.is_ajax():
response = json.dumps({
'timestamp': post.timestamp(),
'content': force_escape(post.content),
})
return HttpResponse(response, mimetype='application/json')
# Redirect the user back to this chat's page for normal, non-Ajax
# requests.
return HttpResponseRedirect(chat.get_absolute_url())
示例3: publishs
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import timestamp [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: write_process
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import timestamp [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'))
示例5: add_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import timestamp [as 别名]
def add_post():
form = PostForm(request.form)
if request.method == 'POST' and form.validate():
post = Post()
form.populate_obj(post)
post.author_id = g.user.id
post.timestamp = datetime.utcnow()
db.session.add(post)
db.session.commit()
return redirect(url_for('show_post', post_id=post.id))
return render_template('content_add_post.html',
title='Add post',
form=form,
user=g.user)