Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/snapshot_context.py
Show First 20 Lines • Show All 424 Lines • ▼ Show 20 Lines | ) -> SnapshotContext: | ||||
assert origin_url is not None or snapshot_id is not None | assert origin_url is not None or snapshot_id is not None | ||||
origin_info = None | origin_info = None | ||||
visit_info = None | visit_info = None | ||||
url_args = {} | url_args = {} | ||||
query_params: Dict[str, Any] = {} | query_params: Dict[str, Any] = {} | ||||
origin_visits_url = None | origin_visits_url = None | ||||
if origin_url: | if origin_url: | ||||
if visit_id is not None: | |||||
query_params["visit_id"] = visit_id | |||||
elif snapshot_id is not None: | |||||
query_params["snapshot"] = snapshot_id | |||||
origin_info = service.lookup_origin({"url": origin_url}) | origin_info = service.lookup_origin({"url": origin_url}) | ||||
visit_info = get_origin_visit(origin_info, timestamp, visit_id, snapshot_id) | visit_info = get_origin_visit(origin_info, timestamp, visit_id, snapshot_id) | ||||
formatted_date = format_utc_iso_date(visit_info["date"]) | formatted_date = format_utc_iso_date(visit_info["date"]) | ||||
visit_info["formatted_date"] = formatted_date | visit_info["formatted_date"] = formatted_date | ||||
snapshot_id = visit_info["snapshot"] | snapshot_id = visit_info["snapshot"] | ||||
if not snapshot_id: | if not snapshot_id: | ||||
Show All 9 Lines | if origin_url: | ||||
timestamp = visit_info["date"] | timestamp = visit_info["date"] | ||||
branches, releases = get_origin_visit_snapshot( | branches, releases = get_origin_visit_snapshot( | ||||
origin_info, timestamp, visit_id, snapshot_id | origin_info, timestamp, visit_id, snapshot_id | ||||
) | ) | ||||
query_params["origin_url"] = origin_info["url"] | query_params["origin_url"] = origin_info["url"] | ||||
origin_visits_url = reverse("browse-origin-visits", query_params=query_params) | origin_visits_url = reverse( | ||||
"browse-origin-visits", query_params={"origin_url": origin_info["url"]} | |||||
if visit_id is not None: | ) | ||||
query_params["visit_id"] = visit_id | |||||
if timestamp is not None: | if timestamp is not None: | ||||
query_params["timestamp"] = format_utc_iso_date( | query_params["timestamp"] = format_utc_iso_date( | ||||
timestamp, "%Y-%m-%dT%H:%M:%SZ" | timestamp, "%Y-%m-%dT%H:%M:%SZ" | ||||
) | ) | ||||
visit_url = reverse("browse-origin-directory", query_params=query_params) | visit_url = reverse("browse-origin-directory", query_params=query_params) | ||||
visit_info["url"] = visit_url | visit_info["url"] = visit_url | ||||
▲ Show 20 Lines • Show All 254 Lines • ▼ Show 20 Lines | ): | ||||
if origin_info: | if origin_info: | ||||
browse_view_name = "browse-origin-log" | browse_view_name = "browse-origin-log" | ||||
else: | else: | ||||
browse_view_name = "browse-snapshot-log" | browse_view_name = "browse-snapshot-log" | ||||
history_url = None | history_url = None | ||||
if snapshot_id != _empty_snapshot_id: | if snapshot_id != _empty_snapshot_id: | ||||
query_params.pop("path", None) | |||||
history_url = reverse( | history_url = reverse( | ||||
browse_view_name, url_args=url_args, query_params=query_params | browse_view_name, url_args=url_args, query_params=query_params | ||||
) | ) | ||||
nb_files = None | nb_files = None | ||||
nb_dirs = None | nb_dirs = None | ||||
dir_path = None | dir_path = None | ||||
if root_directory: | if root_directory: | ||||
▲ Show 20 Lines • Show All 478 Lines • ▼ Show 20 Lines | try: | ||||
) | ) | ||||
displayed_branches, _ = process_snapshot_branches(snapshot) | displayed_branches, _ = process_snapshot_branches(snapshot) | ||||
except Exception as exc: | except Exception as exc: | ||||
return handle_view_exception(request, exc) | return handle_view_exception(request, exc) | ||||
for branch in displayed_branches: | for branch in displayed_branches: | ||||
if snapshot_id: | rev_query_params = {} | ||||
revision_url = reverse( | if origin_info: | ||||
"browse-revision", | rev_query_params["origin_url"] = origin_info["url"] | ||||
url_args={"sha1_git": branch["revision"]}, | |||||
query_params={"snapshot_id": snapshot_id}, | |||||
) | |||||
else: | |||||
revision_url = reverse( | revision_url = reverse( | ||||
"browse-revision", | "browse-revision", | ||||
url_args={"sha1_git": branch["revision"]}, | url_args={"sha1_git": branch["revision"]}, | ||||
query_params={"origin_url": origin_info["url"]}, | query_params=query_params, | ||||
) | ) | ||||
query_params["branch"] = branch["name"] | query_params["branch"] = branch["name"] | ||||
directory_url = reverse( | directory_url = reverse( | ||||
browse_view_name, url_args=url_args, query_params=query_params | browse_view_name, url_args=url_args, query_params=query_params | ||||
) | ) | ||||
del query_params["branch"] | del query_params["branch"] | ||||
branch["revision_url"] = revision_url | branch["revision_url"] = revision_url | ||||
branch["directory_url"] = directory_url | branch["directory_url"] = directory_url | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | try: | ||||
) | ) | ||||
_, displayed_releases = process_snapshot_branches(snapshot) | _, displayed_releases = process_snapshot_branches(snapshot) | ||||
except Exception as exc: | except Exception as exc: | ||||
return handle_view_exception(request, exc) | return handle_view_exception(request, exc) | ||||
for release in displayed_releases: | for release in displayed_releases: | ||||
if snapshot_id: | query_params_tgt = {"snapshot": snapshot_id} | ||||
query_params_tgt = {"snapshot_id": snapshot_id} | if origin_info: | ||||
else: | query_params_tgt["origin_url"] = origin_info["url"] | ||||
query_params_tgt = {"origin_url": origin_info["url"]} | |||||
release_url = reverse( | release_url = reverse( | ||||
"browse-release", | "browse-release", | ||||
url_args={"sha1_git": release["id"]}, | url_args={"sha1_git": release["id"]}, | ||||
query_params=query_params_tgt, | query_params=query_params_tgt, | ||||
) | ) | ||||
target_url = "" | target_url = "" | ||||
if release["target_type"] == "revision": | if release["target_type"] == "revision": | ||||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |