Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/private/deposit_update_status.py
# Copyright (C) 2017-2018 The Software Heritage developers | # Copyright (C) 2017-2018 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 persistent_identifier, REVISION | from swh.model.identifiers import ( | ||||
persistent_identifier, REVISION, DIRECTORY | |||||
) | |||||
from ..common import SWHPutDepositAPI, SWHPrivateAPIView | from ..common import SWHPutDepositAPI, SWHPrivateAPIView | ||||
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 | ||||
class SWHUpdateStatusDeposit(SWHPutDepositAPI, SWHPrivateAPIView): | class SWHUpdateStatusDeposit(SWHPutDepositAPI, SWHPrivateAPIView): | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | def process_put(self, req, headers, collection_name, deposit_id): | ||||
"""Update the deposit's status | """Update the deposit's status | ||||
Returns: | Returns: | ||||
204 No content | 204 No content | ||||
""" | """ | ||||
deposit = Deposit.objects.get(pk=deposit_id) | deposit = Deposit.objects.get(pk=deposit_id) | ||||
deposit.status = req.data['status'] # checks already done before | deposit.status = req.data['status'] # checks already done before | ||||
swh_id = req.data.get('revision_id') | |||||
if swh_id: | origin_url = req.data.get('origin_url') | ||||
deposit.swh_id = persistent_identifier(REVISION, {'id': swh_id}) | |||||
dir_id = req.data.get('directory_id') | |||||
if dir_id: | |||||
deposit.swh_id = persistent_identifier(DIRECTORY, dir_id) | |||||
deposit.swh_id_context = persistent_identifier( | |||||
DIRECTORY, dir_id, metadata={'origin': origin_url}) | |||||
rev_id = req.data.get('revision_id') | |||||
if rev_id: | |||||
deposit.swh_anchor_id = persistent_identifier( | |||||
REVISION, rev_id) | |||||
deposit.swh_anchor_id_context = persistent_identifier( | |||||
REVISION, rev_id, metadata={'origin': origin_url}) | |||||
deposit.save() | deposit.save() | ||||
return {} | return {} |