def remove_object(self, **kwargs): """ Remove the object from the list """ if 'Referer' in cherrypy.request.headers: return_url = cherrypy.request.headers['Referer'] else: return_url = '/policy/' try: if kwargs['object-id'] is None or not kwargs['object-id'].isdigit(): raise TypeError('Policy ID is either None or ID is not int') if kwargs['policy-id'] is None: raise TypeError('Policy content None') object_id = int(kwargs['object-id']) policy_id = int(kwargs['policy-id']) delete_object = Session.query(PolicyChain).filter(and_( PolicyChain.chain_id == policy_id, PolicyChain.id == object_id)).one() parent = delete_object.parent child = delete_object.child Session.delete(delete_object) if parent != 0: parent_object = Session.query(PolicyChain).filter(and_( PolicyChain.id == parent, PolicyChain.chain_id == policy_id)).one() parent_object.child = child Session.merge(parent_object) if child != 0: child_object = Session.query(PolicyChain).filter(and_( PolicyChain.id == child, PolicyChain.chain_id == policy_id)).one() child_object.parent = parent Session.merge(child_object) Session.flush() raise cherrypy.HTTPRedirect(return_url) except NoResultFound: raise cherrypy.HTTPRedirect(return_url) except KeyError as e: raise