Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/views/directory.py
Show All 10 Lines | |||||
from django.shortcuts import redirect, render | from django.shortcuts import redirect, render | ||||
from django.template.defaultfilters import filesizeformat | from django.template.defaultfilters import filesizeformat | ||||
from swh.model.identifiers import DIRECTORY, RELEASE, REVISION, SNAPSHOT | from swh.model.identifiers import DIRECTORY, RELEASE, REVISION, SNAPSHOT | ||||
from swh.web.browse.browseurls import browse_route | from swh.web.browse.browseurls import browse_route | ||||
from swh.web.browse.snapshot_context import get_snapshot_context | from swh.web.browse.snapshot_context import get_snapshot_context | ||||
from swh.web.browse.utils import gen_link, get_directory_entries, get_readme_to_display | from swh.web.browse.utils import gen_link, get_directory_entries, get_readme_to_display | ||||
from swh.web.common import archive | from swh.web.common import archive | ||||
from swh.web.common.exc import NotFoundExc | from swh.web.common.exc import NotFoundExc, http_status_code_message | ||||
from swh.web.common.identifiers import get_swhids_info | from swh.web.common.identifiers import get_swhids_info | ||||
from swh.web.common.typing import DirectoryMetadata, SWHObjectInfo | from swh.web.common.typing import DirectoryMetadata, SWHObjectInfo | ||||
from swh.web.common.utils import gen_path_info, reverse, swh_object_icons | from swh.web.common.utils import gen_path_info, reverse, swh_object_icons | ||||
def _directory_browse(request, sha1_git, path=None): | def _directory_browse(request, sha1_git, path=None): | ||||
root_sha1_git = sha1_git | root_sha1_git = sha1_git | ||||
error_info = {"status_code": 200, "description": None} | |||||
if path: | if path: | ||||
try: | |||||
dir_info = archive.lookup_directory_with_path(sha1_git, path) | dir_info = archive.lookup_directory_with_path(sha1_git, path) | ||||
sha1_git = dir_info["target"] | sha1_git = dir_info["target"] | ||||
except NotFoundExc as e: | |||||
error_info["status_code"] = 404 | |||||
error_info["description"] = f"NotFoundExc: {str(e)}" | |||||
sha1_git = None | |||||
dirs, files = [], [] | |||||
if sha1_git is not None: | |||||
dirs, files = get_directory_entries(sha1_git) | dirs, files = get_directory_entries(sha1_git) | ||||
origin_url = request.GET.get("origin_url") | origin_url = request.GET.get("origin_url") | ||||
if not origin_url: | if not origin_url: | ||||
origin_url = request.GET.get("origin") | origin_url = request.GET.get("origin") | ||||
snapshot_id = request.GET.get("snapshot") | snapshot_id = request.GET.get("snapshot") | ||||
snapshot_context = None | snapshot_context = None | ||||
if origin_url is not None or snapshot_id is not None: | if origin_url is not None or snapshot_id is not None: | ||||
try: | try: | ||||
snapshot_context = get_snapshot_context( | snapshot_context = get_snapshot_context( | ||||
▲ Show 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | return render( | ||||
"top_right_link": top_right_link, | "top_right_link": top_right_link, | ||||
"readme_name": readme_name, | "readme_name": readme_name, | ||||
"readme_url": readme_url, | "readme_url": readme_url, | ||||
"readme_html": readme_html, | "readme_html": readme_html, | ||||
"snapshot_context": snapshot_context, | "snapshot_context": snapshot_context, | ||||
"vault_cooking": vault_cooking, | "vault_cooking": vault_cooking, | ||||
"show_actions": True, | "show_actions": True, | ||||
"swhids_info": swhids_info, | "swhids_info": swhids_info, | ||||
"error_code": error_info["status_code"], | |||||
"error_message": http_status_code_message.get(error_info["status_code"]), | |||||
"error_description": error_info["description"], | |||||
}, | }, | ||||
status=error_info["status_code"], | |||||
) | ) | ||||
@browse_route( | @browse_route( | ||||
r"directory/(?P<sha1_git>[0-9a-f]+)/", | r"directory/(?P<sha1_git>[0-9a-f]+)/", | ||||
view_name="browse-directory", | view_name="browse-directory", | ||||
checksum_args=["sha1_git"], | checksum_args=["sha1_git"], | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |