Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/private/deposit_update_status.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 rest_framework.parsers import JSONParser | from rest_framework.parsers import JSONParser | ||||
from swh.model.identifiers import DIRECTORY, REVISION, SNAPSHOT, swhid | from swh.model.identifiers import DIRECTORY, REVISION, SNAPSHOT, swhid | ||||
from . import APIPrivateView | from . import APIPrivateView | ||||
from ...errors import BAD_REQUEST, DepositError | from ...errors import BAD_REQUEST, DepositError | ||||
from ...models import DEPOSIT_STATUS_DETAIL, DEPOSIT_STATUS_LOAD_SUCCESS, Deposit | from ...models import DEPOSIT_STATUS_DETAIL, DEPOSIT_STATUS_LOAD_SUCCESS | ||||
from ..common import APIPut, ParsedRequestHeaders | from ..common import APIPut, ParsedRequestHeaders, get_deposit_by_id | ||||
MANDATORY_KEYS = ["origin_url", "revision_id", "directory_id", "snapshot_id"] | MANDATORY_KEYS = ["origin_url", "revision_id", "directory_id", "snapshot_id"] | ||||
class APIUpdateStatus(APIPrivateView, APIPut): | class APIUpdateStatus(APIPrivateView, APIPut): | ||||
"""Deposit request class to update the deposit's status. | """Deposit request class to update the deposit's status. | ||||
HTTP verbs supported: PUT | HTTP verbs supported: PUT | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | ) -> None: | ||||
Returns: | Returns: | ||||
204 No content | 204 No content | ||||
400 Bad request if checks fail | 400 Bad request if checks fail | ||||
""" | """ | ||||
data = request.data | data = request.data | ||||
deposit = Deposit.objects.get(pk=deposit_id) | deposit = get_deposit_by_id(deposit_id) | ||||
status = data["status"] | status = data["status"] | ||||
deposit.status = status | deposit.status = status | ||||
if status == DEPOSIT_STATUS_LOAD_SUCCESS: | if status == DEPOSIT_STATUS_LOAD_SUCCESS: | ||||
origin_url = data["origin_url"] | origin_url = data["origin_url"] | ||||
directory_id = data["directory_id"] | directory_id = data["directory_id"] | ||||
revision_id = data["revision_id"] | revision_id = data["revision_id"] | ||||
dir_id = swhid(DIRECTORY, directory_id) | dir_id = swhid(DIRECTORY, directory_id) | ||||
Show All 19 Lines |