Skip to content

Commit

Permalink
Added breadcrumb selector for swift subfolders
Browse files Browse the repository at this point in the history
Fixes bug 1009970

Change-Id: Idd1d0ac31ca132ce09afb49c0e9221997232cfc2
  • Loading branch information
ttrifonov committed Aug 3, 2012
1 parent 2f0678d commit 1275650
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

Expand Down
28 changes: 27 additions & 1 deletion horizon/dashboards/nova/containers/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def test_create_container_post(self):


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,
Expand All @@ -110,6 +110,32 @@ def test_index(self):

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()]
Expand Down
9 changes: 8 additions & 1 deletion horizon/dashboards/nova/containers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,14 @@ def get_subfolders_data(self):
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


Expand Down

0 comments on commit 1275650

Please sign in to comment.