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_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()
lookup_content_raw()
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_fetch()
vault_progress()
diff_revision()
get_revisions_walker()
lookup_object()
lookup_missing_hashes()
lookup_origins_by_sha1s()
- 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.object_type
DirectoryMetadata.object_id
DirectoryMetadata.origin_url
DirectoryMetadata.visit_date
DirectoryMetadata.visit_type
DirectoryMetadata.root_directory
DirectoryMetadata.path
DirectoryMetadata.revision
DirectoryMetadata.revision_found
DirectoryMetadata.release
DirectoryMetadata.snapshot
ReleaseMetadata
ReleaseMetadata.object_type
ReleaseMetadata.object_id
ReleaseMetadata.origin_url
ReleaseMetadata.visit_date
ReleaseMetadata.visit_type
ReleaseMetadata.release
ReleaseMetadata.author
ReleaseMetadata.author_url
ReleaseMetadata.date
ReleaseMetadata.name
ReleaseMetadata.synthetic
ReleaseMetadata.target
ReleaseMetadata.target_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
OriginExistenceCheckInfo
- swh.web.utils.urlsindex module
Module contents:
- swh.web.utils.reverse(viewname: str, url_args: Optional[Dict[str, Any]] = None, query_params: Optional[Mapping[str, Optional[str]]] = None, current_app: Optional[str] = None, urlconf: Optional[str] = None, request: Optional[HttpRequest] = 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.is_swh_web_development(request: HttpRequest) bool [source]#
Indicate if we are running a development version of swh-web.
- swh.web.utils.is_swh_web_staging(request: HttpRequest) bool [source]#
Indicate if we are running a staging version of swh-web.
- swh.web.utils.is_swh_web_production(request: HttpRequest) bool [source]#
Indicate if we are running the public production version of swh-web.
- 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: Optional[Dict[str, Any]]) Optional[Dict[str, Any]] [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) 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.prettify_html(html: str) str [source]#
Prettify an HTML document.
- Parameters:
html – Input HTML document
- Returns:
The prettified HTML document
- swh.web.utils.django_cache(timeout: int = <object object>, catch_exception: bool = False, exception_return_value: ~typing.Optional[~typing.Any] = None, invalidate_cache_pred: ~typing.Callable[[~typing.Any], bool] = <function <lambda>>)[source]#
Decorator to put the result of a function call in Django cache, subsequent calls will directly return the cached value.
- 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
True
invalidate_cache_pred – A predicate function enabling to invalidate the cache under certain conditions, decorated function will then be called again
- Returns:
The returned value of the decorated function for the specified parameters
- swh.web.utils.get_deposits_list(username: Optional[str] = None) List[Dict[str, Any]] [source]#
Return the list of software deposits using swh-deposit API