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: Optional[django.http.request.HttpRequest] = 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, revision) ((e.g.) –

  • 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: Optional[django.http.request.HttpRequest] = 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, revision) ((e.g.) –

  • 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(directory: Dict[str, str], request: Optional[django.http.request.HttpRequest] = None) → Dict[str, str][source]

Enrich directory with url to content or directory.

Parameters
  • directory – dict of data associated to a swh directory object

  • request – Absolute URIs will be generated if provided

Returns

An enriched directory dict filled with additional urls

swh.web.api.utils.enrich_metadata_endpoint(content_metadata: Dict[str, str], request: Optional[django.http.request.HttpRequest] = 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], top_url: Optional[bool] = False, query_string: Optional[str] = None, request: Optional[django.http.request.HttpRequest] = 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: Optional[django.http.request.HttpRequest] = 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: Optional[django.http.request.HttpRequest] = 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], request: Optional[django.http.request.HttpRequest] = 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 an additional url

swh.web.api.utils.enrich_origin_visit(origin_visit: Dict[str, Any], *, with_origin_link: bool, with_origin_visit_link: bool, request: Optional[django.http.request.HttpRequest] = None) → 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