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


Python User.add_permission方法代码示例

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


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

示例1: step_4_pre

# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import add_permission [as 别名]
def step_4_pre():

    if get_ini('main', 'DO_DB_CHECK') is None:
        store_ini('main', 'DO_DB_CHECK', 'Y')
        from core.utils import reboot
        reboot()

    report = []

    from core.models import db, Template
    try:
        db.connect()
    except:
        raise

    db.close()

    report.append("Database connection successful.")

    from settings import DB
    DB.recreate_database()

    report.append("Database tables created successfully.")

    username = "Administrator"
    email = get_ini("user", "email")
    password = get_ini("user", "password")
    blog_path = get_ini("install", "blog_path")

    from core.utils import encrypt_password
    p_key = get_ini('key', 'PASSWORD_KEY')
    password = encrypt_password(password, p_key)

    db.connect()

    with db.atomic():

        from core.models import Site
        new_site = Site.create(
            name="Your first site",
            description="The description for your first site.",
            url=get_ini('main', 'base_url_root'),
            path=blog_path)

        report.append("Initial site created successfully.")

        from core.models import User
        new_user = User(
            name='Administrator',
            email=email,
            encrypted_password=password)

        new_user.save_pwd()

        from core.auth import role

        new_user_permissions = new_user.add_permission(
            permission=role.SYS_ADMIN,
            site=new_site
            )

        new_user_permissions.save()

        report.append("Initial admin user created successfully.")

        plugindir = _join((_s.APPLICATION_PATH, 'data', 'plugins'))

        import shutil

        # TODO: warn on doing this?
        # this should only happen with a totally fresh install, not an upgrade

        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))
#.........这里部分代码省略.........
开发者ID:syegulalp,项目名称:mercury,代码行数:103,代码来源:install.py


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