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
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
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(".")
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']) session.add(new) else: flash(_(u"Invalid Power Type entry")) redirect(".") flash(_(u"OK")) redirect(".")
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, )
def edit(self, **kw): title = _(u'New Power Type') values = [] if kw.get('id'): powertype = PowerType.by_id(kw['id']) title = powertype.name values = dict( id=powertype.id, name=powertype.name, ) return dict( form=self.form, title=title, action='./save', options={}, value=values, )
def remove(self, **kw): remove = PowerType.by_id(kw['id']) session.delete(remove) flash( _(u"%s Deleted") % remove.name ) raise redirect(".")
def remove(self, **kw): remove = PowerType.by_id(kw['id']) session.delete(remove) flash(_(u"%s Deleted") % remove.name) raise redirect(".")