Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/service_document.py
# Copyright (C) 2017-2020 The Software Heritage developers | # Copyright (C) 2017-2021 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.shortcuts import render | from django.shortcuts import render | ||||
from django.urls import reverse | from django.urls import reverse | ||||
from ..config import COL_IRI | from swh.deposit.api.common import ( | ||||
from ..models import DepositClient, DepositCollection | ACCEPT_ARCHIVE_CONTENT_TYPES, | ||||
from .common import ACCEPT_ARCHIVE_CONTENT_TYPES, ACCEPT_PACKAGINGS, APIBase | ACCEPT_PACKAGINGS, | ||||
APIBase, | |||||
) | |||||
from swh.deposit.config import COL_IRI | |||||
from swh.deposit.models import DepositCollection | |||||
class ServiceDocumentAPI(APIBase): | class ServiceDocumentAPI(APIBase): | ||||
def get(self, req, *args, **kwargs): | def get(self, request, *args, **kwargs): | ||||
client = DepositClient.objects.get(username=req.user) | client = request.user | ||||
collections = {} | collections = {} | ||||
for col_id in client.collections: | for col_id in client.collections: | ||||
col = DepositCollection.objects.get(pk=col_id) | col = DepositCollection.objects.get(pk=col_id) | ||||
col_uri = req.build_absolute_uri(reverse(COL_IRI, args=[col.name])) | col_uri = request.build_absolute_uri(reverse(COL_IRI, args=[col.name])) | ||||
collections[col.name] = col_uri | collections[col.name] = col_uri | ||||
context = { | context = { | ||||
"max_upload_size": self.config["max_upload_size"], | "max_upload_size": self.config["max_upload_size"], | ||||
"accept_packagings": ACCEPT_PACKAGINGS, | "accept_packagings": ACCEPT_PACKAGINGS, | ||||
"accept_content_types": ACCEPT_ARCHIVE_CONTENT_TYPES, | "accept_content_types": ACCEPT_ARCHIVE_CONTENT_TYPES, | ||||
"collections": collections, | "collections": collections, | ||||
} | } | ||||
return render( | return render( | ||||
req, "deposit/service_document.xml", context, content_type="application/xml" | request, | ||||
"deposit/service_document.xml", | |||||
context, | |||||
content_type="application/xml", | |||||
) | ) |