class TypesBackend(ServiceBackend): service_path = "types" model_class = TypesModel _schema_draft = schemas.TypeDraftSchema _schema_update = schemas.TypeUpdateSchema _schema_query_response = schemas.TypePagedQueryResponseSchema 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), ("^(?P<id>[^/]+)$", "DELETE", self.delete_by_id), ("^key=(?P<key>[^/]+)$", "DELETE", self.delete_by_key), ] # Fixme: use decorator for this _actions = { "addFieldDefinition": update_attribute_add_item("fieldDefinitions", "field_definition", schemas.FieldDefinitionSchema), "setDescription": update_attribute("description", "description") }
class ZonesBackend(ServiceBackend): service_path = "zones" model_class = ZonesModel _schema_draft = schemas.ZoneDraftSchema _schema_update = schemas.ZoneUpdateSchema _schema_query_response = schemas.ZonePagedQueryResponseSchema def urls(self): return [ ("^$", "GET", self.query), ("^$", "POST", self.create), ("^(?P<id>[^/]+)$", "GET", self.get_by_id), ("^(?P<id>[^/]+)$", "POST", self.update_by_id), ("^(?P<id>[^/]+)$", "DELETE", self.delete_by_id), ("^key=(?P<key>[^/]+)$", "DELETE", self.delete_by_key), ] _actions = { "changeName": update_attribute("name", "name"), "setKey": update_attribute("key", "key"), "setDescription": update_attribute("description", "description"), "addLocation": update_attribute_add_item( "locations", "location", schemas.LocationSchema ), "removeLocation": update_attribute_delete_item( "locations", "location", schemas.LocationSchema ), }
def add_tax_rate_action(): return update_attribute_add_item("rates", "tax_rate", TaxRateSchema, generate_tax_rate_id)