summaryrefslogtreecommitdiff
path: root/horizon/dashboards/nova
diff options
context:
space:
mode:
authorTihomir Trifonov <t.trifonov@gmail.com>2012-08-03 13:17:49 +0300
committerTihomir Trifonov <t.trifonov@gmail.com>2012-08-03 16:11:34 +0300
commit127565031b5406689dd8e165f74fd1edb79084cb (patch)
tree4ac9e78a2c4199db416ced3aabce88d49b5afb20 /horizon/dashboards/nova
parent2f0678db4543a1a06bd19d8185028680a5318ddd (diff)
downloadtuskar-ui-127565031b5406689dd8e165f74fd1edb79084cb.tar.gz
Added breadcrumb selector for swift subfolders
Fixes bug 1009970 Change-Id: Idd1d0ac31ca132ce09afb49c0e9221997232cfc2
Diffstat (limited to 'horizon/dashboards/nova')
-rw-r--r--horizon/dashboards/nova/containers/templates/containers/detail.html16
-rw-r--r--horizon/dashboards/nova/containers/tests.py28
-rw-r--r--horizon/dashboards/nova/containers/views.py9
3 files changed, 50 insertions, 3 deletions
diff --git a/horizon/dashboards/nova/containers/templates/containers/detail.html b/horizon/dashboards/nova/containers/templates/containers/detail.html
index 4c2cf460..a2e15f49 100644
--- a/horizon/dashboards/nova/containers/templates/containers/detail.html
+++ b/horizon/dashboards/nova/containers/templates/containers/detail.html
@@ -4,7 +4,21 @@
{% block page_header %}
<div class='page-header'>
- <h2>{% trans "Container" %}: {{ container_name }}<small>/{{ subfolder_path|default:"" }}</small></h2>
+ <h2>{% trans "Container" %}:
+ {% if subfolders %}
+ <a href="{% url horizon:nova:containers:object_index container_name=container_name %}">{{container_name}}</a>
+ <small>/</small>
+ {% else %}
+ {{container_name}}
+ {% endif %}
+ {% for subfolder, path in subfolders %}
+ <small>
+ {% if not forloop.last %}
+ <a href="{% url horizon:nova:containers:object_index container_name=container_name subfolder_path=path %}">
+ {% endif %}{{ subfolder }}{% if not forloop.last %}</a> /{% endif %}
+ </small>
+ {% endfor %}
+ </h2>
</div>
{% endblock page_header %}
diff --git a/horizon/dashboards/nova/containers/tests.py b/horizon/dashboards/nova/containers/tests.py
index cdafc22f..7e7bbe8d 100644
--- a/horizon/dashboards/nova/containers/tests.py
+++ b/horizon/dashboards/nova/containers/tests.py
@@ -99,8 +99,8 @@ class ContainerViewTests(test.TestCase):
class ObjectViewTests(test.TestCase):
+ @test.create_stubs({api: ('swift_get_objects',)})
def test_index(self):
- self.mox.StubOutWithMock(api, 'swift_get_objects')
ret = (self.objects.list(), False)
api.swift_get_objects(IsA(http.HttpRequest),
self.containers.first().name,
@@ -110,6 +110,32 @@ class ObjectViewTests(test.TestCase):
res = self.client.get(reverse('horizon:nova:containers:object_index',
args=[self.containers.first().name]))
+ self.assertEquals(res.context['container_name'],
+ self.containers.first().name)
+ self.assertTemplateUsed(res, 'nova/containers/detail.html')
+ # UTF8 encoding here to ensure there aren't problems with Nose output.
+ expected = [obj.name.encode('utf8') for obj in self.objects.list()]
+ self.assertQuerysetEqual(res.context['objects_table'].data,
+ expected,
+ lambda obj: obj.name.encode('utf8'))
+
+ @test.create_stubs({api: ('swift_get_objects',)})
+ def test_index_subfolders(self):
+ ret = (self.objects.list(), False)
+ api.swift_get_objects(IsA(http.HttpRequest),
+ self.containers.first().name,
+ marker=None,
+ path='sub1/sub2').AndReturn(ret)
+ self.mox.ReplayAll()
+
+ res = self.client.get(reverse('horizon:nova:containers:object_index',
+ args=[self.containers.first().name,
+ u'sub1/sub2/']))
+ self.assertEquals(res.context['container_name'],
+ self.containers.first().name)
+ self.assertListEqual(res.context['subfolders'],
+ [('sub1', 'sub1/'),
+ ('sub2', 'sub1/sub2/'), ])
self.assertTemplateUsed(res, 'nova/containers/detail.html')
# UTF8 encoding here to ensure there aren't problems with Nose output.
expected = [obj.name.encode('utf8') for obj in self.objects.list()]
diff --git a/horizon/dashboards/nova/containers/views.py b/horizon/dashboards/nova/containers/views.py
index 0f2f4614..91b9aaca 100644
--- a/horizon/dashboards/nova/containers/views.py
+++ b/horizon/dashboards/nova/containers/views.py
@@ -136,7 +136,14 @@ class ObjectIndexView(tables.MixedDataTableView):
def get_context_data(self, **kwargs):
context = super(ObjectIndexView, self).get_context_data(**kwargs)
context['container_name'] = self.kwargs["container_name"]
- context['subfolder_path'] = self.kwargs["subfolder_path"]
+ context['subfolders'] = []
+ if self.kwargs["subfolder_path"]:
+ (parent, slash, folder) = self.kwargs["subfolder_path"].\
+ strip('/').rpartition('/')
+ while folder:
+ path = "%s%s%s/" % (parent, slash, folder)
+ context['subfolders'].insert(0, (folder, path))
+ (parent, slash, folder) = parent.rpartition('/')
return context