本文整理汇总了Python中models.Entry.old_id方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.old_id方法的具体用法?Python Entry.old_id怎么用?Python Entry.old_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Entry
的用法示例。
在下文中一共展示了Entry.old_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_from_json
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import old_id [as 别名]
def import_from_json(data, show=False):
ret = []
if show:
print len([i for i in Entry.all()])
# Deserialize
objects = simplejson.loads(data)
for obj in objects:
if obj['model'] != 'blog.entry':
continue
#if obj['fields']['media_type'] == 'I':
# print "'%s': %s"%(obj['fields']['slug'], obj['pk'])
#continue
if obj['fields']['media_type'] != 'P' or not obj['fields']['published']:
continue
msg = '%d %s'%(obj['pk'], obj['fields']['title'])
if show:
print msg
else:
ret.append(msg)
# Blog entry
try:
entry = Entry.all().filter('old_id =', int(obj['pk']))[0]
except IndexError:
entry = Entry()
entry.old_id = obj['pk']
m = RE_DATETIME.match(obj['fields']['pub_date'])
groups = [int(i) for i in m.groups()]
entry.pub_date = datetime.datetime(*groups)
entry.title = obj['fields']['title']
entry.description = obj['fields']['description']
entry.format = obj['fields']['format']
entry.published = True
entry.show_in_rss = False
entry.slug = obj['fields']['slug']
entry.tags = [db.Category(TAGS[tag]) for tag in obj['fields']['tags']]
text = obj['fields']['content']
text = text.replace('http://media.marinhobrandao.com/','/')
f = RE_IMG_URL.findall(text)
rep = []
for url in f:
m = RE_IMG_URL2.match(url)
new_url = '/media/img/upload/%s'%IMAGES[m.group(1)]
if show:
print '\t', new_url
text = text.replace(url, new_url)
entry.text = text
entry.save()
# Gallery image
msg = [i.slug for i in Entry.all()]
if show:
print msg
else:
ret.append(' '.join([i for i in msg]))