本文整理汇总了Python中HydraServer.db.DBSession.delete方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.delete方法的具体用法?Python DBSession.delete怎么用?Python DBSession.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HydraServer.db.DBSession
的用法示例。
在下文中一共展示了DBSession.delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_resourcegroupitem
# 需要导入模块: from HydraServer.db import DBSession [as 别名]
# 或者: from HydraServer.db.DBSession import delete [as 别名]
def delete_resourcegroupitem(item_id,**kwargs):
group_item_i = _get_item(item_id)
scenario._check_can_edit_scenario(group_item_i.scenario_id, kwargs['user_id'])
DBSession.delete(group_item_i)
DBSession.flush()
return 'OK'
示例2: _delete_resourcescenario
# 需要导入模块: from HydraServer.db import DBSession [as 别名]
# 或者: from HydraServer.db.DBSession import delete [as 别名]
def _delete_resourcescenario(scenario_id, resource_scenario):
ra_id = resource_scenario.resource_attr_id
try:
sd_i = DBSession.query(ResourceScenario).filter(ResourceScenario.scenario_id==scenario_id, ResourceScenario.resource_attr_id==ra_id).one()
except NoResultFound:
raise HydraError("ResourceAttr %s does not exist in scenario %s."%(ra_id, scenario_id))
DBSession.delete(sd_i)
示例3: update_dataset
# 需要导入模块: from HydraServer.db import DBSession [as 别名]
# 或者: from HydraServer.db.DBSession import delete [as 别名]
def update_dataset(dataset_id, name, data_type, val, units, dimension, metadata={}, **kwargs):
"""
Update an existing dataset
"""
if dataset_id is None:
raise HydraError("Dataset must have an ID to be updated.")
user_id = kwargs.get('user_id')
dataset = DBSession.query(Dataset).filter(Dataset.dataset_id==dataset_id).one()
#This dataset been seen before, so it may be attached
#to other scenarios, which may be locked. If they are locked, we must
#not change their data, so new data must be created for the unlocked scenarios
locked_scenarios = []
unlocked_scenarios = []
for dataset_rs in dataset.resourcescenarios:
if dataset_rs.scenario.locked == 'Y':
locked_scenarios.append(dataset_rs)
else:
unlocked_scenarios.append(dataset_rs)
#Are any of these scenarios locked?
if len(locked_scenarios) > 0:
#If so, create a new dataset and assign to all unlocked datasets.
dataset = add_dataset(data_type,
val,
units,
dimension,
metadata=metadata,
name=name,
user_id=kwargs['user_id'])
for unlocked_rs in unlocked_scenarios:
unlocked_rs.dataset = dataset
else:
dataset.set_val(data_type, val)
dataset.set_metadata(metadata)
dataset.data_type = data_type
dataset.data_units = units
dataset.data_name = name
dataset.data_dimen = dimension
dataset.created_by = kwargs['user_id']
dataset.data_hash = dataset.set_hash()
#Is there a dataset in the DB already which is identical to the updated dataset?
existing_dataset = DBSession.query(Dataset).filter(Dataset.data_hash==dataset.data_hash, Dataset.dataset_id != dataset.dataset_id).first()
if existing_dataset is not None and existing_dataset.check_user(user_id):
log.warn("An identical dataset %s has been found to dataset %s."
" Deleting dataset and returning dataset %s",
existing_dataset.dataset_id, dataset.dataset_id, existing_dataset.dataset_id)
DBSession.delete(dataset)
dataset = existing_dataset
return dataset
示例4: update_value_from_mapping
# 需要导入模块: from HydraServer.db import DBSession [as 别名]
# 或者: from HydraServer.db.DBSession import delete [as 别名]
def update_value_from_mapping(source_resource_attr_id, target_resource_attr_id, source_scenario_id, target_scenario_id, **kwargs):
"""
Using a resource attribute mapping, take the value from the source and apply
it to the target. Both source and target scenarios must be specified (and therefor
must exist).
"""
rm = aliased(ResourceAttrMap, name='rm')
#Check the mapping exists.
mapping = DBSession.query(rm).filter(
or_(
and_(
rm.resource_attr_id_a == source_resource_attr_id,
rm.resource_attr_id_b == target_resource_attr_id
),
and_(
rm.resource_attr_id_a == target_resource_attr_id,
rm.resource_attr_id_b == source_resource_attr_id
)
)
).first()
if mapping is None:
raise ResourceNotFoundError("Mapping between %s and %s not found"%
(source_resource_attr_id,
target_resource_attr_id))
#check scenarios exist
s1 = _get_scenario(source_scenario_id, False, False)
s2 = _get_scenario(target_scenario_id, False, False)
rs = aliased(ResourceScenario, name='rs')
rs1 = DBSession.query(rs).filter(rs.resource_attr_id == source_resource_attr_id,
rs.scenario_id == source_scenario_id).first()
rs2 = DBSession.query(rs).filter(rs.resource_attr_id == target_resource_attr_id,
rs.scenario_id == target_scenario_id).first()
#3 possibilities worth considering:
#1: Both RS exist, so update the target RS
#2: Target RS does not exist, so create it with the dastaset from RS1
#3: Source RS does not exist, so it must be removed from the target scenario if it exists
return_value = None#Either return null or return a new or updated resource scenario
if rs1 is not None:
if rs2 is not None:
log.info("Destination Resource Scenario exists. Updating dastaset ID")
rs2.dataset_id = rs1.dataset_id
else:
log.info("Destination has no data, so making a new Resource Scenario")
rs2 = ResourceScenario(resource_attr_id=target_resource_attr_id, scenario_id=target_scenario_id, dataset_id=rs1.dataset_id)
DBSession.add(rs2)
DBSession.flush()
return_value = rs2
else:
log.info("Source Resource Scenario does not exist. Deleting destination Resource Scenario")
if rs2 is not None:
DBSession.delete(rs2)
DBSession.flush()
return return_value
示例5: delete_resourcegroup
# 需要导入模块: from HydraServer.db import DBSession [as 别名]
# 或者: from HydraServer.db.DBSession import delete [as 别名]
def delete_resourcegroup(group_id,**kwargs):
"""
Add a new group to a scenario.
"""
group_i = _get_group(group_id)
#This should cascaded to delete all the group items.
DBSession.delete(group_i)
return 'OK'
示例6: delete_dataset_collection
# 需要导入模块: from HydraServer.db import DBSession [as 别名]
# 或者: from HydraServer.db.DBSession import delete [as 别名]
def delete_dataset_collection(collection_id,**kwargs):
try:
collection = DBSession.query(DatasetCollection).filter(DatasetCollection.collection_id==collection_id).one()
except NoResultFound:
raise ResourceNotFoundError("No dataset collection found with id %s"%collection_id)
DBSession.delete(collection)
DBSession.flush()
示例7: purge_scenario
# 需要导入模块: from HydraServer.db import DBSession [as 别名]
# 或者: from HydraServer.db.DBSession import delete [as 别名]
def purge_scenario(scenario_id, **kwargs):
"""
Set the status of a scenario.
"""
_check_can_edit_scenario(scenario_id, kwargs['user_id'])
scenario_i = _get_scenario(scenario_id, False, False)
DBSession.delete(scenario_i)
DBSession.flush()
return 'OK'
示例8: delete_project
# 需要导入模块: from HydraServer.db import DBSession [as 别名]
# 或者: from HydraServer.db.DBSession import delete [as 别名]
def delete_project(project_id,**kwargs):
"""
Set the status of a project to 'X'
"""
user_id = kwargs.get('user_id')
#check_perm(user_id, 'delete_project')
project = _get_project(project_id)
project.check_write_permission(user_id)
DBSession.delete(project)
DBSession.flush()
示例9: delete_role
# 需要导入模块: from HydraServer.db import DBSession [as 别名]
# 或者: from HydraServer.db.DBSession import delete [as 别名]
def delete_role(role_id,**kwargs):
"""
"""
check_perm(kwargs.get('user_id'), 'edit_role')
try:
role_i = DBSession.query(Role).filter(Role.role_id==role_id).one()
DBSession.delete(role_i)
except InvalidRequestError:
raise ResourceNotFoundError("Role (role_id=%s) does not exist"%(role_id))
return 'OK'
示例10: delete_perm
# 需要导入模块: from HydraServer.db import DBSession [as 别名]
# 或者: from HydraServer.db.DBSession import delete [as 别名]
def delete_perm(perm_id,**kwargs):
"""
"""
check_perm(kwargs.get('user_id'), 'edit_perm')
try:
perm_i = DBSession.query(Perm).filter(Perm.perm_id==perm_id).one()
DBSession.delete(perm_i)
except InvalidRequestError:
raise ResourceNotFoundError("Permission (id=%s) does not exist"%(perm_id))
return 'OK'
示例11: delete_resourcegroupitems
# 需要导入模块: from HydraServer.db import DBSession [as 别名]
# 或者: from HydraServer.db.DBSession import delete [as 别名]
def delete_resourcegroupitems(scenario_id, item_ids, **kwargs):
"""
Delete specified items in a group, in a scenario.
"""
user_id = int(kwargs.get('user_id'))
scenario = _get_scenario(scenario_id, include_data=False, include_items=False)
_check_network_ownership(scenario.network_id, user_id)
for item_id in item_ids:
rgi = DBSession.query(ResourceGroupItem).\
filter(ResourceGroupItem.item_id==item_id).one()
DBSession.delete(rgi)
示例12: delete_resource_attr_collection
# 需要导入模块: from HydraServer.db import DBSession [as 别名]
# 或者: from HydraServer.db.DBSession import delete [as 别名]
def delete_resource_attr_collection(ctx, collection_id):
"""
Delete a resource attribute collection
"""
collection_i = DBSession.query(ResourceAttrCollection).filter(ResourceAttrCollection.collection_id==collection_id).first()
if collection_i is None:
raise HydraError("No collection with ID %s", collection_id)
DBSession.delete(collection_i)
return 'OK'
示例13: delete_role_perm
# 需要导入模块: from HydraServer.db import DBSession [as 别名]
# 或者: from HydraServer.db.DBSession import delete [as 别名]
def delete_role_perm(role_id, perm_id,**kwargs):
check_perm(kwargs.get('user_id'), 'edit_perm')
_get_perm(perm_id)
_get_role(role_id)
try:
roleperm_i = DBSession.query(RolePerm).filter(RolePerm.role_id==role_id, RolePerm.perm_id==perm_id).one()
DBSession.delete(roleperm_i)
except NoResultFound:
raise ResourceNotFoundError("Role Perm does not exist")
return 'OK'
示例14: delete_user_role
# 需要导入模块: from HydraServer.db import DBSession [as 别名]
# 或者: from HydraServer.db.DBSession import delete [as 别名]
def delete_user_role(deleted_user_id, role_id,**kwargs):
check_perm(kwargs.get('user_id'), 'edit_role')
try:
_get_user(deleted_user_id)
_get_role(role_id)
roleuser_i = DBSession.query(RoleUser).filter(RoleUser.user_id==deleted_user_id, RoleUser.role_id==role_id).one()
DBSession.delete(roleuser_i)
except NoResultFound:
raise ResourceNotFoundError("User Role does not exist")
return 'OK'
示例15: delete_user
# 需要导入模块: from HydraServer.db import DBSession [as 别名]
# 或者: from HydraServer.db.DBSession import delete [as 别名]
def delete_user(deleted_user_id,**kwargs):
"""
"""
check_perm(kwargs.get('user_id'), 'edit_user')
try:
user_i = DBSession.query(User).filter(User.user_id==deleted_user_id).one()
DBSession.delete(user_i)
except NoResultFound:
raise ResourceNotFoundError("User (user_id=%s) does not exist"%(deleted_user_id))
return 'OK'