本文整理汇总了Python中models.Post.created方法的典型用法代码示例。如果您正苦于以下问题:Python Post.created方法的具体用法?Python Post.created怎么用?Python Post.created使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.created方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_posts
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import created [as 别名]
def convert_posts(self, board_id=181):
start_time = time.time()
cursor = connection.cursor()
cursor.execute("SELECT * FROM smf_messages WHERE id_board=%d ORDER BY id_msg ASC" % board_id)
rows = cursor.fetchall()
for row in rows:
try:
try:
profile = Profile.objects.get(old_user_id=row[4])
except Profile.DoesNotExist, e:
if not row[4] == 0:
print "Profile does not exist for %s" % (row[4])
profile = None
try:
topic = Topic.objects.get(old_topic_id=row[1])
except Topic.DoesNotExist, e:
print "Topic %s does not exist" % (row[1])
post = Post()
post.topic = topic
post.old_post_id = row[0]
if profile == None:
post.user = None
else:
post.user = profile.user
post.legacy_username= row[7]
post.created = self.fix_epoch(row[3])
post.updated = self.fix_epoch(row[11])
post.subject = row[6]
post.body = self.clean(row[13])
post.body_html = self.markup(self.clean(row[13]))
post.user_ip = row[9]
post.save()
post.topic.save()
示例2: create
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import created [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)
示例3: new_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import created [as 别名]
def new_post():
if not g.site.domain == g.user:
abort(403)
p = Post()
if request.method == "POST":
reqfile = request.files.get("file")
if reqfile:
f = File()
f.site = g.site.domain
f.name = reqfile.filename
f.content_type = reqfile.mimetype
f.slug, f.content_length = save_file(reqfile, blog.config["UPLOAD_FOLDER"])
f.save()
import datetime
p.site = g.site.domain
p.name = request.form.get("name")
p.created = datetime.datetime.utcnow()
p.year = p.created.year
p.month = p.created.month
p.day = p.created.day
slugs = [
__j.slug
for __j in Post.objects.filter(site=g.site.domain, year=p.year, month=p.month, day=p.day, slug=p.slug)
]
counter = 1
slug = slugify(p.name)
__slug = slug
while __slug in slugs:
counter += 1
__slug = "%s_%d" % (slug, counter)
p.slug = __slug
p.text = request.form.get("text")
if reqfile:
p.image_slug = f.slug
p.save()
return redirect(url_for("post", year=p.year, month=p.month, day=p.day, slug=p.slug))
return render_template("edit_post.html", post=p)
示例4: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import created [as 别名]
def post(self):
"""
Create new post
"""
json = {}
if not self.current_user:
json = {
'error': 1,
'msg': self._('Access denied')
}
self.write(json)
return
type = self.get_argument('type', Post.TYPE_POST)
title = self.get_argument('title', None)
content = self.get_argument('content', '')
slug = self.get_argument('slug', None)
format = self.get_argument('format', 'standard')
excerpt = self.get_argument('excerpt', '')
thumbnail = self.get_argument('thumbnail', '')
category_id = self.get_argument('category', None)
tags = self.get_argument('tags', '')
date = self.get_argument('date', None)
comment_open = bool(int(self.get_argument('comment_open', '1')))
if type not in [Post.TYPE_POST, Post.TYPE_PAGE]:
type = Post.TYPE_POST
if format not in ['standard', 'aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat']:
format = 'standard'
# valid arguments
if not slug:
json = {
'error': 1,
'msg': self._('Slug field can not be empty')
}
self.write(json)
return
elif self.get_post_by_slug(slug):
json = {
'error': 1,
'msg': self._('Slug already exists')
}
self.write(json)
return
if type == Post.TYPE_POST and not category_id:
json = {
'error': 1,
'msg': self._('Category field can not be empty')
}
self.write(json)
return
if type == Post.TYPE_POST:
category = self.get_category_by_id(category_id)
if not category:
json = {
'error': 1,
'msg': self._('No such category')
}
self.write(json)
return
if date:
if validators.date(date):
date = datetime.strptime(date, '%Y-%m-%d')
elif validators.datetime(date):
date = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
else:
date = datetime.utcnow()
else:
date = datetime.utcnow()
# now create post
post = Post()
post.type = type
post.created = date
post.title = title
post.slug = slug
post.content = content
post.html = wrap_content(content)
post.format = format
post.excerpt = excerpt
post.thumbnail = thumbnail
post.comment_open = comment_open
if type == Post.TYPE_POST:
post.category_id = category.id
else:
post.category_id = 1 # default category
# update category post count
if type == Post.TYPE_POST:
category.post_count += 1
self.db.add(category)
# commit
self.db.add(post)
self.db.commit()
# create tags
if type == Post.TYPE_POST and tags:
post.tag_ids = self.create_tags(tags.split(','), post.id)
self.db.add(post)
self.db.commit()
# delete cache
keys = ['PostList:1', 'CategoryPostList:%s:1' %
category.id, 'SystemStatus', 'ArchiveHTML', 'TagCloud']
self.cache.delete_multi(keys)
#.........这里部分代码省略.........