当前位置: 首页>>代码示例>>Python>>正文


Python Blog.setup方法代码示例

本文整理汇总了Python中core.models.Blog.setup方法的典型用法代码示例。如果您正苦于以下问题:Python Blog.setup方法的具体用法?Python Blog.setup怎么用?Python Blog.setup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在core.models.Blog的用法示例。


在下文中一共展示了Blog.setup方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: step_4_pre

# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import setup [as 别名]

#.........这里部分代码省略.........

        install_directory = _join((_s.APPLICATION_PATH, _s.INSTALL_SRC_PATH))

        if (os.path.isdir(plugindir)):
            shutil.rmtree(plugindir)

        shutil.copytree(_join((install_directory, 'plugins')),
            plugindir)

        report.append("Default plugins copied successfully to data directory.")

        themedir = _join((_s.APPLICATION_PATH, 'data', 'themes'))

        if (os.path.isdir(themedir)):
            shutil.rmtree(themedir)

        shutil.copytree(_join((install_directory, 'themes')),
            themedir)

        report.append("Default themes copied successfully to data directory.")

        from core import plugins

        for x in os.listdir(plugindir):
            if (os.path.isdir(_join((plugindir, x))) is True and
                x != '__pycache__'):
                new_plugin = plugins.register_plugin(x, enable=True)
                report.append("New plugin '{}' installed successfully.".format(
                    new_plugin.name))

        from settings.defaults import DEFAULT_THEME
        from core.models import Theme
        new_theme = Theme.install_to_system(DEFAULT_THEME)

        report.append("Default theme created and installed successfully to system.")

        from core.models import Blog

        new_blog = Blog(
            site=new_site,
            name="Your first blog",
            description="The description for your first blog.",
            url=new_site.url,
            path=new_site.path,
            local_path=new_site.path,
            theme=new_theme
            )

        # TODO: add blog-level permission for new user as well

        new_blog.setup(new_user, new_theme)

        # TODO: Add default post

        report.append("Initial blog created successfully with default theme.")

    db.close()

    output_file_name = _join((_s.APPLICATION_PATH + _s.DATA_FILE_PATH, _s.INI_FILE_NAME))

    config_parser = ConfigParser()

    sections = ('db', 'path', 'key')

    for s in sections:
        for name, value in parser.items(s):
            try:
                config_parser.add_section(s)
            except DuplicateSectionError:
                pass
            config_parser.set(s, name, value)

#     if request.environ['HTTP_HOST'] == _s.DEFAULT_LOCAL_ADDRESS + _s.DEFAULT_LOCAL_PORT:
#         config_parser.add_section('server')
#         config_parser.set('server', 'DESKTOP_MODE', 'True')

    try:
        with open(output_file_name, "w", encoding='utf-8') as output_file:
            config_parser.write(output_file)
    except BaseException as e:
        raise SetupError(str(e.__class__.__name__) + ": " + str(e))

    try:
        os.remove(config_file_name)
    except OSError as e:
        from core.error import not_found
        if not_found(e) is False:
            raise e
    except Exception as e:
        raise e

    finished = '''
    <p>Installation is complete. <a href="{}">Return to the main page to begin using the application.</a>
    <script>
    $.get('/reboot',function(data){{}});
    </script>
    '''.format(_s.BASE_URL)

    return {'report':report,
        'finished':finished}
开发者ID:syegulalp,项目名称:mercury,代码行数:104,代码来源:install.py

示例2: blog_create_save

# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import setup [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)
开发者ID:syegulalp,项目名称:mercury,代码行数:74,代码来源:blog.py


注:本文中的core.models.Blog.setup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。