Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/content.py
# Copyright (C) 2017-2020 The Software Heritage developers | # Copyright (C) 2017-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 General Public License version 3, or any later version | # License: GNU 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 django.http import HttpResponse | from django.http import HttpResponse | ||||
from django.shortcuts import render | from django.shortcuts import render | ||||
from rest_framework import status | from rest_framework import status | ||||
from ..errors import NOT_FOUND, make_error_response, make_error_response_from_dict | from ..errors import NOT_FOUND, make_error_response | ||||
from ..models import DEPOSIT_STATUS_DETAIL, Deposit, DepositRequest | from ..models import DEPOSIT_STATUS_DETAIL, Deposit, DepositRequest | ||||
from .common import APIBase | from .common import APIBase | ||||
class ContentAPI(APIBase): | class ContentAPI(APIBase): | ||||
"""Deposit request class defining api endpoints for sword deposit. | """Deposit request class defining api endpoints for sword deposit. | ||||
What's known as 'Cont-IRI' and 'File-IRI' in the sword specification. | What's known as 'Cont-IRI' and 'File-IRI' in the sword specification. | ||||
HTTP verbs supported: GET | HTTP verbs supported: GET | ||||
""" | """ | ||||
def get(self, req, collection_name: str, deposit_id: int) -> HttpResponse: | def get(self, req, collection_name: str, deposit_id: int) -> HttpResponse: | ||||
checks = self.checks(req, collection_name, deposit_id) | self.checks(req, collection_name, deposit_id) | ||||
if "error" in checks: | |||||
return make_error_response_from_dict(req, checks["error"]) | |||||
try: | try: | ||||
deposit = Deposit.objects.get(pk=deposit_id) | deposit = Deposit.objects.get(pk=deposit_id) | ||||
if deposit.collection.name != collection_name: | if deposit.collection.name != collection_name: | ||||
raise Deposit.DoesNotExist | raise Deposit.DoesNotExist | ||||
except Deposit.DoesNotExist: | except Deposit.DoesNotExist: | ||||
return make_error_response( | return make_error_response( | ||||
req, | req, | ||||
Show All 20 Lines |