swh.web.utils package#
Subpackages#
Submodules#
- swh.web.utils.archive module
lookup_multiple_hashes()lookup_hash()search_hash()lookup_content_filetype()lookup_content_language()lookup_content_license()lookup_origin()lookup_origins()lookup_origin_snapshots()search_origin()search_origin_metadata()count_origins()lookup_origin_intrinsic_metadata()lookup_origin_intrinsic_citation_metadata()lookup_intrinsic_citation_metadata_by_target_swhid()lookup_origin_extrinsic_metadata()directory_exists()lookup_directory()lookup_directory_with_path()lookup_release()lookup_release_multiple()lookup_revision()lookup_revision_multiple()lookup_revision_message()lookup_revision_by()lookup_revision_log()lookup_revision_log_by()lookup_revision_with_context_by()lookup_revision_with_context()lookup_directory_with_revision()lookup_content()stat_counters()lookup_origin_visits()lookup_origin_visit_latest()lookup_origin_visit()origin_visit_find_by_date()lookup_snapshot_sizes()lookup_snapshot()lookup_latest_origin_snapshot()lookup_snapshot_alias()lookup_revision_through()lookup_directory_through_revision()vault_cook()vault_download()vault_download_url()vault_progress()diff_revision()get_revisions_walker()lookup_object()lookup_missing_hashes()lookup_origins_by_sha1s()encode_extid()decode_extid()lookup_extid()lookup_extid_by_target()lookup_raw_extrinsic_metadata()
- swh.web.utils.citation module
- swh.web.utils.converters module
- swh.web.utils.exc module
- swh.web.utils.highlightjs module
- swh.web.utils.identifiers module
- swh.web.utils.middlewares module
- swh.web.utils.origin_visits module
- swh.web.utils.query module
- swh.web.utils.swh_templatetags module
- swh.web.utils.typing module
OriginInfoOriginMetadataInfoOriginVisitInfoSnapshotBranchInfoSnapshotReleaseInfoSnapshotContextSnapshotContext.branchSnapshotContext.branch_aliasSnapshotContext.branchesSnapshotContext.branches_urlSnapshotContext.is_emptySnapshotContext.origin_infoSnapshotContext.origin_visits_urlSnapshotContext.query_paramsSnapshotContext.releaseSnapshotContext.release_aliasSnapshotContext.release_idSnapshotContext.releasesSnapshotContext.releases_urlSnapshotContext.revision_idSnapshotContext.revision_infoSnapshotContext.root_directorySnapshotContext.snapshot_idSnapshotContext.snapshot_sizesSnapshotContext.snapshot_swhidSnapshotContext.url_argsSnapshotContext.visit_infoSnapshotContext.browse_url
SWHObjectInfoSWHIDContextSWHIDInfoSWHObjectInfoMetadataContentMetadataContentMetadata.sha1ContentMetadata.sha1_gitContentMetadata.sha256ContentMetadata.blake2s256ContentMetadata.content_urlContentMetadata.mimetypeContentMetadata.encodingContentMetadata.sizeContentMetadata.languageContentMetadata.pathContentMetadata.filenameContentMetadata.directoryContentMetadata.root_directoryContentMetadata.revisionContentMetadata.releaseContentMetadata.snapshotContentMetadata.object_typeContentMetadata.object_idContentMetadata.origin_urlContentMetadata.visit_dateContentMetadata.visit_type
DirectoryMetadataDirectoryMetadata.directoryDirectoryMetadata.nb_filesDirectoryMetadata.nb_dirsDirectoryMetadata.sum_file_sizesDirectoryMetadata.root_directoryDirectoryMetadata.pathDirectoryMetadata.revisionDirectoryMetadata.revision_foundDirectoryMetadata.releaseDirectoryMetadata.snapshotDirectoryMetadata.object_typeDirectoryMetadata.object_idDirectoryMetadata.origin_urlDirectoryMetadata.visit_dateDirectoryMetadata.visit_type
ReleaseMetadataReleaseMetadata.releaseReleaseMetadata.authorReleaseMetadata.author_urlReleaseMetadata.dateReleaseMetadata.nameReleaseMetadata.syntheticReleaseMetadata.targetReleaseMetadata.target_typeReleaseMetadata.snapshotReleaseMetadata.object_typeReleaseMetadata.object_idReleaseMetadata.origin_urlReleaseMetadata.visit_dateReleaseMetadata.visit_type
RevisionMetadataRevisionMetadata.object_typeRevisionMetadata.object_idRevisionMetadata.origin_urlRevisionMetadata.visit_dateRevisionMetadata.visit_typeRevisionMetadata.revisionRevisionMetadata.authorRevisionMetadata.author_urlRevisionMetadata.committerRevisionMetadata.committer_urlRevisionMetadata.dateRevisionMetadata.committer_dateRevisionMetadata.directoryRevisionMetadata.mergeRevisionMetadata.metadataRevisionMetadata.parentsRevisionMetadata.syntheticRevisionMetadata.typeRevisionMetadata.snapshotRevisionMetadata.root_directory
SaveOriginRequestInfoSaveOriginRequestInfo.idSaveOriginRequestInfo.save_request_dateSaveOriginRequestInfo.visit_typeSaveOriginRequestInfo.visit_statusSaveOriginRequestInfo.origin_urlSaveOriginRequestInfo.save_request_statusSaveOriginRequestInfo.loading_task_idSaveOriginRequestInfo.visit_dateSaveOriginRequestInfo.save_task_statusSaveOriginRequestInfo.noteSaveOriginRequestInfo.from_webhookSaveOriginRequestInfo.webhook_originSaveOriginRequestInfo.snapshot_swhidSaveOriginRequestInfo.next_runSaveOriginRequestInfo.metadata
OriginExistenceCheckInfoIntrinsicMetadataFiletypeIntrinsicMetadataFileCitation
- swh.web.utils.url_path_converters module
- swh.web.utils.urlsindex module
Module contents#
- swh.web.utils.reverse(viewname: str, url_args: Dict[str, Any] | None = None, query_params: Mapping[str, str | None] | None = None, current_app: str | None = None, urlconf: str | None = None, request: HttpRequest | None = None) str[source]#
An override of django reverse function supporting query parameters.
- Parameters:
viewname – the name of the django view from which to compute a url
url_args – dictionary of url arguments indexed by their names
query_params – dictionary of query parameters to append to the reversed url
current_app – the name of the django app tighten to the view
urlconf – url configuration module
request – build an absolute URI if provided
- Returns:
the url of the requested view with processed arguments and query parameters
- Return type:
- swh.web.utils.datetime_to_utc(date)[source]#
Returns datetime in UTC without timezone info
- Parameters:
date (datetime.datetime) – input datetime with timezone info
- Returns:
datetime in UTC without timezone info
- Return type:
- swh.web.utils.parse_iso8601_date_to_utc(iso_date: str) datetime[source]#
Given an ISO 8601 datetime string, parse the result as UTC datetime.
- Returns:
a timezone-aware datetime representing the parsed date
- Raises:
swh.web.utils.exc.BadInputExc – provided date does not respect ISO 8601 format
- Samples:
2016-01-12
2016-01-12T09:19:12+0100
2007-01-14T20:34:22Z
- swh.web.utils.shorten_path(path)[source]#
Shorten the given path: for each hash present, only return the first 8 characters followed by an ellipsis
- swh.web.utils.format_utc_iso_date(iso_date, fmt='%d %B %Y, %H:%M:%S UTC')[source]#
Turns a string representation of an ISO 8601 datetime string to UTC and format it into a more human readable one.
For instance, from the following input string: ‘2017-05-04T13:27:13+02:00’ the following one is returned: ‘04 May 2017, 11:27 UTC’. Custom format string may also be provided as parameter
- swh.web.utils.gen_path_info(path)[source]#
Function to generate path data navigation for use with a breadcrumb in the swh web ui.
For instance, from a path /folder1/folder2/folder3, it returns the following list:
[{'name': 'folder1', 'path': 'folder1'}, {'name': 'folder2', 'path': 'folder1/folder2'}, {'name': 'folder3', 'path': 'folder1/folder2/folder3'}]
- Parameters:
path – a filesystem path
- Returns:
a list of path data for navigation as illustrated above.
- Return type:
- swh.web.utils.parse_rst(text, report_level=2)[source]#
Parse a reStructuredText string with docutils.
- swh.web.utils.get_client_ip(request)[source]#
Return the client IP address from an incoming HTTP request.
- Parameters:
request (django.http.HttpRequest) – the incoming HTTP request
- Returns:
The client IP address
- Return type:
- swh.web.utils.context_processor(request)[source]#
Django context processor used to inject variables in all swh-web templates.
- swh.web.utils.resolve_branch_alias(snapshot: Dict[str, Any], branch: Dict[str, Any] | None) Dict[str, Any] | None[source]#
Resolve branch alias in snapshot content.
- Parameters:
snapshot – a full snapshot content
branch – a branch alias contained in the snapshot
- Returns:
The real snapshot branch that got aliased.
- swh.web.utils.rst_to_html(rst: str, raw_enabled: bool = False) str[source]#
Convert reStructuredText document into HTML.
- Parameters:
rst – A string containing a reStructuredText document
- Returns:
Body content of the produced HTML conversion.
- swh.web.utils.cache_set(cache_key: str, obj: ~typing.Any, timeout: int = <object object>, extra_encoders: ~typing.List[~typing.Tuple[type, str, ~typing.Callable]] | None = None) None[source]#
Set a value in django cache.
For optimizing cache size, the value to cache is serialized to binary using msgpack and then compressed with gzip.
- Parameters:
cache_key – string key for the value to set in cache
obj – value to store in cache
timeout – the duration in seconds after which the cache expires
extra_encoders – optional encoders for serializing types that are not default supported by msgpack, see
swh.core.api.serializers
- swh.web.utils.cache_get(cache_key: str, extra_decoders: Dict[str, Callable] | None = None) Any | None[source]#
Get a value from the django cache.
For optimizing cache size, values to cache are serialized to binary using msgpack and then compressed with gzip.
- Parameters:
cache_key – string key for the value to get from cache
extra_decoders – optional decoders for deserializing types that are not default supported by msgpack, see
swh.core.api.serializers
- Returns:
the cached value or
Noneif it does not exist
- swh.web.utils.django_cache(timeout: int = <object object>, catch_exception: bool = False, exception_return_value: ~typing.Any = None, invalidate_cache_pred: ~typing.Callable[[~typing.Any], bool] = <function <lambda>>, extra_encoders: ~typing.List[~typing.Tuple[type, str, ~typing.Callable]] | None = None, extra_decoders: ~typing.Dict[str, ~typing.Callable] | None = None)[source]#
Decorator to put the result of a function call in Django cache, subsequent calls will directly return the cached value.
For optimizing cache size, values to cache are serialized to binary using msgpack and then compressed with gzip.
- Parameters:
timeout – The number of seconds value will be hold in cache
catch_exception – If
True, any thrown exception by the decorated function will be caught and not reraisedexception_return_value – The value to return if previous parameter is set to
Trueinvalidate_cache_pred – A predicate function enabling to invalidate the cache under certain conditions, decorated function will then be called again
extra_encoders – optional encoders for serializing types that are not default supported by msgpack, see
swh.core.api.serializersextra_decoders – optional decoders for deserializing types that are not default supported by msgpack, see
swh.core.api.serializers
- Returns:
The returned value of the decorated function for the specified parameters
- swh.web.utils.origin_visit_types(use_cache: bool = True) List[str][source]#
Return the exhaustive list of visit types for origins ingested into the archive.
- Parameters:
use_cache – if
True, store visit types in django cache for 24 hours.
- swh.web.utils.redirect_to_new_route(request, new_route, permanent=True)[source]#
Redirect a request to another route with url args and query parameters eg: /origin/<url:url-val>/log?path=test can be redirected as /log?url=<url-val>&path=test. This can be used to deprecate routes
- swh.web.utils.demangle_url(url: str) str[source]#
Fix URL where the
://character sequence was mangled into:/by HTTP clients
- swh.web.utils.datatables_pagination_params(request: HttpRequest) Tuple[int, int][source]#
Datatables paginations parameters.
- Parameters:
request – an HttpRequest to get the length and start query parameters
- Returns:
A tuple with the number of results per page and the current page number
- swh.web.utils.strtobool(value: str) bool[source]#
Convert a string representation of truth to True or False.
Port of distutils.util.strtobool due to distutils deprecation and to better handle invalid values as BadInputExc exceptions will result in HTTP 400 errors.
- Raises:
BadInputExc –
valueis not a valid truthy/falsy string