Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/views/release.py
Show All 35 Lines | def release_browse(request, sha1_git): | ||||
identified by its id. | identified by its id. | ||||
The url that points to it is :http:get:`/browse/release/(sha1_git)/`. | The url that points to it is :http:get:`/browse/release/(sha1_git)/`. | ||||
""" | """ | ||||
try: | try: | ||||
release = service.lookup_release(sha1_git) | release = service.lookup_release(sha1_git) | ||||
snapshot_context = {} | snapshot_context = {} | ||||
origin_info = None | origin_info = None | ||||
snapshot_id = request.GET.get("snapshot_id", None) | snapshot_id = request.GET.get("snapshot_id") | ||||
origin_url = request.GET.get("origin_url", None) | if not snapshot_id: | ||||
snapshot_id = request.GET.get("snapshot") | |||||
origin_url = request.GET.get("origin_url") | |||||
if not origin_url: | if not origin_url: | ||||
origin_url = request.GET.get("origin", None) | origin_url = request.GET.get("origin") | ||||
timestamp = request.GET.get("timestamp", None) | timestamp = request.GET.get("timestamp") | ||||
visit_id = request.GET.get("visit_id", None) | visit_id = request.GET.get("visit_id") | ||||
if origin_url: | if origin_url: | ||||
try: | try: | ||||
snapshot_context = get_snapshot_context( | snapshot_context = get_snapshot_context( | ||||
snapshot_id, origin_url, timestamp, visit_id | snapshot_id, origin_url, timestamp, visit_id | ||||
) | ) | ||||
except NotFoundExc: | except NotFoundExc as e: | ||||
raw_rel_url = reverse("browse-release", url_args={"sha1_git": sha1_git}) | raw_rel_url = reverse("browse-release", url_args={"sha1_git": sha1_git}) | ||||
error_message = ( | error_message = ( | ||||
vlorentz: should rename this variable or move it in the if block | |||||
"The Software Heritage archive has a release " | "The Software Heritage archive has a release " | ||||
"with the hash you provided but the origin " | "with the hash you provided but the origin " | ||||
"mentioned in your request appears broken: %s. " | "mentioned in your request appears broken: %s. " | ||||
"Please check the URL and try again.\n\n" | "Please check the URL and try again.\n\n" | ||||
"Nevertheless, you can still browse the release " | "Nevertheless, you can still browse the release " | ||||
"without origin information: %s" | "without origin information: %s" | ||||
% (gen_link(origin_url), gen_link(raw_rel_url)) | % (gen_link(origin_url), gen_link(raw_rel_url)) | ||||
) | ) | ||||
if str(e).startswith("Origin"): | |||||
raise NotFoundExc(error_message) | raise NotFoundExc(error_message) | ||||
else: | |||||
raise e | |||||
origin_info = snapshot_context["origin_info"] | origin_info = snapshot_context["origin_info"] | ||||
elif snapshot_id: | elif snapshot_id: | ||||
snapshot_context = get_snapshot_context(snapshot_id) | snapshot_context = get_snapshot_context(snapshot_id) | ||||
except Exception as exc: | except Exception as exc: | ||||
return handle_view_exception(request, exc) | return handle_view_exception(request, exc) | ||||
target_url = None | target_url = None | ||||
if release["target_type"] == REVISION: | if release["target_type"] == REVISION: | ||||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | def release_browse(request, sha1_git): | ||||
rev_directory_url = None | rev_directory_url = None | ||||
if rev_directory is not None: | if rev_directory is not None: | ||||
if origin_info: | if origin_info: | ||||
rev_directory_url = reverse( | rev_directory_url = reverse( | ||||
"browse-origin-directory", | "browse-origin-directory", | ||||
query_params={ | query_params={ | ||||
"origin_url": origin_info["url"], | "origin_url": origin_info["url"], | ||||
"release": release["name"], | "release": release["name"], | ||||
"snapshot": snapshot_id, | |||||
}, | }, | ||||
) | ) | ||||
elif snapshot_id: | elif snapshot_id: | ||||
rev_directory_url = reverse( | rev_directory_url = reverse( | ||||
"browse-snapshot-directory", | "browse-snapshot-directory", | ||||
url_args={"snapshot_id": snapshot_id}, | url_args={"snapshot_id": snapshot_id}, | ||||
query_params={"release": release["name"]}, | query_params={"release": release["name"]}, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |
should rename this variable or move it in the if block