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()
def create_admin_user_to_db(): print(db.session.query(User).count()) user = User.query.filter(User.email == "admin").first() user_role = Role.query.filter(Role.name == "user").first() super_user_role = Role.query.filter(Role.name == "superuser").first() if not user_role: user_role = Role(name="user") db.session.add(user_role) db.session.commit() if not super_user_role: super_user_role = Role(name="superuser") db.session.add(super_user_role) db.session.commit() if not user: now = datetime.now() user_datastore.create_user(email='admin', password=encrypt_password('8Lapis6Luna'), connect_date=now, roles=[user_role, super_user_role]) db.session.commit() print("admin user created")
def init(): from app import Role, User db.drop_all() db.create_all() Role.insert_roles() User.generate_admin() fake_user(10) fake_device(15)
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) # 如果启用了use_cookies就可以像浏览器一样发送cookies
def db_recreate(default_data=True, sample_data=False): "Recreates database tables (same as issuing 'drop' and then 'create')" db_drop() db_create() admin_role = Role("ADMIN", "Administratör") user_role = Role("USER", "Användare") db.session.add_all([user_role, admin_role]) db.session.commit()
def setUpClass(cls): cls.app = create_app('testing') cls.app_context = cls.app.app_context() cls.app_context.push() db.create_all() Role.insert_roles() cls.acc = Account(password='******', email='*****@*****.**') db.session.add(cls.acc) db.session.commit()
def populate(): Role.insert_roles() user = Account(password='******', email='*****@*****.**', confirmed=True) user2 = Account(password='******', email='*****@*****.**', confirmed=True) new_category = Category(name='Kategoria1') new_category2 = Category(name='Kategoria2') new_product = Product(name='Produkt1', description='Opis1', weight=1.99, price=12.99, category=new_category, seller=user) new_product2 = Product(name='Produkt2', description='Opis2', weight=20, price=100, category=new_category2, seller=user2) db.session.add_all([user, user2, new_product, new_product2, new_category, new_category2]) db.session.commit()
def deploy(): """Run deployment tasks.""" # migrate database to latest revision db.create_all() # create or update user roles Role.insert_role() Category.generate_default() # ensure all users are following themselves User.add_self_follows() User.generate_fake(50) Post.generate_fake(50)
def insert_roles(): roles = ('Student', 'Admin') for r in roles: role = Role.query.filter_by(name=r).first() if role is None: role = Role(name=r) db.session.add(role) db.session.commit()
def createRole(): print('creating role') name = request.json.get('name') role = Role(name=name) db.session.add(role) db.session.commit() return jsonify({'operation': 'success'})
def build_sample_db(): """ Populate a small db with some example entries. """ db.drop_all() db.create_all() with app.app_context(): user_role = Role(name='user') super_user_role = Role(name='superuser') db.session.add(user_role) db.session.add(super_user_role) db.session.commit() test_user = user_datastore.create_user( first_name='Admin', email='admin', password=encrypt_password('admin'), roles=[user_role, super_user_role]) first_names = ['Harry', 'Amelia', 'Oliver'] last_names = ['Brown', 'Smith', 'Patel'] for i in range(len(first_names)): tmp_email = first_names[i].lower() + "." + last_names[i].lower( ) + "@example.com" tmp_pass = ''.join( random.choice(string.ascii_lowercase + string.digits) for i in range(10)) user_datastore.create_user(first_name=first_names[i], last_name=last_names[i], email=tmp_email, password=encrypt_password(tmp_pass), roles=[ user_role, ]) db.session.commit() return
def create_user(): admin_group = Groups(name="管理员") db.session.add(admin_group) admin_role = Role(name="admin", permissions=0xff) admin_user = User(username="******", email="*****@*****.**", active=True, job="admin") admin_user.password = "******" admin_user.roles = [admin_role] admin_group.roles = [admin_role] db.session.add(admin_role) db.session.add(admin_user) db.session.commit() print("Roles added!")
def addroles(): if request.method == 'GET': return render_template('addroles.html') if request.method == 'POST': new_role = request.form.get('r_name') old_role = Role.query.filter_by(r_name=new_role).first() if old_role: msg = '用户已存在,添加失败' return render_template('addroles.html', msg=msg) else: new_role = Role(r_name=new_role) db.session.add(new_role) db.session.commit() msg = '用户添加成功' return render_template('addroles.html', msg=msg)
def build_sample_db(): """ Populate a small db with some example entries. """ db.drop_all() db.create_all() with app.app_context(): super_user_role = Role(name='superuser') db.session.add(super_user_role) db.session.commit() test_user = user_datastore.create_user( name='superuser', email='*****@*****.**', password=encrypt_password('123456'), roles=[super_user_role]) db.session.commit() return
def init(): from app import Role, User Role.insert_roles() User.generate_admin()
def add_roles(): admin_role = Role("ADMIN", "Administratör") user_role = Role("USER", "Användare") db.session.add_all([user_role, admin_role]) db.session.commit()
# NARVAEZ BETZABETH 2018106117 from app import db, Role, User, Post if __name__ == '__main__': db.create_all() admin_role = Role(name='Admin') mod_role = Role(name='Moderator') user_role = Role(name='User') user_john = User(username='******', role=admin_role) user_susan = User(username='******', role=user_role) user_david = User(username='******', role=user_role) db.session.add_all( [admin_role, mod_role, user_role, user_john, user_susan, user_david]) # print(admin_role.id) # db.session.commit() # print(admin_role.id) admin_role.name = 'Adminstrator' db.session.add(admin_role) # db.session.commit() # db.session.delete(mod_role) # db.session.commit() # joined = User.query.join(Role\ # .add_columns(User.id, User.username, User.role_id, Role.name)\ # .filter(User.role)) bp_ex1 = Post(body='example 1', title="example 1", user_id=user_john.id)