def create(): db.create_all() for sitename in site_names: site = Site(name=sitename) site.inbuildings_config = InbuildingsConfig(enabled=False, key="") db.session.add(site) for typename in asset_types: asset_type = AssetType(name=typename) db.session.add(asset_type) for pointname in point_types: point_type = PointType(name=pointname) db.session.add(point_type) site = Site.query.filter_by(name=site_names[0]).one() asset_type = AssetType.query.filter_by(name=asset_types[0]).one() asset = Asset(name=test_asset_name, site=site, type=asset_type, health=0, priority=1, notes='') # add one of each point type to dummy unit for pointtype in point_types: point = PointType.query.filter_by(name=pointtype).one() asset_point = AssetPoint(name=pointtype, type=point, asset=asset) asset.points.append(asset_point) db.session.add(asset) db.session.commit() db.session.close()
def regenerate(): # ensure session is closed db.session.close() # regenerate all tables in the database, based on models db.drop_all() db.create_all() # add some initial data for sitename in site_names: site = Site(name=sitename) site.inbuildings_config = InbuildingsConfig(enabled=False, key="") db.session.add(site) for typename in asset_types: asset_type = AssetType(name=typename) db.session.add(asset_type) for pointname in point_types: point_type = PointType(name=pointname) db.session.add(point_type) site = Site.query.filter_by(name=site_names[0]).one() asset_type = AssetType.query.filter_by(name=asset_types[0]).one() asset = Asset(name=test_asset_name, site=site, type=asset_type, health=0, priority=1, notes='') # add one of each point type to dummy unit for pointtype in point_types: point = PointType.query.filter_by(name=pointtype).one() asset_point = AssetPoint(name=pointtype, type=point, asset=asset) asset.points.append(asset_point) # add and commit to db db.session.add(asset) db.session.commit() # map assets to algorithms map_all() # generate users admin = User(username=admin_user, password=user_manager.hash_password(admin_pw), active=True) test = User(username=test_user, password=user_manager.hash_password(test_pw), active=True) db.session.add(admin) db.session.add(test) # generate roles for role_name in roles: role = Role(name=role_name, label=role_name) admin.roles.append(role) db.session.commit() db.session.close()