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()
- 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- OriginInfo
- OriginMetadataInfo
- OriginVisitInfo
- SnapshotBranchInfo
- SnapshotReleaseInfo
- SnapshotContext- SnapshotContext.branch
- SnapshotContext.branch_alias
- SnapshotContext.branches
- SnapshotContext.branches_url
- SnapshotContext.is_empty
- SnapshotContext.origin_info
- SnapshotContext.origin_visits_url
- SnapshotContext.query_params
- SnapshotContext.release
- SnapshotContext.release_alias
- SnapshotContext.release_id
- SnapshotContext.releases
- SnapshotContext.releases_url
- SnapshotContext.revision_id
- SnapshotContext.revision_info
- SnapshotContext.root_directory
- SnapshotContext.snapshot_id
- SnapshotContext.snapshot_sizes
- SnapshotContext.snapshot_swhid
- SnapshotContext.url_args
- SnapshotContext.visit_info
- SnapshotContext.browse_url
 
- SWHObjectInfo
- SWHIDContext
- SWHIDInfo
- SWHObjectInfoMetadata
- ContentMetadata- ContentMetadata.sha1
- ContentMetadata.sha1_git
- ContentMetadata.sha256
- ContentMetadata.blake2s256
- ContentMetadata.content_url
- ContentMetadata.mimetype
- ContentMetadata.encoding
- ContentMetadata.size
- ContentMetadata.language
- ContentMetadata.path
- ContentMetadata.filename
- ContentMetadata.directory
- ContentMetadata.root_directory
- ContentMetadata.revision
- ContentMetadata.release
- ContentMetadata.snapshot
- ContentMetadata.object_type
- ContentMetadata.object_id
- ContentMetadata.origin_url
- ContentMetadata.visit_date
- ContentMetadata.visit_type
 
- DirectoryMetadata- DirectoryMetadata.directory
- DirectoryMetadata.nb_files
- DirectoryMetadata.nb_dirs
- DirectoryMetadata.sum_file_sizes
- DirectoryMetadata.root_directory
- DirectoryMetadata.path
- DirectoryMetadata.revision
- DirectoryMetadata.revision_found
- DirectoryMetadata.release
- DirectoryMetadata.snapshot
- DirectoryMetadata.object_type
- DirectoryMetadata.object_id
- DirectoryMetadata.origin_url
- DirectoryMetadata.visit_date
- DirectoryMetadata.visit_type
 
- ReleaseMetadata- ReleaseMetadata.release
- ReleaseMetadata.author
- ReleaseMetadata.author_url
- ReleaseMetadata.date
- ReleaseMetadata.name
- ReleaseMetadata.synthetic
- ReleaseMetadata.target
- ReleaseMetadata.target_type
- ReleaseMetadata.object_type
- ReleaseMetadata.object_id
- ReleaseMetadata.origin_url
- ReleaseMetadata.visit_date
- ReleaseMetadata.visit_type
- ReleaseMetadata.snapshot
 
- RevisionMetadata- RevisionMetadata.object_type
- RevisionMetadata.object_id
- RevisionMetadata.origin_url
- RevisionMetadata.visit_date
- RevisionMetadata.visit_type
- RevisionMetadata.revision
- RevisionMetadata.author
- RevisionMetadata.author_url
- RevisionMetadata.committer
- RevisionMetadata.committer_url
- RevisionMetadata.date
- RevisionMetadata.committer_date
- RevisionMetadata.directory
- RevisionMetadata.merge
- RevisionMetadata.metadata
- RevisionMetadata.parents
- RevisionMetadata.synthetic
- RevisionMetadata.type
- RevisionMetadata.snapshot
 
- SaveOriginRequestInfo- SaveOriginRequestInfo.id
- SaveOriginRequestInfo.save_request_date
- SaveOriginRequestInfo.visit_type
- SaveOriginRequestInfo.visit_status
- SaveOriginRequestInfo.origin_url
- SaveOriginRequestInfo.save_request_status
- SaveOriginRequestInfo.loading_task_id
- SaveOriginRequestInfo.visit_date
- SaveOriginRequestInfo.save_task_status
- SaveOriginRequestInfo.note
- SaveOriginRequestInfo.from_webhook
- SaveOriginRequestInfo.webhook_origin
- SaveOriginRequestInfo.snapshot_swhid
- SaveOriginRequestInfo.next_run
 
- OriginExistenceCheckInfo
- IntrinsicMetadataFiletype
- IntrinsicMetadataFile
- Citation
 
- 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 reraised
- exception_return_value – The value to return if previous parameter is set to - True
- invalidate_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.serializers
- extra_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.get_deposits_list(username: str | None = None) List[Dict[str, Any]][source]#
- Return the list of software deposits using swh-deposit API 
- 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