本文整理汇总了Python中feincms.module.page.models.Page.save方法的典型用法代码示例。如果您正苦于以下问题:Python Page.save方法的具体用法?Python Page.save怎么用?Python Page.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类feincms.module.page.models.Page
的用法示例。
在下文中一共展示了Page.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_structure
# 需要导入模块: from feincms.module.page.models import Page [as 别名]
# 或者: from feincms.module.page.models.Page import save [as 别名]
def import_structure(f, root_id=None):
"""docstring for import_structure"""
parents = {}
if root_id:
parents[0] = Page.objects.get(id=root_id)
else:
parents[0] = None
kwargs = {
'active': True,
'in_navigation': True,
}
for line in f:
match = re.match(r"^(#+) (\{[^)]*} )?(.*)$", unicode(line))
if match:
level = len(match.group(1))
opts = match.group(2)
if opts:
js = json.loads(opts)
kwargs.update(**dict([(str(k), v) for k, v in js.items()]))
title = match.group(3)
parent = parents[level-1]
parent_page = Page.objects.get(pk=parent.pk) if parent else None
p = Page(
title=title,
slug=slugify(title),
parent=parent_page,
**kwargs
)
p.save()
parents[level] = p
print('adding FeinCMS page: %s' % title)
示例2: import_structure
# 需要导入模块: from feincms.module.page.models import Page [as 别名]
# 或者: from feincms.module.page.models.Page import save [as 别名]
def import_structure(f, root_id=None):
"""docstring for import_structure"""
parents = {}
if root_id:
parents[0] = Page.objects.get(id=root_id)
else:
parents[0] = None
for line in f:
match = re.match(r"^(#+) (.*)$", line)
if match:
level = len(match.group(1))
title = match.group(2)
parent = parents[level - 1]
parent_page = Page.objects.get(pk=parent.pk) if parent else None
p = Page(active=True, title=title, slug=slugify(title), in_navigation=True, parent=parent_page)
for field in ("navigation_type",):
if parent and parent.__dict__.get(field, None):
p.__dict__[field] = parent.__dict__[field]
p.save()
parents[level] = p
print("adding FeinCMS page: %s" % title)