class TaxCategoryBackend(ServiceBackend): service_path = "tax-categories" model_class = TaxCategoryModel _schema_draft = TaxCategoryDraftSchema _schema_update = TaxCategoryUpdateSchema _schema_query_response = TaxCategoryPagedQueryResponseSchema def urls(self): return [ ("^$", "GET", self.query), ("^$", "POST", self.create), ("^key=(?P<key>[^/]+)$", "GET", self.get_by_key), ("^(?P<id>[^/]+)$", "GET", self.get_by_id), ("^key=(?P<key>[^/]+)$", "POST", self.update_by_key), ("^(?P<id>[^/]+)$", "POST", self.update_by_id), ("^key=(?P<key>[^/]+)$", "DELETE", self.delete_by_key), ("^(?P<id>[^/]+)$", "DELETE", self.delete_by_id), ] _actions = { "changeName": update_attribute("name", "name"), "setKey": update_attribute("key", "key"), "setDescription": update_attribute("description", "description"), "addTaxRate": add_tax_rate_action(), "removeTaxRate": update_attribute_delete_item_by_id("rates", "tax_rate_id"), "replaceTaxRate": replace_tax_rate_action(), }
def replace_tax_rate_action(): delete_action = update_attribute_delete_item_by_id("rates", "tax_rate_id") add_action = add_tax_rate_action() def updater(self, obj, action): obj = delete_action(self, obj, action) return add_action(self, obj, action) return updater