def nav_links_for_taxonomy_item_page(taxonomy: Taxonomy) -> List[ApiLink]: nav_links: List[ApiLink] = [ ApiLink( href=url_for( "api-v1.TaxonomyView", namespace=str(taxonomy.namespace_id), taxonomy=str(taxonomy.id), _external=True, ), rel=("up", ), resource_type="ont-taxonomy", resource_key=taxonomy_to_key(taxonomy), schema=url_for("api-v1.ApiSchemaView", schema_id="TaxonomySchema", _external=True), name=taxonomy.name, ), ApiLink( href=url_for( "api-v1.NamespaceView", namespace=str(taxonomy.namespace_id), _external=True, ), rel=("nav", ), resource_type="ont-namespace", resource_key={"namespaceId": str(taxonomy.namespace_id)}, schema=url_for("api-v1.ApiSchemaView", schema_id="Namespace", _external=True), name=taxonomy.namespace.name, ), ] return nav_links
def nav_links_for_object(object: OntologyObject) -> List[ApiLink]: nav_links: List[ApiLink] = [ ApiLink( href=url_for( "api-v1.ObjectsView", namespace=str(object.namespace_id), _external=True, ), rel=("up", "page", "first", "collection"), resource_type="ont-object", resource_key={"namespaceId": str(object.namespace_id)}, ), ApiLink( href=url_for( "api-v1.ObjectVersionsView", namespace=str(object.namespace_id), object_id=str(object.id), _external=True, ), rel=("nav", "page", "first", "collection"), resource_type="ont-object-version", resource_key=object_to_key(object), ), ApiLink( href=url_for( "api-v1.NamespaceView", namespace=str(object.namespace_id), _external=True, ), rel=("nav", ), resource_type="ont-namespace", resource_key={"namespaceId": str(object.namespace_id)}, schema=url_for("api-v1.ApiSchemaView", schema_id="Namespace", _external=True), name=object.namespace.name, ), ] if isinstance(object, OntologyObject): nav_links.append( ApiLink( href=url_for( "api-v1.TypeView", namespace=str(object.namespace_id), object_type=str(object.object_type_id), _external=True, ), rel=("nav", ), resource_type="ont-type", resource_key=type_to_key(object.ontology_type), schema=url_for("api-v1.ApiSchemaView", schema_id="TypeSchema", _external=True), name=object.ontology_type.name, )) # TODO add more nav links to type and to current version… ? return nav_links
def nav_links_for_type(object_type: OntologyObjectType) -> List[ApiLink]: nav_links: List[ApiLink] = [ ApiLink( href=url_for( "api-v1.TypesView", namespace=str(object_type.namespace_id), _external=True, ), rel=("up", "page", "first", "collection"), resource_type="ont-type", resource_key={"namespaceId": str(object_type.namespace_id)}, schema=url_for( "api-v1.ApiSchemaView", schema_id="ObjectType", _external=True ), ), ApiLink( href=url_for( "api-v1.TypeVersionsView", namespace=str(object_type.namespace_id), object_type=str(object_type.id), _external=True, ), rel=("nav", "page", "first", "collection", "schema"), resource_type="ont-type-version", resource_key=type_to_key(object_type), schema=url_for( "api-v1.ApiSchemaView", schema_id="OntologyType", _external=True ), ), ApiLink( # TODO decide whether to keep this for abstract types! href=url_for( "api-v1.ObjectsView", namespace=str(object_type.namespace_id), **{"type-id": str(object_type.id)}, _external=True, ), rel=("nav", "collection", "page", "first"), resource_type="ont-object", resource_key={ "namespaceId": str(object_type.namespace_id), "?type-id": str(object_type.id), }, ), ApiLink( href=url_for( "api-v1.NamespaceView", namespace=str(object_type.namespace_id), _external=True, ), rel=("nav",), resource_type="ont-namespace", resource_key={"namespaceId": str(object_type.namespace_id)}, schema=url_for("api-v1.ApiSchemaView", schema_id="Namespace", _external=True), name=object_type.namespace.name, ), ] return nav_links
def action_links_for_namespace(namespace: Namespace) -> List[ApiLink]: actions: List[ApiLink] = [ ApiLink( href=url_for("api-v1.NamespacesView", _external=True), rel=("create", "post"), resource_type="ont-namespace", schema=url_for("api-v1.ApiSchemaView", schema_id="Namespace", _external=True), ), ] resource_key = namespace_to_key(namespace) if namespace.deleted_on is None: actions.append( ApiLink( href=url_for( "api-v1.NamespaceView", namespace=str(namespace.id), _external=True, ), rel=("update", "put"), resource_type="ont-namespace", resource_key=resource_key, schema=url_for( "api-v1.ApiSchemaView", schema_id="Namespace", _external=True ), name=namespace.name, ) ) actions.append( ApiLink( href=url_for( "api-v1.NamespaceView", namespace=str(namespace.id), _external=True, ), rel=("delete",), resource_type="ont-namespace", resource_key=resource_key, name=namespace.name, ) ) else: actions.append( ApiLink( href=url_for( "api-v1.NamespaceView", namespace=str(namespace.id), _external=True, ), rel=("restore", "post"), resource_type="ont-namespace", resource_key=resource_key, name=namespace.name, ) ) return actions
def nav_links_for_taxonomy_item_relation( relation: TaxonomyItemRelation, ) -> List[ApiLink]: taxonomy = relation.taxonomy_item_source.taxonomy namespace_id = str(taxonomy.namespace_id) nav_links: List[ApiLink] = [ ApiLink( href=url_for( "api-v1.TaxonomyView", namespace=namespace_id, taxonomy=str(taxonomy.id), _external=True, ), rel=("up", ), resource_type="ont-taxonomy", resource_key=taxonomy_to_key(taxonomy), schema=url_for("api-v1.ApiSchemaView", schema_id="TaxonomySchema", _external=True), name=taxonomy.name, ), ApiLink( href=url_for( "api-v1.TaxonomiesView", namespace=namespace_id, _external=True, ), rel=("nav", "page", "first", "collection"), resource_type="ont-taxonomy", resource_key={"namespaceId": namespace_id}, schema=url_for("api-v1.ApiSchemaView", schema_id="TaxonomySchema", _external=True), ), ApiLink( href=url_for( "api-v1.NamespaceView", namespace=namespace_id, _external=True, ), rel=("nav", ), resource_type="ont-namespace", resource_key={"namespaceId": namespace_id}, schema=url_for("api-v1.ApiSchemaView", schema_id="Namespace", _external=True), name=taxonomy.namespace.name, ), ] return nav_links
def nav_links_for_taxonomy(taxonomy: Taxonomy) -> List[ApiLink]: nav_links: List[ApiLink] = [ ApiLink( href=url_for( "api-v1.TaxonomiesView", namespace=str(taxonomy.namespace_id), _external=True, ), rel=("up", "page", "first", "collection"), resource_type="ont-taxonomy", resource_key={"namespaceId": str(taxonomy.namespace_id)}, schema=url_for("api-v1.ApiSchemaView", schema_id="TaxonomySchema", _external=True), ), ApiLink( href=url_for( "api-v1.TaxonomyItemsView", namespace=str(taxonomy.namespace_id), taxonomy=str(taxonomy.id), _external=True, ), rel=("nav", "page", "first", "collection"), resource_type="ont-taxonomy-item", resource_key={ "namespaceId": str(taxonomy.namespace_id), "taxonomyId": str(taxonomy.id), }, schema=url_for("api-v1.ApiSchemaView", schema_id="TaxonomyItemSchema", _external=True), ), ApiLink( href=url_for( "api-v1.NamespaceView", namespace=str(taxonomy.namespace_id), _external=True, ), rel=("nav", ), resource_type="ont-namespace", resource_key={"namespaceId": str(taxonomy.namespace_id)}, schema=url_for("api-v1.ApiSchemaView", schema_id="Namespace", _external=True), name=taxonomy.namespace.name, ), ] return nav_links
def action_links_for_taxonomy_item_relation( relation: TaxonomyItemRelation, ) -> List[ApiLink]: actions: List[ApiLink] = [] item: TaxonomyItem = relation.taxonomy_item_source if (item.taxonomy.namespace.deleted_on is None and item.taxonomy.deleted_on is None and item.deleted_on is None): # namespace and taxonomy and item are modifyable namespace_id = str(item.taxonomy.namespace_id) resource_key = taxonomy_item_to_key(item) resource_key["relationId"] = str(relation.id) if item.deleted_on is None: actions.append( ApiLink( href=url_for( "api-v1.TaxonomyItemRelationView", namespace=namespace_id, taxonomy=str(item.taxonomy_id), taxonomy_item=str(item.id), relation=str(relation.id), _external=True, ), rel=("delete", ), resource_type="ont-taxonomy-item-relation", resource_key=resource_key, )) return actions
def type_version_to_type_data( object_type_version: OntologyObjectTypeVersion, ) -> ObjectTypeData: return ObjectTypeData( self=ApiLink( href=url_for( "api-v1.TypeVersionView", namespace=str(object_type_version.ontology_type.namespace_id), object_type=str(object_type_version.object_type_id), version=str(object_type_version.version), _external=True, ), rel=("schema", ), resource_type="ont-type-version", resource_key=type_version_to_key(object_type_version), schema=url_for("api-v1.ApiSchemaView", schema_id="OntologyType", _external=True), name=object_type_version.name, ), name=object_type_version.name, description=object_type_version.description, created_on=object_type_version.created_on, updated_on=object_type_version.created_on, deleted_on=object_type_version.deleted_on, version=object_type_version.version, abstract=object_type_version.abstract, schema=object_type_version.data, )
def type_to_type_data(object_type: OntologyObjectType) -> ObjectTypeData: return ObjectTypeData( self=ApiLink( href=url_for( "api-v1.TypeView", namespace=str(object_type.namespace_id), object_type=str(object_type.id), _external=True, ), rel=tuple(), resource_type="ont-type", resource_key=type_to_key(object_type), schema=url_for("api-v1.ApiSchemaView", schema_id="OntologyType", _external=True), name=object_type.name, ), name=object_type.name, description=object_type.description, created_on=object_type.created_on, updated_on=object_type.updated_on, deleted_on=object_type.deleted_on, version=object_type.version, abstract=not object_type.is_toplevel_type, schema=object_type.schema, )
def nav_links_for_type_versions_page( object_type: OntologyObjectType) -> List[ApiLink]: nav_links: List[ApiLink] = [ ApiLink( href=url_for( "api-v1.TypeView", namespace=str(object_type.namespace_id), object_type=str(object_type.id), _external=True, ), rel=("up", ), resource_type="ont-type", resource_key=type_to_key(object_type), schema=url_for("api-v1.ApiSchemaView", schema_id="OntologyType", _external=True), name=object_type.name, ), ApiLink( href=url_for( "api-v1.TypesView", namespace=str(object_type.namespace_id), _external=True, ), rel=("nav", "page", "first", "collection"), resource_type="ont-type", resource_key={"namespaceId": str(object_type.namespace_id)}, schema=url_for("api-v1.ApiSchemaView", schema_id="ObjectType", _external=True), ), ApiLink( href=url_for( "api-v1.NamespaceView", namespace=str(object_type.namespace_id), _external=True, ), rel=("nav", ), resource_type="ont-namespace", resource_key={"namespaceId": str(object_type.namespace_id)}, schema=url_for("api-v1.ApiSchemaView", schema_id="Namespace", _external=True), name=object_type.namespace.name, ), ] return nav_links
def nav_links_for_namespace(namespace: Namespace) -> List[ApiLink]: nav_links: List[ApiLink] = [ ApiLink( href=url_for( "api-v1.ObjectsView", namespace=str(namespace.id), _external=True, ), rel=("nav", "collection", "page", "first"), resource_type="ont-object", resource_key=namespace_to_key(namespace), ), ApiLink( href=url_for( "api-v1.TypesView", namespace=str(namespace.id), _external=True, ), rel=("nav", "collection", "page", "first"), resource_type="ont-type", resource_key=namespace_to_key(namespace), schema=url_for( "api-v1.ApiSchemaView", schema_id="OntologyType", _external=True ), ), ApiLink( href=url_for( "api-v1.TaxonomiesView", namespace=str(namespace.id), _external=True, ), rel=("nav", "collection", "page", "first"), resource_type="ont-taxonomy", resource_key=namespace_to_key(namespace), schema=url_for( "api-v1.ApiSchemaView", schema_id="TaxonomySchema", _external=True ), ), ] return nav_links
def create_action_link_for_taxonomy_page(namespace: Namespace) -> ApiLink: return ApiLink( href=url_for( "api-v1.TaxonomiesView", namespace=str(namespace.id), _external=True, ), rel=("create", "post"), resource_type="ont-taxonomy", resource_key={"namespaceId": str(namespace.id)}, schema=url_for("api-v1.ApiSchemaView", schema_id="TaxonomySchema", _external=True), )
def object_to_self_link(object: OntologyObject) -> ApiLink: return ApiLink( href=url_for( "api-v1.ObjectView", namespace=str(object.namespace_id), object_id=str(object.id), _external=True, ), rel=tuple(), resource_type="ont-object", resource_key=object_to_key(object), schema=type_version_to_schema_url(object.ontology_type_version), name=object.name, )
def create_action_link_for_taxonomy_item_page(taxonomy: Taxonomy) -> ApiLink: return ApiLink( href=url_for( "api-v1.TaxonomyItemsView", namespace=str(taxonomy.namespace_id), taxonomy=str(taxonomy.id), _external=True, ), rel=("create", "post"), resource_type="ont-taxonomy-item", resource_key=taxonomy_to_key(taxonomy), schema=url_for("api-v1.ApiSchemaView", schema_id="TaxonomyItemSchema", _external=True), )
def taxonomy_item_to_api_link(item: TaxonomyItem) -> ApiLink: return ApiLink( href=url_for( "api-v1.TaxonomyItemView", namespace=str(item.taxonomy.namespace_id), taxonomy=str(item.taxonomy_id), taxonomy_item=str(item.id), _external=True, ), rel=tuple(), resource_type="ont-taxonomy-item", resource_key=taxonomy_item_to_key(item), schema=url_for("api-v1.ApiSchemaView", schema_id="TaxonomyItemSchema", _external=True), name=item.name, )
def taxonomy_item_relation_to_api_link( relation: TaxonomyItemRelation) -> ApiLink: resource_key = taxonomy_item_to_key(relation.taxonomy_item_source) resource_key["relationId"] = str(relation.id) return ApiLink( href=url_for( "api-v1.TaxonomyItemRelationView", namespace=str(relation.taxonomy_item_source.taxonomy.namespace_id), taxonomy=str(relation.taxonomy_item_source.taxonomy_id), taxonomy_item=str(relation.taxonomy_item_source_id), relation=str(relation.id), _external=True, ), rel=tuple(), resource_type="ont-taxonomy-item-relation", resource_key=resource_key, )
def namespace_to_namespace_data(namespace: Namespace) -> NamespaceData: return NamespaceData( self=ApiLink( href=url_for( "api-v1.NamespaceView", namespace=str(namespace.id), _external=True ), rel=("ont-namespace",), resource_type="ont-namespace", resource_key=namespace_to_key(namespace), schema=url_for("api-v1.ApiSchemaView", schema_id="Namespace", _external=True), name=namespace.name, ), name=namespace.name, description=namespace.description, created_on=namespace.created_on, updated_on=namespace.updated_on, deleted_on=namespace.deleted_on, )
def nav_links_for_taxonomy_page(namespace: Namespace) -> List[ApiLink]: nav_links: List[ApiLink] = [ ApiLink( href=url_for( "api-v1.NamespaceView", namespace=str(namespace.id), _external=True, ), rel=("up", ), resource_type="ont-namespace", resource_key={"namespaceId": str(namespace.id)}, schema=url_for("api-v1.ApiSchemaView", schema_id="Namespace", _external=True), name=namespace.name, ), ] return nav_links
def namespace_to_api_response(namespace: Namespace) -> ApiResponse: namespace_data = namespace_to_namespace_data(namespace) raw_namespace: Dict[str, Any] = NamespaceSchema().dump(namespace_data) return ApiResponse( links=( ApiLink( href=url_for("api-v1.NamespacesView", _external=True), rel=("first", "page", "up", "collection", "ont-namespace"), resource_type="ont-namespace", schema=url_for( "api-v1.ApiSchemaView", schema_id="Namespace", _external=True ), ), *nav_links_for_namespace(namespace), *action_links_for_namespace(namespace), ), data=raw_namespace, )
def action_links_for_object_page( namespace: Namespace, type: Optional[OntologyObjectType] = None) -> List[ApiLink]: actions: List[ApiLink] = [] if (type is not None and type.is_toplevel_type # type is not abstract and type.deleted_on is None and namespace.deleted_on is None): actions.append( ApiLink( href=url_for( "api-v1.ObjectsView", namespace=str(namespace.id), **{"type-id": str(type.id)}, _external=True, ), rel=("create", "post"), resource_type="ont-object", resource_key={ "namespaceId": str(namespace.id), "?type-id": str(type.id) }, schema=type_version_to_schema_url(type.current_version), )) return actions
def create_action_link_for_taxonomy_item_relation_page( namespace: str, taxonomy: str, taxonomy_item: str) -> ApiLink: return ApiLink( href=url_for( "api-v1.TaxonomyItemRelationsView", namespace=namespace, taxonomy=taxonomy, taxonomy_item=taxonomy_item, _external=True, ), rel=("create", "post"), resource_type="ont-taxonomy-item-relation", resource_key={ "namespaceId": namespace, "taxonomyId": taxonomy, "taxonomyItemId": taxonomy_item, }, schema=url_for( "api-v1.ApiSchemaView", schema_id="TaxonomyItemRelationPostSchema", _external=True, ), )
def taxonomy_to_taxonomy_data(taxonomy: Taxonomy) -> TaxonomyData: return TaxonomyData( self=ApiLink( href=url_for( "api-v1.TaxonomyView", namespace=str(taxonomy.namespace_id), taxonomy=str(taxonomy.id), _external=True, ), rel=tuple(), resource_type="ont-taxonomy", resource_key=taxonomy_to_key(taxonomy), schema=url_for("api-v1.ApiSchemaView", schema_id="TaxonomySchema", _external=True), name=taxonomy.name, ), name=taxonomy.name, description=taxonomy.description, created_on=taxonomy.created_on, updated_on=taxonomy.updated_on, deleted_on=taxonomy.deleted_on, items=taxonomy_to_items_links(taxonomy), )
def action_links_for_object(object: OntologyObject) -> List[ApiLink]: object_type_version = object.ontology_type_version assert (object_type_version is not None), "An object should always have a current version!" current_type_schema_url = type_version_to_schema_url( object.ontology_type.current_version) actions: List[ApiLink] = [] if object.namespace.deleted_on is None: # namespace is modifyable actions.append( ApiLink( href=url_for( "api-v1.ObjectsView", namespace=str(object.namespace_id), type_id=str(object.object_type_id), _external=True, ), rel=("create", "post"), resource_type="ont-object", resource_key={ "namespaceId": str(object.namespace_id), "?type-id": str(object.object_type_id), }, schema=current_type_schema_url, )) resource_key = object_to_key(object) if object.deleted_on is None: actions.append( ApiLink( href=url_for( "api-v1.ObjectView", namespace=str(object.namespace_id), object_id=str(object.id), _external=True, ), rel=("update", "put"), resource_type="ont-object", resource_key=resource_key, schema=current_type_schema_url, name=object.name, )) actions.append( ApiLink( href=url_for( "api-v1.ObjectView", namespace=str(object.namespace_id), object_id=str(object.id), _external=True, ), rel=("delete", ), resource_type="ont-object", resource_key=resource_key, name=object.name, )) else: actions.append( ApiLink( href=url_for( "api-v1.ObjectView", namespace=str(object.namespace_id), object_id=str(object.id), _external=True, ), rel=("restore", "post"), resource_type="ont-object", resource_key=resource_key, name=object.name, )) return actions
def nav_links_for_taxonomy_item_version( item_version: TaxonomyItemVersion, ) -> List[ApiLink]: item = item_version.taxonomy_item namespace_id = str(item.taxonomy.namespace_id) nav_links: List[ApiLink] = [ # TODO up navigation link to versions page ApiLink( href=url_for( "api-v1.TaxonomyItemView", namespace=namespace_id, taxonomy=str(item.taxonomy_id), taxonomy_item=str(item.id), _external=True, ), rel=("nav", ), resource_type="ont-taxonomy-item", resource_key=taxonomy_to_key(item.taxonomy), schema=url_for("api-v1.ApiSchemaView", schema_id="TaxonomyItemSchema", _external=True), name=item.name, ), ApiLink( href=url_for( "api-v1.TaxonomyView", namespace=namespace_id, taxonomy=str(item.taxonomy_id), _external=True, ), rel=("up", ), resource_type="ont-taxonomy", resource_key=taxonomy_to_key(item.taxonomy), schema=url_for("api-v1.ApiSchemaView", schema_id="TaxonomySchema", _external=True), name=item.taxonomy.name, ), ApiLink( href=url_for( "api-v1.TaxonomiesView", namespace=namespace_id, _external=True, ), rel=("nav", "page", "first", "collection"), resource_type="ont-taxonomy", resource_key={"namespaceId": namespace_id}, schema=url_for("api-v1.ApiSchemaView", schema_id="TaxonomySchema", _external=True), ), ApiLink( href=url_for( "api-v1.NamespaceView", namespace=namespace_id, _external=True, ), rel=("nav", ), resource_type="ont-namespace", resource_key={"namespaceId": namespace_id}, schema=url_for("api-v1.ApiSchemaView", schema_id="Namespace", _external=True), name=item.taxonomy.namespace.name, ), ] return nav_links
def action_links_for_type(object_type: OntologyObjectType) -> List[ApiLink]: actions: List[ApiLink] = [] if object_type.namespace.deleted_on is None: # namespace is modifyable actions.append( ApiLink( href=url_for( "api-v1.TypesView", namespace=str(object_type.namespace_id), _external=True, ), rel=("create", "post"), resource_type="ont-type", resource_key={"namespaceId": str(object_type.namespace_id)}, schema=url_for("api-v1.ApiSchemaView", schema_id="TypeSchema", _external=True), )) resource_key = type_to_key(object_type) if object_type.deleted_on is None: actions.append( ApiLink( href=url_for( "api-v1.TypeView", namespace=str(object_type.namespace_id), object_type=str(object_type.id), _external=True, ), rel=("update", "put"), resource_type="ont-type", resource_key=resource_key, schema=url_for("api-v1.ApiSchemaView", schema_id="TypeSchema", _external=True), name=object_type.name, )) actions.append( ApiLink( href=url_for( "api-v1.TypeView", namespace=str(object_type.namespace_id), object_type=str(object_type.id), _external=True, ), rel=("delete", ), resource_type="ont-type", resource_key=resource_key, name=object_type.name, )) if object_type.is_toplevel_type: # only allow object creation for top level (non abstract) types actions.append( ApiLink( href=url_for( "api-v1.ObjectsView", namespace=str(object_type.namespace_id), **{"type-id": str(object_type.id)}, _external=True, ), rel=("create", "post"), resource_type="ont-object", resource_key={ "namespaceId": str(object_type.namespace_id), "?type-id": str(object_type.id), }, schema=url_for( "api-v1.TypeSchemaView", schema_id=str(object_type.current_version_id), _external=True, ), )) else: actions.append( ApiLink( href=url_for( "api-v1.TypeView", namespace=str(object_type.namespace_id), object_type=str(object_type.id), _external=True, ), rel=("restore", "post"), resource_type="ont-type", resource_key=resource_key, name=object_type.name, )) return actions
def action_links_for_taxonomy(taxonomy: Taxonomy) -> List[ApiLink]: actions: List[ApiLink] = [] if taxonomy.namespace.deleted_on is None: # namespace is modifyable actions.append( ApiLink( href=url_for( "api-v1.TaxonomiesView", namespace=str(taxonomy.namespace_id), _external=True, ), rel=("create", "post"), resource_type="ont-taxonomy", resource_key={"namespaceId": str(taxonomy.namespace_id)}, schema=url_for("api-v1.ApiSchemaView", schema_id="TaxonomySchema", _external=True), )) resource_key = taxonomy_to_key(taxonomy) if taxonomy.deleted_on is None: actions.append( ApiLink( href=url_for( "api-v1.TaxonomyView", namespace=str(taxonomy.namespace_id), taxonomy=str(taxonomy.id), _external=True, ), rel=("update", "put"), resource_type="ont-taxonomy", resource_key=resource_key, schema=url_for("api-v1.ApiSchemaView", schema_id="TaxonomySchema", _external=True), name=taxonomy.name, )) actions.append( ApiLink( href=url_for( "api-v1.TaxonomyView", namespace=str(taxonomy.namespace_id), taxonomy=str(taxonomy.id), _external=True, ), rel=("delete", ), resource_type="ont-taxonomy", resource_key=resource_key, name=taxonomy.name, )) actions.append(create_action_link_for_taxonomy_item_page(taxonomy)) else: actions.append( ApiLink( href=url_for( "api-v1.TaxonomyView", namespace=str(taxonomy.namespace_id), taxonomy=str(taxonomy.id), _external=True, ), rel=("restore", "post"), resource_type="ont-taxonomy", resource_key=resource_key, name=taxonomy.name, )) return actions
def action_links_for_taxonomy_item(item: TaxonomyItem) -> List[ApiLink]: actions: List[ApiLink] = [] if item.taxonomy.namespace.deleted_on is None and item.taxonomy.deleted_on is None: # namespace and taxonomy are modifyable namespace_id = str(item.taxonomy.namespace_id) actions.append( ApiLink( href=url_for( "api-v1.TaxonomyItemsView", namespace=namespace_id, taxonomy=str(item.taxonomy_id), _external=True, ), rel=("create", "post"), resource_type="ont-taxonomy-item", resource_key=taxonomy_to_key(item.taxonomy), schema=url_for("api-v1.ApiSchemaView", schema_id="TaxonomyItemSchema", _external=True), )) resource_key = taxonomy_item_to_key(item) if item.deleted_on is None: actions.append( ApiLink( href=url_for( "api-v1.TaxonomyItemView", namespace=namespace_id, taxonomy=str(item.taxonomy_id), taxonomy_item=str(item.id), _external=True, ), rel=("update", "put"), resource_type="ont-taxonomy-item", resource_key=resource_key, schema=url_for( "api-v1.ApiSchemaView", schema_id="TaxonomyItemSchema", _external=True, ), name=item.name, )) actions.append( ApiLink( href=url_for( "api-v1.TaxonomyItemView", namespace=namespace_id, taxonomy=str(item.taxonomy_id), taxonomy_item=str(item.id), _external=True, ), rel=("delete", ), resource_type="ont-taxonomy-item", resource_key=resource_key, name=item.name, )) actions.append( ApiLink( href=url_for( "api-v1.TaxonomyItemRelationsView", namespace=namespace_id, taxonomy=str(item.taxonomy_id), taxonomy_item=str(item.id), _external=True, ), rel=("create", "post"), resource_type="ont-taxonomy-item-relation", resource_key=taxonomy_item_to_key(item), schema=url_for( "api-v1.ApiSchemaView", schema_id="TaxonomyItemRelationPostSchema", _external=True, ), )) else: actions.append( ApiLink( href=url_for( "api-v1.TaxonomyItemView", namespace=namespace_id, taxonomy=str(item.taxonomy_id), taxonomy_item=str(item.id), _external=True, ), rel=("restore", "post"), resource_type="ont-taxonomy-item", resource_key=resource_key, name=item.name, )) return actions