本文整理汇总了Python中post.Post.set_status方法的典型用法代码示例。如果您正苦于以下问题:Python Post.set_status方法的具体用法?Python Post.set_status怎么用?Python Post.set_status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类post.Post
的用法示例。
在下文中一共展示了Post.set_status方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_publish_now
# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import set_status [as 别名]
def process_publish_now(self, publish_future=False):
"""
Scans PUBLISH_NOW_DIR for post with 'publish' status.
Args:
publish_future:
if False, won't publish posts with date later than today.
if True, will publish everything in directory.
"""
for f in os.listdir(self.s.DRAFTS_PUBLISH_NOW_DIR):
if f.endswith(self.s.MD_EXT):
source_file = os.path.join(self.s.DRAFTS_PUBLISH_NOW_DIR, f)
post = Post(source_file, self.s)
if not publish_future:
# skip future posts
if self.is_in_future(post):
continue
post.set_status(published=True)
post.normalize()
# Check layout: post or page?
if post.layout.lower()==self.s.POST_TYPE_PAGE.lower():
dest_fname = "%s%s" % (post.slug, self.s.MD_EXT)
dest_dir = self.s.PAGES_DIR
tools.mkdirp(dest_dir)
try:
shutil.copy(source_file, os.path.join(dest_dir, dest_fname))
os.remove(source_file)
self.remove_post_review(post)
except IOError as e:
logging.error('Could not move file %s to %s. Error: %s.' % (source_file,
os.path.join(dest_dir, dest_fname), e))
else:
sequence = self.get_next_sequence(post.date.year, post.date.month, post.date.day)
# output filename has form YYYYMMDD-p##-slug.md
if sequence > self.s.MAX_POSTS_PER_DAY:
raise Exception("Max posts per day is 99. Got %d posts for %04d-%02d-%02d." %
sequence, post.date.year, post.date.month, post.date.day
)
dest_fname = "%04d%02d%02d-p%02d-%s%s" % (post.date.year,
post.date.month, post.date.day,
sequence,
post.slug, self.s.MD_EXT)
# copy post to posts dir YYYY/MM
dest_dir = os.path.join(self.s.POSTS_DIR, "%04d" % post.date.year, "%02d" % post.date.month)
tools.mkdirp(dest_dir)
try:
shutil.copy(source_file, os.path.join(dest_dir, dest_fname))
os.remove(source_file)
except IOError as e:
logging.error('Could not move file %s to %s. Error: %s.' % (source_file,
os.path.join(dest_dir, dest_fname), e))