def post(self, *args, **kwargs): category_id = self.get_angular_argument('id') if not category_id: self.on_error(**ErrorCodeMessage.category_not_exists) return category = Category.init_from_category_id(category_id) if not category: self.on_error(**ErrorCodeMessage.category_not_exists) return if category.recover(): self.on_success() else: self.on_error(**ErrorCodeMessage.database_error)
def delete(self, category_id=0, *args, **kwargs): """删除""" category_id = category_id if not category_id: self.on_error(**ErrorCodeMessage.category_not_exists) return category = Category.init_from_category_id(category_id) if not category: self.on_error(**ErrorCodeMessage.category_not_exists) return if category.delete(): self.on_success() else: self.on_error(**ErrorCodeMessage.database_error)
def put(self, *args, **kwargs): """改名""" category_name = self.get_angular_argument('name') category_id = self.get_angular_argument('id') if not category_id: self.on_error(**ErrorCodeMessage.category_not_exists) return category = Category.init_from_category_id(category_id) if not category: self.on_error(**ErrorCodeMessage.category_not_exists) return if not category_name: self.on_error(**ErrorCodeMessage.category_name_illegal) return if category.edit_name(category_name): self.on_success() else: self.on_error(**ErrorCodeMessage.database_error)