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, persistent_identifier, REVISION, SNAPSHOT | from swh.model.identifiers import DIRECTORY, swhid, REVISION, SNAPSHOT | ||||
from . import SWHPrivateAPIView | from . import SWHPrivateAPIView | ||||
from ..common import SWHPutDepositAPI | from ..common import SWHPutDepositAPI | ||||
from ...errors import make_error_dict, BAD_REQUEST | from ...errors import make_error_dict, BAD_REQUEST | ||||
from ...models import Deposit, DEPOSIT_STATUS_DETAIL | from ...models import Deposit, DEPOSIT_STATUS_DETAIL | ||||
from ...models import DEPOSIT_STATUS_LOAD_SUCCESS | from ...models import DEPOSIT_STATUS_LOAD_SUCCESS | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | def process_put(self, request, headers, collection_name, deposit_id): | ||||
deposit = Deposit.objects.get(pk=deposit_id) | deposit = Deposit.objects.get(pk=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 = persistent_identifier(DIRECTORY, directory_id) | dir_id = swhid(DIRECTORY, directory_id) | ||||
snp_id = persistent_identifier(SNAPSHOT, data["snapshot_id"]) | snp_id = swhid(SNAPSHOT, data["snapshot_id"]) | ||||
rev_id = persistent_identifier(REVISION, revision_id) | rev_id = swhid(REVISION, revision_id) | ||||
deposit.swh_id = dir_id | deposit.swh_id = dir_id | ||||
# new id with contextual information | # new id with contextual information | ||||
deposit.swh_id_context = persistent_identifier( | deposit.swh_id_context = swhid( | ||||
DIRECTORY, | DIRECTORY, | ||||
directory_id, | directory_id, | ||||
metadata={ | metadata={ | ||||
"origin": origin_url, | "origin": origin_url, | ||||
"visit": snp_id, | "visit": snp_id, | ||||
"anchor": rev_id, | "anchor": rev_id, | ||||
"path": "/", | "path": "/", | ||||
}, | }, | ||||
) | ) | ||||
else: # rejected | else: # rejected | ||||
deposit.status = status | deposit.status = status | ||||
deposit.save() | deposit.save() | ||||
return {} | return {} |