本文整理汇总了Python中blog.models.Category.alias方法的典型用法代码示例。如果您正苦于以下问题:Python Category.alias方法的具体用法?Python Category.alias怎么用?Python Category.alias使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Category
的用法示例。
在下文中一共展示了Category.alias方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_xml
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import alias [as 别名]
def parse_xml():
et = ET.ElementTree(file='/home/jasper/Downloads/jasper.xml')
root = et.getroot()
user = User.objects.get(username='jasper')
count = 1
alias_re = re.compile(r'^[a-z|0-9|\-]+$')
for channel in root.findall('channel'):
for item in channel.findall('item'):
title = item.find('title')
post_name = item.find('{http://wordpress.org/export/1.2/}post_name')
pubDate = item.find('pubDate')
description = item.find('description')
content = item.find('{http://purl.org/rss/1.0/modules/content/}encoded')
categories = item.findall('category')
tags = []
category = Category()
for ca in categories:
if ca.attrib['domain'] == 'post_tag':
tags.append(ca.text)
else:
try:
category = Category.objects.get(name=ca.text)
except Category.DoesNotExist:
category.name = ca.text
if alias_re.match(ca.attrib['nicename']):
category.alias = ca.attrib['nicename']
else:
category.alias = category.name
print category.alias
category.save()
try:
Post.objects.get(title=title.text)
print title.text, 'already exist'
continue
except Post.DoesNotExist:
pass
post = Post()
post.title = title.text
post.category = category
if alias_re.match(post_name.text):
post.alias = post_name.text
else:
post.alias = title.text
print post.alias
post.content = content.text
post.content_html = content.text
if not description.text:
post.summary = content.text[:140]
else:
post.summary = description.text
post.is_old = True
post.tags = ','.join(tags)
create_time = pubDate.text[:-6]
tf = '%a, %d %b %Y %H:%M:%S'
post.old_pub_time = datetime.strptime(create_time, tf)
print post.old_pub_time
post.author = user
try:
post.save()
print count, post
count += 1
except Exception, e:
print e