swh.web.api.utils module#
- swh.web.api.utils.filter_field_keys(data, field_keys)[source]#
- Given an object instance (directory or list), and a csv field keys to filter on. - Return the object instance with filtered keys. - Note: Returns obj as is if it’s an instance of types not in (dictionary, list) - Parameters:
- data (-) – one object (dictionary, list…) to filter. 
- field_keys (-) – csv or set of keys to filter the object on 
 
- Returns:
- obj filtered on field_keys 
 
- swh.web.api.utils.person_to_string(person)[source]#
- Map a person (person, committer, tagger, etc…) to a string. 
- swh.web.api.utils.enrich_object(object: Dict[str, str], request: HttpRequest | None = None) Dict[str, str][source]#
- Enrich an object (revision, release) with link to the ‘target’ of type ‘target_type’. - Parameters:
- object – An object with target and target_type keys 
- release ((e.g.) 
- revision) 
- request – Absolute URIs will be generated if provided 
 
- Returns:
- Object enriched with target object url (revision, release, content, directory) 
 
- swh.web.api.utils.enrich_release(object: Dict[str, str], request: HttpRequest | None = None) Dict[str, str]#
- Enrich an object (revision, release) with link to the ‘target’ of type ‘target_type’. - Parameters:
- object – An object with target and target_type keys 
- release ((e.g.) 
- revision) 
- request – Absolute URIs will be generated if provided 
 
- Returns:
- Object enriched with target object url (revision, release, content, directory) 
 
- swh.web.api.utils.enrich_directory_entry(directory: Dict[str, str], request: HttpRequest | None = None) Dict[str, str][source]#
- Enrich directory entry with url to target. - Parameters:
- directory – dict of data associated to a swh directory entry 
- request – Absolute URIs will be generated if provided 
 
- Returns:
- An enriched directory dict filled with additional url 
 
- swh.web.api.utils.enrich_metadata_endpoint(content_metadata: Dict[str, str], request: HttpRequest | None = None) Dict[str, str][source]#
- Enrich content metadata dict with link to the upper metadata endpoint. - Parameters:
- content_metadata – dict of data associated to a swh content metadata 
- request – Absolute URIs will be generated if provided 
 
- Returns:
- An enriched content metadata dict filled with an additional url 
 
- swh.web.api.utils.enrich_content(content: Dict[str, Any], request: HttpRequest | None = None, top_url: bool | None = False, query_string: str | None = None) Dict[str, str][source]#
- Enrich content with links to:
- data_url: its raw data 
- filetype_url: its filetype information 
- language_url: its programming language information 
- license_url: its licensing information 
 
 - Parameters:
- content – dict of data associated to a swh content object 
- top_url – whether or not to include the content url in the enriched data 
- query_string – optional query string of type ‘<algo>:<hash>’ used when requesting the content, it acts as a hint for picking the same hash method when computing the url listed above 
- request – Absolute URIs will be generated if provided 
 
- Returns:
- An enriched content dict filled with additional urls 
 
- swh.web.api.utils.enrich_revision(revision: Dict[str, Any], request: HttpRequest | None = None) Dict[str, Any][source]#
- Enrich revision with links where it makes sense (directory, parents). Keep track of the navigation breadcrumbs if they are specified. - Parameters:
- revision – the revision as a dict 
- request – Absolute URIs will be generated if provided 
 
- Returns:
- An enriched revision dict filled with additional urls 
 
- swh.web.api.utils.enrich_snapshot(snapshot: Dict[str, Any], request: HttpRequest | None = None) Dict[str, Any][source]#
- Enrich snapshot with links to the branch targets - Parameters:
- snapshot – the snapshot as a dict 
- request – Absolute URIs will be generated if provided 
 
- Returns:
- An enriched snapshot dict filled with additional urls 
 
- swh.web.api.utils.enrich_origin(origin: Dict[str, Any] | OriginInfo, request: HttpRequest | None = None) Dict[str, Any][source]#
- Enrich origin dict with link to its visits - Parameters:
- origin – the origin as a dict 
- request – Absolute URIs will be generated if provided 
 
- Returns:
- An enriched origin dict filled with additional urls 
 
- swh.web.api.utils.enrich_origin_search_result(origin_search_result: Tuple[List[Dict[str, Any]], str | None], request: HttpRequest | None = None) Tuple[List[Dict[str, Any]], str | None][source]#
- Enrich origin search result with additional links - Parameters:
- origin_search_result – tuple returned when searching origins 
- request – Absolute URIs will be generated if provided 
 
- Returns:
- An enriched origin search result filled with additional urls 
 
- swh.web.api.utils.enrich_origin_visit(origin_visit: Dict[str, Any], request: HttpRequest | None = None, with_origin_link: bool = False, with_origin_visit_link: bool = False) Dict[str, Any][source]#
- Enrich origin visit dict with additional links - Parameters:
- origin_visit – the origin visit as a dict 
- with_origin_link – whether to add link to origin 
- with_origin_visit_link – whether to add link to origin visit 
- request – Absolute URIs will be generated if provided 
 
- Returns:
- An enriched origin visit dict filled with additional urls