Changeset View
Changeset View
Standalone View
Standalone View
swh/web/misc/badges.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from base64 import b64encode | from base64 import b64encode | ||||
from typing import cast, Optional | from typing import cast, Optional | ||||
from django.conf.urls import url | from django.conf.urls import url | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | ) -> HttpResponse: | ||||
""" | """ | ||||
left_text = "error" | left_text = "error" | ||||
whole_link = None | whole_link = None | ||||
try: | try: | ||||
if object_type == ORIGIN: | if object_type == ORIGIN: | ||||
service.lookup_origin({"url": object_id}) | service.lookup_origin({"url": object_id}) | ||||
right_text = "repository" | right_text = "repository" | ||||
whole_link = reverse("browse-origin", url_args={"origin_url": object_id}) | whole_link = reverse( | ||||
"browse-origin", query_params={"origin_url": object_id} | |||||
) | |||||
else: | else: | ||||
# when pid is provided, object type and id will be parsed | # when pid is provided, object type and id will be parsed | ||||
# from it | # from it | ||||
if object_pid: | if object_pid: | ||||
parsed_pid = parse_persistent_identifier(object_pid) | parsed_pid = parse_persistent_identifier(object_pid) | ||||
object_type = parsed_pid.object_type | object_type = parsed_pid.object_type | ||||
object_id = parsed_pid.object_id | object_id = parsed_pid.object_id | ||||
swh_object = service.lookup_object(object_type, object_id) | swh_object = service.lookup_object(object_type, object_id) | ||||
▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines |