本文整理汇总了Python中core.models.Blog.validate方法的典型用法代码示例。如果您正苦于以下问题:Python Blog.validate方法的具体用法?Python Blog.validate怎么用?Python Blog.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.models.Blog
的用法示例。
在下文中一共展示了Blog.validate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: blog_create_save
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import validate [as 别名]
def blog_create_save(site_id):
user = auth.is_logged_in(request)
site = Site.load(site_id)
permission = auth.is_site_admin(user, site)
errors = []
new_blog = Blog(
site=site,
name=request.forms.getunicode('blog_name'),
description=request.forms.getunicode('blog_description'),
url=request.forms.getunicode('blog_url'),
path=request.forms.getunicode('blog_path'),
set_timezone=request.forms.getunicode('blog_timezone'),
# theme=get_default_theme(),
theme=Theme.default_theme()
)
try:
new_blog.validate()
except Exception as e:
errors.extend(e.args[0])
if len(errors) == 0:
from core.libs.peewee import IntegrityError
try:
new_blog.setup(user, Theme.default_theme())
# new_blog.theme)
except IntegrityError as e:
from core.utils import field_error
errors.append(field_error(e))
if len(errors) > 0:
status = utils.Status(
type='danger',
no_sure=True,
message='The blog could not be created due to the following problems:',
message_list=errors)
from core.libs import pytz
tags = template_tags(site=site,
user=user)
tags.status = status
tags.blog = new_blog
themes = Theme.select()
return template('ui/ui_blog_settings',
section_title="Create new blog",
# search_context=(search_context['sites'], None),
menu=generate_menu('site_create_blog', site),
nav_default='all',
themes=themes,
timezones=pytz.all_timezones,
** tags.__dict__
)
else:
tags = template_tags(user=user, site=site,
blog=new_blog)
status = utils.Status(
type='success',
message='''
Blog <b>{}</b> was successfully created. You can <a href="{}/blog/{}/newpage">start posting</a> immediately.
'''.format(
new_blog.for_display,
BASE_URL, new_blog.id)
)
tags.status = status
return report(tags, 'site_create_blog', site)