本文整理汇总了Python中blog.models.Blog.get_by_unique方法的典型用法代码示例。如果您正苦于以下问题:Python Blog.get_by_unique方法的具体用法?Python Blog.get_by_unique怎么用?Python Blog.get_by_unique使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Blog
的用法示例。
在下文中一共展示了Blog.get_by_unique方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import get_by_unique [as 别名]
def make(self, **kwargs):
make_path = kwargs.get("make", "")
if not make_path:
smart_print(u"请指定文件名")
post_root = settings.POST_DIR_ROOT
path = os.path.join(post_root, "%s.md" %make_path)
file_handler = open(path, "r")
text = file_handler.read()
file_handler.close()
html = md.convert(text.decode("utf-8"))
metadata = parse_meta(md)
metadata['content'] = HtmlFormatter.format_html(html)
title = metadata.get("title", "")
if not title:
print("MD文件无title")
return
blog = Blog.get_by_unique(title=title)
if not blog:
blog = Blog()
for key, value in metadata.items():
setattr(blog, key, value)
blog.save()
smart_print("博客: %s,存储成功" %title)
示例2: make
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import get_by_unique [as 别名]
def make(self, **kwargs):
make_path = kwargs.get("make", "")
if not make_path:
smart_print(u"请指定文件名")
post_root = settings.POST_DIR_ROOT
path = os.path.join(post_root, "%s.md" %make_path)
file_handler = open(path, "r")
text = file_handler.read()
file_handler.close()
text = text.decode("utf-8")
# at = At2Section()
html = md.convert(text)
metadata = parse_meta(md)
prog = re.compile(pattern, re.DOTALL)
match = prog.match(html)
# parsed_html = at.parse(match.group(1))
metadata['content'] = html
title = metadata.get("title", "")
if not title:
print("MD文件无title")
return
blog = Blog.get_by_unique(title=title)
if not blog:
blog = Blog(**metadata)
else:
for key, value in metadata.items():
setattr(blog, key.lower(), value)
blog.save()
smart_print("博客: %s,存储成功" %title)