Can now filter objects in the dashboard
Tests added pep8 fixes
This commit is contained in:
parent
556aad36fa
commit
c5ed82a909
@ -514,9 +514,9 @@ def swift_delete_container(name):
|
||||
swift_api().delete_container(name)
|
||||
|
||||
|
||||
def swift_get_objects(container_name):
|
||||
def swift_get_objects(container_name, prefix=None):
|
||||
container = swift_api().get_container(container_name)
|
||||
return [SwiftObject(o) for o in container.get_objects()]
|
||||
return [SwiftObject(o) for o in container.get_objects(prefix=prefix)]
|
||||
|
||||
|
||||
def swift_copy_object(orig_container_name, orig_object_name,
|
||||
|
@ -37,6 +37,19 @@ from django_openstack import forms
|
||||
LOG = logging.getLogger('django_openstack.dash')
|
||||
|
||||
|
||||
class FilterObjects(forms.SelfHandlingForm):
|
||||
container_name = forms.CharField(widget=forms.HiddenInput())
|
||||
object_prefix = forms.CharField(required=False)
|
||||
|
||||
def handle(self, request, data):
|
||||
object_prefix = data['object_prefix'] or None
|
||||
|
||||
objects = api.swift_get_objects(data['container_name'],
|
||||
prefix=object_prefix)
|
||||
|
||||
return objects
|
||||
|
||||
|
||||
class DeleteObject(forms.SelfHandlingForm):
|
||||
object_name = forms.CharField(widget=forms.HiddenInput())
|
||||
container_name = forms.CharField(widget=forms.HiddenInput())
|
||||
@ -104,13 +117,17 @@ def index(request, tenant_id, container_name):
|
||||
if handled:
|
||||
return handled
|
||||
|
||||
objects = api.swift_get_objects(container_name)
|
||||
filter_form, objects = FilterObjects.maybe_handle(request)
|
||||
if not objects:
|
||||
filter_form.fields['container_name'].initial = container_name
|
||||
objects = api.swift_get_objects(container_name)
|
||||
|
||||
delete_form.fields['container_name'].initial = container_name
|
||||
return render_to_response('dash_objects.html', {
|
||||
'container_name': container_name,
|
||||
'objects': objects,
|
||||
'delete_form': delete_form,
|
||||
'filter_form': filter_form,
|
||||
}, context_instance=template.RequestContext(request))
|
||||
|
||||
|
||||
|
@ -1397,7 +1397,7 @@ class SwiftApiTests(test.TestCase):
|
||||
|
||||
swift_objects = (TEST_RETURN, TEST_RETURN + '2')
|
||||
container = self.mox.CreateMock(cloudfiles.container.Container)
|
||||
container.get_objects().AndReturn(swift_objects)
|
||||
container.get_objects(prefix=None).AndReturn(swift_objects)
|
||||
|
||||
swift_api = self.stub_swift_api()
|
||||
|
||||
@ -1414,6 +1414,29 @@ class SwiftApiTests(test.TestCase):
|
||||
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_swift_get_objects_with_prefix(self):
|
||||
NAME = 'containerName'
|
||||
PREFIX = 'prefacedWith'
|
||||
|
||||
swift_objects = (TEST_RETURN, TEST_RETURN + '2')
|
||||
container = self.mox.CreateMock(cloudfiles.container.Container)
|
||||
container.get_objects(prefix=PREFIX).AndReturn(swift_objects)
|
||||
|
||||
swift_api = self.stub_swift_api()
|
||||
|
||||
swift_api.get_container(NAME).AndReturn(container)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
ret_val = api.swift_get_objects(NAME, prefix=PREFIX)
|
||||
|
||||
self.assertEqual(len(ret_val), len(swift_objects))
|
||||
for swift_object in ret_val:
|
||||
self.assertIsInstance(swift_object, api.SwiftObject)
|
||||
self.assertIn(swift_object._apiresource, swift_objects)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_swift_upload_object(self):
|
||||
CONTAINER_NAME = 'containerName'
|
||||
OBJECT_NAME = 'objectName'
|
||||
|
@ -164,3 +164,27 @@ class ObjectViewTests(base.BaseViewTests):
|
||||
ORIG_OBJECT_NAME]))
|
||||
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_filter(self):
|
||||
PREFIX = 'prefix'
|
||||
|
||||
formData = {'method': 'FilterObjects',
|
||||
'container_name': self.CONTAINER_NAME,
|
||||
'object_prefix': PREFIX,
|
||||
}
|
||||
|
||||
self.mox.StubOutWithMock(api, 'swift_get_objects')
|
||||
api.swift_get_objects(unicode(self.CONTAINER_NAME),
|
||||
prefix=unicode(PREFIX)
|
||||
).AndReturn(self.swift_objects)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self.client.post(reverse('dash_objects',
|
||||
args=[self.TEST_TENANT,
|
||||
self.CONTAINER_NAME]),
|
||||
formData)
|
||||
|
||||
self.assertTemplateUsed(res, 'dash_objects.html')
|
||||
|
||||
self.mox.VerifyAll()
|
||||
|
10
openstack-dashboard/dashboard/templates/_object_filter.html
Normal file
10
openstack-dashboard/dashboard/templates/_object_filter.html
Normal file
@ -0,0 +1,10 @@
|
||||
<form id="form_filter_{{ container_name }}" class="form-filter" method="post">
|
||||
{% csrf_token %}
|
||||
{% for hidden in form.hidden_fields %}
|
||||
{{hidden}}
|
||||
{% endfor %}
|
||||
{% for field in form.visible_fields %}
|
||||
{{field}}
|
||||
{% endfor %}
|
||||
<input id="filter_{{ container_name }}" class="filter" type="submit" value="Filter" />
|
||||
</form>
|
@ -19,13 +19,8 @@
|
||||
{% if objects %}
|
||||
<div class='table_title wide'>
|
||||
<h3>Objects</h3>
|
||||
<div class='search'>
|
||||
<form action='' method='post'>
|
||||
<fieldset>
|
||||
<label for='table_search'>Search</label>
|
||||
<input id='table_search' name='search' type='text' value='' />
|
||||
</fieldset>
|
||||
</form>
|
||||
<div class='filter'>
|
||||
{% include '_object_filter.html' with form=filter_form %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -344,8 +344,9 @@ input[readonly="readonly"] {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
.form-filter {
|
||||
float: right;
|
||||
}
|
||||
|
||||
|
||||
.search {
|
||||
|
Loading…
x
Reference in New Issue
Block a user