Commit a64d810d authored by Jens Langhammer's avatar Jens Langhammer

Improve S3 Compatibility by removing ns0: prefix in XML Responses

parent 4f607051
Pipeline #3844 passed with stage
in 4 minutes and 36 seconds
...@@ -99,7 +99,7 @@ class Blob(UUIDModel, TagModel): ...@@ -99,7 +99,7 @@ class Blob(UUIDModel, TagModel):
@property @property
def filename(self): def filename(self):
"""Return only the filename part of self.path""" """Return only the filename part of self.path"""
return self.path.split('/')[-1] return self.path
def _open_read_handle(self): def _open_read_handle(self):
if not self._reading_handle: if not self._reading_handle:
......
"""p2 S3 App Config""" """p2 S3 App Config"""
from xml.etree import ElementTree
from django.apps import AppConfig from django.apps import AppConfig
from p2.s3.constants import XML_NAMESPACE
class P2S3Config(AppConfig): class P2S3Config(AppConfig):
"""p2 S3 App Config""" """p2 S3 App Config"""
...@@ -8,3 +12,6 @@ class P2S3Config(AppConfig): ...@@ -8,3 +12,6 @@ class P2S3Config(AppConfig):
name = 'p2.s3' name = 'p2.s3'
label = 'p2_s3' label = 'p2_s3'
verbose_name = 'p2 S3' verbose_name = 'p2 S3'
def ready(self):
ElementTree.register_namespace("", XML_NAMESPACE)
...@@ -4,6 +4,7 @@ from xml.etree import ElementTree ...@@ -4,6 +4,7 @@ from xml.etree import ElementTree
from django.views import View from django.views import View
from guardian.shortcuts import get_objects_for_user from guardian.shortcuts import get_objects_for_user
from p2.s3.constants import XML_NAMESPACE
from p2.s3.http import XMLResponse from p2.s3.http import XMLResponse
...@@ -12,22 +13,18 @@ class ListView(View): ...@@ -12,22 +13,18 @@ class ListView(View):
def get(self, request): def get(self, request):
"""Return list of Buckets""" """Return list of Buckets"""
root = ElementTree.Element("{http://s3.amazonaws.com/doc/2006-03-01}ListAllMyBucketsResult") root = ElementTree.Element("{%s}ListAllMyBucketsResult" % XML_NAMESPACE)
owner = ElementTree.Element("Owner") owner = ElementTree.Element("Owner")
owner_id = ElementTree.SubElement(owner, 'ID') ElementTree.SubElement(owner, 'ID').text = str(request.user.id)
owner_id.text = str(request.user.id) ElementTree.SubElement(owner, 'DisplayName').text = request.user.username
owner_display_name = ElementTree.SubElement(owner, 'DisplayName')
owner_display_name.text = request.user.username
buckets = ElementTree.Element('Buckets') buckets = ElementTree.Element('Buckets')
for volume in get_objects_for_user(self.request.user, 'p2_core.use_volume'): for volume in get_objects_for_user(self.request.user, 'p2_core.use_volume'):
bucket = ElementTree.Element("Bucket") bucket = ElementTree.Element("Bucket")
bucket_name = ElementTree.SubElement(bucket, "Name") ElementTree.SubElement(bucket, "Name").text = volume.name
bucket_name.text = volume.name ElementTree.SubElement(bucket, "CreationDate").text = "2006-02-03T16:45:09.000Z"
bucket_creation_date = ElementTree.SubElement(bucket, "CreationDate")
bucket_creation_date.text = "2006-02-03T16:45:09.000Z"
buckets.append(bucket) buckets.append(bucket)
root.append(owner) root.append(owner)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment