Fixes LP bug 882189 -- Adds paging support to swift API calls.
This commit is contained in:
parent
05c9110ba2
commit
6afc91208b
@ -831,8 +831,10 @@ def swift_object_exists(request, container_name, object_name):
|
||||
return False
|
||||
|
||||
|
||||
def swift_get_containers(request):
|
||||
return [Container(c) for c in swift_api(request).get_all_containers()]
|
||||
def swift_get_containers(request, marker=None):
|
||||
return [Container(c) for c in swift_api(request).get_all_containers(
|
||||
limit=getattr(settings, 'SWIFT_PAGINATE_LIMIT', 10000),
|
||||
marker=marker)]
|
||||
|
||||
|
||||
def swift_create_container(request, name):
|
||||
@ -846,9 +848,11 @@ def swift_delete_container(request, name):
|
||||
swift_api(request).delete_container(name)
|
||||
|
||||
|
||||
def swift_get_objects(request, container_name, prefix=None):
|
||||
def swift_get_objects(request, container_name, prefix=None, marker=None):
|
||||
container = swift_api(request).get_container(container_name)
|
||||
return [SwiftObject(o) for o in container.get_objects(prefix=prefix)]
|
||||
objects = container.get_objects(prefix=prefix, marker=marker,
|
||||
limit=getattr(settings, 'SWIFT_PAGINATE_LIMIT', 10000))
|
||||
return [SwiftObject(o) for o in objects]
|
||||
|
||||
|
||||
def swift_copy_object(request, orig_container_name, orig_object_name,
|
||||
|
@ -68,11 +68,13 @@ class CreateContainer(forms.SelfHandlingForm):
|
||||
|
||||
@login_required
|
||||
def index(request, tenant_id):
|
||||
marker = request.GET.get('marker', None)
|
||||
|
||||
delete_form, handled = DeleteContainer.maybe_handle(request)
|
||||
if handled:
|
||||
return handled
|
||||
|
||||
containers = api.swift_get_containers(request)
|
||||
containers = api.swift_get_containers(request, marker=marker)
|
||||
|
||||
return shortcuts.render_to_response(
|
||||
'django_openstack/dash/containers/index.html', {
|
||||
|
@ -123,6 +123,8 @@ class CopyObject(forms.SelfHandlingForm):
|
||||
|
||||
@login_required
|
||||
def index(request, tenant_id, container_name):
|
||||
marker = request.GET.get('marker', None)
|
||||
|
||||
delete_form, handled = DeleteObject.maybe_handle(request)
|
||||
if handled:
|
||||
return handled
|
||||
@ -131,7 +133,7 @@ def index(request, tenant_id, container_name):
|
||||
|
||||
if objects is None:
|
||||
filter_form.fields['container_name'].initial = container_name
|
||||
objects = api.swift_get_objects(request, container_name)
|
||||
objects = api.swift_get_objects(request, container_name, marker=marker)
|
||||
|
||||
delete_form.fields['container_name'].initial = container_name
|
||||
return render_to_response(
|
||||
|
@ -1,9 +1,13 @@
|
||||
{%load i18n%}
|
||||
{% load i18n swift_paging %}
|
||||
|
||||
<table id="containers" class="wide">
|
||||
<tr>
|
||||
<th>{% trans "Name" %}</th>
|
||||
<th>{% trans "Actions" %}</th>
|
||||
</tr>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "Name" %}</th>
|
||||
<th>{% trans "Actions" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for container in containers %}
|
||||
<tr class="{% cycle 'odd' 'even' %}">
|
||||
<td>{{ container.name }}</td>
|
||||
@ -16,4 +20,10 @@
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="2">{% object_paging containers %}</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
|
@ -1,19 +1,29 @@
|
||||
{%load i18n%}
|
||||
{% load i18n swift_paging %}
|
||||
|
||||
<table id="objects" class="wide">
|
||||
<tr>
|
||||
<th>{% trans "Name"%}</th>
|
||||
<th style="width: 100px;">{% trans "Actions"%}</th>
|
||||
</tr>
|
||||
{% for object in objects %}
|
||||
<tr class="{% cycle 'odd' 'even' %}">
|
||||
<td>{{ object.name }}</td>
|
||||
<td id="actions">
|
||||
<ul>
|
||||
<li><a href="{% url dash_object_copy request.user.tenant_id container_name object.name %}">{% trans "Copy"%}</a></li>
|
||||
<li class="form">{% include "django_openstack/dash/objects/_delete.html" with form=delete_form %}</li>
|
||||
<li><a href="{% url dash_objects_download request.user.tenant_id container_name object.name %}">{% trans "Download"%}</a>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "Name"%}</th>
|
||||
<th style="width: 100px;">{% trans "Actions"%}</th>
|
||||
</tr>
|
||||
</theaad>
|
||||
<tbody>
|
||||
{% for object in objects %}
|
||||
<tr class="{% cycle 'odd' 'even' %}">
|
||||
<td>{{ object.name }}</td>
|
||||
<td id="actions">
|
||||
<ul>
|
||||
<li><a href="{% url dash_object_copy request.user.tenant_id container_name object.name %}">{% trans "Copy"%}</a></li>
|
||||
<li class="form">{% include "django_openstack/dash/objects/_delete.html" with form=delete_form %}</li>
|
||||
<li><a href="{% url dash_objects_download request.user.tenant_id container_name object.name %}">{% trans "Download"%}</a>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="2">{% object_paging objects %}</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
|
@ -0,0 +1 @@
|
||||
{% if marker %}<a href="?marker={{ marker }}">More</a>{% endif %}
|
@ -0,0 +1,15 @@
|
||||
from django import template
|
||||
from django.conf import settings
|
||||
from django.utils import http
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.inclusion_tag('django_openstack/dash/objects/_paging.html')
|
||||
def object_paging(objects):
|
||||
marker = None
|
||||
if objects and not \
|
||||
len(objects) < getattr(settings, 'SWIFT_PAGINATE_LIMIT', 10000):
|
||||
last_object = objects[-1]
|
||||
marker = http.urlquote_plus(last_object.name)
|
||||
return {'marker': marker}
|
@ -1362,7 +1362,8 @@ class SwiftApiTests(test.TestCase):
|
||||
|
||||
swift_api = self.stub_swift_api()
|
||||
|
||||
swift_api.get_all_containers().AndReturn(containers)
|
||||
swift_api.get_all_containers(limit=10000,
|
||||
marker=None).AndReturn(containers)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -1414,7 +1415,9 @@ class SwiftApiTests(test.TestCase):
|
||||
|
||||
swift_objects = (TEST_RETURN, TEST_RETURN + '2')
|
||||
container = self.mox.CreateMock(cloudfiles.container.Container)
|
||||
container.get_objects(prefix=None).AndReturn(swift_objects)
|
||||
container.get_objects(limit=10000,
|
||||
marker=None,
|
||||
prefix=None).AndReturn(swift_objects)
|
||||
|
||||
swift_api = self.stub_swift_api()
|
||||
|
||||
@ -1437,7 +1440,9 @@ class SwiftApiTests(test.TestCase):
|
||||
|
||||
swift_objects = (TEST_RETURN, TEST_RETURN + '2')
|
||||
container = self.mox.CreateMock(cloudfiles.container.Container)
|
||||
container.get_objects(prefix=PREFIX).AndReturn(swift_objects)
|
||||
container.get_objects(limit=10000,
|
||||
marker=None,
|
||||
prefix=PREFIX).AndReturn(swift_objects)
|
||||
|
||||
swift_api = self.stub_swift_api()
|
||||
|
||||
|
@ -36,7 +36,7 @@ class ContainerViewTests(base.BaseViewTests):
|
||||
def test_index(self):
|
||||
self.mox.StubOutWithMock(api, 'swift_get_containers')
|
||||
api.swift_get_containers(
|
||||
IsA(http.HttpRequest)).AndReturn([self.container])
|
||||
IsA(http.HttpRequest), marker=None).AndReturn([self.container])
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
|
@ -39,7 +39,8 @@ class ObjectViewTests(base.BaseViewTests):
|
||||
self.mox.StubOutWithMock(api, 'swift_get_objects')
|
||||
api.swift_get_objects(
|
||||
IsA(http.HttpRequest),
|
||||
self.CONTAINER_NAME).AndReturn(self.swift_objects)
|
||||
self.CONTAINER_NAME,
|
||||
marker=None).AndReturn(self.swift_objects)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
|
@ -37,6 +37,8 @@ OPENSTACK_KEYSTONE_URL = "http://localhost:5000/v2.0/"
|
||||
OPENSTACK_KEYSTONE_ADMIN_URL = "http://localhost:35357/v2.0"
|
||||
OPENSTACK_KEYSTONE_DEFAULT_ROLE = "Member"
|
||||
|
||||
SWIFT_PAGINATE_LIMIT = 100
|
||||
|
||||
# Configure quantum connection details for networking
|
||||
QUANTUM_ENABLED = True
|
||||
QUANTUM_URL = '127.0.0.1'
|
||||
|
Loading…
x
Reference in New Issue
Block a user