本文整理汇总了Python中bkr.server.model.PowerType.by_id方法的典型用法代码示例。如果您正苦于以下问题:Python PowerType.by_id方法的具体用法?Python PowerType.by_id怎么用?Python PowerType.by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bkr.server.model.PowerType
的用法示例。
在下文中一共展示了PowerType.by_id方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_powertype
# 需要导入模块: from bkr.server.model import PowerType [as 别名]
# 或者: from bkr.server.model.PowerType import by_id [as 别名]
def delete_powertype(id):
"""
Deletes a power type by the given id.
:param id: The id of the power type to be deleted.
:status 204: Power type successfully deleted.
:status 400: Power type is referenced by systems.
:status 404: Power type can not be found.
"""
try:
powertype = PowerType.by_id(id)
except NoResultFound:
raise NotFound404('Power type: %s does not exist' % id)
systems_referenced = System.query.join(System.power).filter(
Power.power_type == powertype).count()
if systems_referenced:
raise BadRequest400('Power type %s still referenced by %i systems' % (
powertype.name, systems_referenced))
session.delete(powertype)
activity = Activity(identity.current.user, u'HTTP', u'Deleted', u'PowerType', powertype.name)
session.add(activity)
return '', 204
示例2: save
# 需要导入模块: from bkr.server.model import PowerType [as 别名]
# 或者: from bkr.server.model.PowerType import by_id [as 别名]
def save(self, **kw):
if kw['id']:
edit = PowerType.by_id(kw['id'])
edit.name = kw['name']
elif kw.get('name'):
new = PowerType(name=kw['name'])
else:
flash(_(u"Invalid Power Type entry"))
redirect(".")
flash( _(u"OK") )
redirect(".")
示例3: edit
# 需要导入模块: from bkr.server.model import PowerType [as 别名]
# 或者: from bkr.server.model.PowerType import by_id [as 别名]
def edit(self,**kw):
values = []
if kw.get('id'):
powertype = PowerType.by_id(kw['id'])
values = dict(
id = powertype.id,
name = powertype.name,
)
return dict(
form = self.form,
action = './save',
options = {},
value = values,
)
示例4: remove
# 需要导入模块: from bkr.server.model import PowerType [as 别名]
# 或者: from bkr.server.model.PowerType import by_id [as 别名]
def remove(self, **kw):
remove = PowerType.by_id(kw['id'])
session.delete(remove)
flash( _(u"%s Deleted") % remove.name )
raise redirect(".")