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


Python Role.insert_roles方法代码示例

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


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

示例1: setup_general

# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def setup_general():
    """Runs the set-up needed for both local development and production.
       Also sets up first admin user."""
    Role.insert_roles()
    admin_query = Role.query.filter_by(name='Administrator')
    if admin_query.first() is not None:
        if User.query.filter_by(email=Config.ADMIN_EMAIL).first() is None:
            user = User(
                first_name='Radha',
                last_name='Krishna',
                password=Config.ADMIN_PASSWORD,
                confirmed=True,
                email=Config.ADMIN_EMAIL)
            db.session.add(user)
            db.session.commit()
            print('Added administrator {}'.format(user.full_name())) 
开发者ID:gita,项目名称:BhagavadGita,代码行数:18,代码来源:manage.py

示例2: setup_general

# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def setup_general():
    """Runs the set-up needed for both local development and production.
       Also sets up first admin user."""
    Role.insert_roles()
    admin_query = Role.query.filter_by(name='Administrator')
    if admin_query.first() is not None:
        if User.query.filter_by(email=Config.ADMIN_EMAIL).first() is None:
            user = User(
                first_name='Admin',
                last_name='Account',
                password=Config.ADMIN_PASSWORD,
                confirmed=True,
                email=Config.ADMIN_EMAIL)
            db.session.add(user)
            db.session.commit()
            print('Added administrator {}'.format(user.full_name())) 
开发者ID:abhisuri97,项目名称:penn-club-ratings,代码行数:18,代码来源:manage.py

示例3: deploy

# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def deploy():
    """Run deployment tasks."""
    from flask_migrate import upgrade
    from app.models import Role, User

    # migrate database to latest revision
    upgrade()

    # create user roles
    Role.insert_roles()

    # create self-follows for all users
    User.add_self_follows() 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:15,代码来源:manage.py

示例4: setUp

# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        Role.insert_roles()
        self.client = self.app.test_client() 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:9,代码来源:test_api.py

示例5: setUp

# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        Role.insert_roles() 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:8,代码来源:test_user_model.py

示例6: setUpClass

# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def setUpClass(cls):
        # start Chrome
        try:
            cls.client = webdriver.Chrome(service_args=["--verbose", "--log-path=test-reports/chrome.log"])
        except:
            pass

        # skip these tests if the browser could not be started
        if cls.client:
            # create the application
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            # suppress logging to keep unittest output clean
            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel("ERROR")

            # create the database and populate with some fake data
            db.create_all()
            Role.insert_roles()
            User.generate_fake(10)
            Post.generate_fake(10)

            # add an administrator user
            admin_role = Role.query.filter_by(permissions=0xff).first()
            admin = User(email='john@example.com',
                         username='john', password='cat',
                         role=admin_role, confirmed=True)
            db.session.add(admin)
            db.session.commit()

            # start the Flask server in a thread
            threading.Thread(target=cls.app.run).start()

            # give the server a second to ensure it is up
            time.sleep(1) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:40,代码来源:test_selenium.py

示例7: setUp

# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        Role.insert_roles()
        self.client = self.app.test_client(use_cookies=True) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:9,代码来源:test_client.py

示例8: deploy

# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def deploy():
    from flask_migrate import upgrade
    from app.models import Role
    # 迁移数据库到最新修订版本
    upgrade()
    # 创建用户角色
    Role.insert_roles() 
开发者ID:Blackyukun,项目名称:Simpleblog,代码行数:9,代码来源:manage.py

示例9: test_roles_and_permissions

# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def test_roles_and_permissions(self):
        Role.insert_roles()
        u = User(email='john@example.com', password='cat')
        self.assertTrue(u.operation(Permission.WRITE_ARTICLES))
        self.assertFalse(u.operation(Permission.MODERATE_COMMENTS)) 
开发者ID:Blackyukun,项目名称:Simpleblog,代码行数:7,代码来源:test_user_model.py

示例10: test_roles_and_permissions

# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def test_roles_and_permissions(self):
        Role.insert_roles()
        u = User(email='user@example.com', password='password')
        self.assertTrue(u.can(Permission.GENERAL))
        self.assertFalse(u.can(Permission.ADMINISTER)) 
开发者ID:gita,项目名称:BhagavadGita,代码行数:7,代码来源:test_user_model.py

示例11: test_make_administrator

# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def test_make_administrator(self):
        Role.insert_roles()
        u = User(email='user@example.com', password='password')
        self.assertFalse(u.can(Permission.ADMINISTER))
        u.role = Role.query.filter_by(
            permissions=Permission.ADMINISTER).first()
        self.assertTrue(u.can(Permission.ADMINISTER)) 
开发者ID:gita,项目名称:BhagavadGita,代码行数:9,代码来源:test_user_model.py

示例12: test_administrator

# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def test_administrator(self):
        Role.insert_roles()
        r = Role.query.filter_by(permissions=Permission.ADMINISTER).first()
        u = User(email='user@example.com', password='password', role=r)
        self.assertTrue(u.can(Permission.ADMINISTER))
        self.assertTrue(u.can(Permission.GENERAL))
        self.assertTrue(u.is_admin()) 
开发者ID:gita,项目名称:BhagavadGita,代码行数:9,代码来源:test_user_model.py

示例13: setUpClass

# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def setUpClass(cls):
        # start Firefox
        try:
            cls.client = webdriver.Firefox()
        except:
            pass

        # skip these tests if the browser could not be started
        if cls.client:
            # create the application
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            # suppress logging to keep unittest output clean
            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel("ERROR")

            # create the database and populate with some fake data
            db.create_all()
            Role.insert_roles()
            User.generate_fake(10)
            Post.generate_fake(10)

            # add an administrator user
            admin_role = Role.query.filter_by(permissions=0xff).first()
            admin = User(email='john@example.com',
                         username='john', password='cat',
                         role=admin_role, confirmed=True)
            db.session.add(admin)
            db.session.commit()

            # start the Flask server in a thread
            threading.Thread(target=cls.app.run).start()

            # give the server a second to ensure it is up
            time.sleep(1) 
开发者ID:miguelgrinberg,项目名称:flasky-first-edition,代码行数:40,代码来源:test_selenium.py

示例14: deploy

# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade
    from app.models import Role, User

    # migrate database to latest revision
    upgrade()

    # create user roles
    Role.insert_roles()

    # create self-follows for all users
    User.add_self_follows() 
开发者ID:miguelgrinberg,项目名称:flasky-with-celery,代码行数:15,代码来源:manage.py

示例15: deploy

# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def deploy():
    """Run deployment tasks."""
    # 插入角色
    Role.insert_roles()
    # 插入管理员
    User.insert_admin() 
开发者ID:adisonhuang,项目名称:flask-blog,代码行数:8,代码来源:manage.py


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