Change of path of wrap_delimiter function

openstack_dashboard/dashboards/project/containers/forms.py imports
containers/tables.py just for the 'wrap_delimiter' function.
The wrap_delimiter function has been moved to a new containers/utils.py,
and then imported to both forms and tables.It is done as per the
instructions
specified in the bug.

Co-Authored-By: GB21 <geetika791@gmail.com>
Co-Authored-By: Kamil Rykowski <kamil.rykowski@intel.com>

Closes-bug:1411806
Change-Id: I0bd04b0e2b31fd1bf2235256f6741ea628104680
This commit is contained in:
Geetika Batra 2015-02-20 19:17:46 +05:30 committed by Kamil Rykowski
parent 477faf4c0b
commit 038963cb12
5 changed files with 52 additions and 37 deletions

View File

@ -27,7 +27,7 @@ from horizon import forms
from horizon import messages
from openstack_dashboard import api
from openstack_dashboard.dashboards.project.containers import tables
from openstack_dashboard.dashboards.project.containers import utils
no_slash_validator = validators.RegexValidator(r'^(?u)[^/]+$',
@ -229,10 +229,10 @@ class CopyObject(forms.SelfHandlingForm):
except exceptions.HorizonException as exc:
messages.error(request, exc)
raise exceptions.Http302(
reverse(index, args=[tables.wrap_delimiter(orig_container)]))
reverse(index, args=[utils.wrap_delimiter(orig_container)]))
except Exception:
redirect = reverse(index,
args=[tables.wrap_delimiter(orig_container)])
args=[utils.wrap_delimiter(orig_container)])
exceptions.handle(request,
_("Unable to copy object."),
redirect=redirect)

View File

@ -28,18 +28,13 @@ from horizon.utils.urlresolvers import reverse # noqa
from openstack_dashboard import api
from openstack_dashboard.api import swift
from openstack_dashboard.dashboards.project.containers import utils
LOG = logging.getLogger(__name__)
LOADING_IMAGE = '<img src="/static/dashboard/img/loading.gif" />'
def wrap_delimiter(name):
if name and not name.endswith(swift.FOLDER_DELIMITER):
return name + swift.FOLDER_DELIMITER
return name
class ViewContainer(tables.LinkAction):
name = "view"
verbose_name = _("View Details")
@ -160,7 +155,7 @@ class ListObjects(tables.LinkAction):
def get_link_url(self, datum=None):
container_name = http.urlquote(datum.name)
args = (wrap_delimiter(container_name),)
args = (utils.wrap_delimiter(container_name),)
return reverse(self.url, args=args)
@ -228,7 +223,7 @@ def get_size_used(container):
def get_container_link(container):
return reverse("horizon:project:containers:index",
args=(wrap_delimiter(container.name),))
args=(utils.wrap_delimiter(container.name),))
class ContainerAjaxUpdateRow(tables.Row):
@ -396,7 +391,7 @@ class ObjectFilterAction(tables.FilterAction):
request = table.request
container = self.table.kwargs['container_name']
subfolder = self.table.kwargs['subfolder_path']
prefix = wrap_delimiter(subfolder) if subfolder else ''
prefix = utils.wrap_delimiter(subfolder) if subfolder else ''
self.filtered_data = api.swift.swift_filter_objects(request,
filter_string,
container,
@ -432,8 +427,8 @@ def get_size(obj):
def get_link_subfolder(subfolder):
container_name = subfolder.container_name
return reverse("horizon:project:containers:index",
args=(wrap_delimiter(container_name),
wrap_delimiter(subfolder.name)))
args=(utils.wrap_delimiter(container_name),
utils.wrap_delimiter(subfolder.name)))
class ObjectsTable(tables.DataTable):

View File

@ -27,6 +27,7 @@ from mox import IsA # noqa
from openstack_dashboard import api
from openstack_dashboard.dashboards.project.containers import forms
from openstack_dashboard.dashboards.project.containers import tables
from openstack_dashboard.dashboards.project.containers import utils
from openstack_dashboard.dashboards.project.containers import views
from openstack_dashboard.test import helpers as test
@ -49,7 +50,7 @@ def invalid_paths():
if not INVALID_PATHS:
for x in (CONTAINER_NAME_1_QUOTED, CONTAINER_NAME_2_QUOTED):
y = reverse('horizon:project:containers:index',
args=(tables.wrap_delimiter(x), ))
args=(utils.wrap_delimiter(x), ))
INVALID_PATHS.append(y)
for x in (CONTAINER_NAME_1, CONTAINER_NAME_2):
INVALID_PATHS.append(CONTAINER_INDEX_URL + x)
@ -134,7 +135,7 @@ class SwiftTests(test.TestCase):
'method': forms.CreateContainer.__name__}
res = self.client.post(
reverse('horizon:project:containers:create'), formData)
args = (tables.wrap_delimiter(container.name),)
args = (utils.wrap_delimiter(container.name),)
url = reverse('horizon:project:containers:index', args=args)
self.assertRedirectsNoFollow(res, url)
@ -184,7 +185,7 @@ class SwiftTests(test.TestCase):
container_name = self.containers.first().name
res = self.client.get(
reverse('horizon:project:containers:index',
args=[tables.wrap_delimiter(container_name)]))
args=[utils.wrap_delimiter(container_name)]))
self.assertTemplateUsed(res, 'project/containers/index.html')
# UTF8 encoding here to ensure there aren't problems with Nose output.
expected = [obj.name.encode('utf8') for obj in self.objects.list()]
@ -228,7 +229,7 @@ class SwiftTests(test.TestCase):
'object_file': temp_file}
res = self.client.post(upload_url, formData)
args = (tables.wrap_delimiter(container.name),)
args = (utils.wrap_delimiter(container.name),)
index_url = reverse('horizon:project:containers:index', args=args)
self.assertRedirectsNoFollow(res, index_url)
@ -260,7 +261,7 @@ class SwiftTests(test.TestCase):
'object_file': None}
res = self.client.post(upload_url, formData)
args = (tables.wrap_delimiter(container.name),)
args = (utils.wrap_delimiter(container.name),)
index_url = reverse('horizon:project:containers:index', args=args)
self.assertRedirectsNoFollow(res, index_url)
@ -289,7 +290,7 @@ class SwiftTests(test.TestCase):
res = self.client.post(create_pseudo_folder_url, formData)
index_url = reverse('horizon:project:containers:index',
args=[tables.wrap_delimiter(container.name)])
args=[utils.wrap_delimiter(container.name)])
self.assertRedirectsNoFollow(res, index_url)
@ -297,7 +298,7 @@ class SwiftTests(test.TestCase):
def test_delete(self):
container = self.containers.first()
obj = self.objects.first()
args = (tables.wrap_delimiter(container.name),)
args = (utils.wrap_delimiter(container.name),)
index_url = reverse('horizon:project:containers:index', args=args)
api.swift.swift_delete_object(IsA(http.HttpRequest),
container.name,
@ -316,7 +317,7 @@ class SwiftTests(test.TestCase):
def test_delete_pseudo_folder(self):
container = self.containers.first()
folder = self.folder.first()
args = (tables.wrap_delimiter(container.name),)
args = (utils.wrap_delimiter(container.name),)
index_url = reverse('horizon:project:containers:index', args=args)
api.swift.swift_delete_object(IsA(http.HttpRequest),
container.name,
@ -397,7 +398,7 @@ class SwiftTests(test.TestCase):
copy_url = reverse('horizon:project:containers:object_copy',
args=[container_1.name, obj.name])
res = self.client.post(copy_url, formData)
args = (tables.wrap_delimiter(container_2.name),)
args = (utils.wrap_delimiter(container_2.name),)
index_url = reverse('horizon:project:containers:index', args=args)
self.assertRedirectsNoFollow(res, index_url)
@ -457,7 +458,7 @@ class SwiftTests(test.TestCase):
'object_file': temp_file}
res = self.client.post(update_url, formData)
args = (tables.wrap_delimiter(container.name),)
args = (utils.wrap_delimiter(container.name),)
index_url = reverse('horizon:project:containers:index', args=args)
self.assertRedirectsNoFollow(res, index_url)
@ -481,7 +482,7 @@ class SwiftTests(test.TestCase):
'name': obj.name}
res = self.client.post(update_url, formData)
args = (tables.wrap_delimiter(container.name),)
args = (utils.wrap_delimiter(container.name),)
index_url = reverse('horizon:project:containers:index', args=args)
self.assertRedirectsNoFollow(res, index_url)
@ -533,4 +534,4 @@ class SwiftTests(test.TestCase):
'containerD/objectA': 'containerD/objectA/'
}
for name, expected_name in expected.items():
self.assertEqual(tables.wrap_delimiter(name), expected_name)
self.assertEqual(utils.wrap_delimiter(name), expected_name)

View File

@ -0,0 +1,19 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from openstack_dashboard.api import swift
def wrap_delimiter(name):
if name and not name.endswith(swift.FOLDER_DELIMITER):
return name + swift.FOLDER_DELIMITER
return name

View File

@ -39,7 +39,7 @@ from openstack_dashboard.dashboards.project.containers \
import browsers as project_browsers
from openstack_dashboard.dashboards.project.containers \
import forms as project_forms
from openstack_dashboard.dashboards.project.containers import tables
from openstack_dashboard.dashboards.project.containers import utils
class ContainerView(browsers.ResourceBrowserView):
@ -133,11 +133,11 @@ class CreateView(forms.ModalFormView):
if parent:
container, slash, remainder = parent.partition(
swift.FOLDER_DELIMITER)
args = (tables.wrap_delimiter(container),
tables.wrap_delimiter(remainder))
args = (utils.wrap_delimiter(container),
utils.wrap_delimiter(remainder))
return reverse(self.success_url, args=args)
else:
container = tables.wrap_delimiter(self.request.POST['name'])
container = utils.wrap_delimiter(self.request.POST['name'])
return reverse(self.success_url, args=[container])
def get_initial(self):
@ -155,7 +155,7 @@ class CreatePseudoFolderView(forms.ModalFormView):
def get_success_url(self):
container_name = self.request.POST['container_name']
return reverse(self.success_url,
args=(tables.wrap_delimiter(container_name),
args=(utils.wrap_delimiter(container_name),
self.request.POST.get('path', '')))
def get_initial(self):
@ -176,8 +176,8 @@ class UploadView(forms.ModalFormView):
page_title = _("Upload Objects")
def get_success_url(self):
container = tables.wrap_delimiter(self.request.POST['container_name'])
path = tables.wrap_delimiter(self.request.POST.get('path', ''))
container = utils.wrap_delimiter(self.request.POST['container_name'])
path = utils.wrap_delimiter(self.request.POST.get('path', ''))
args = (container, path)
return reverse(self.success_url, args=args)
@ -220,9 +220,9 @@ class CopyView(forms.ModalFormView):
page_title = _("Copy Object")
def get_success_url(self):
container = tables.wrap_delimiter(
container = utils.wrap_delimiter(
self.request.POST['new_container_name'])
path = tables.wrap_delimiter(self.request.POST.get('path', ''))
path = utils.wrap_delimiter(self.request.POST.get('path', ''))
args = (container, path)
return reverse(self.success_url, args=args)
@ -315,8 +315,8 @@ class UpdateObjectView(forms.ModalFormView):
page_title = _("Update Object")
def get_success_url(self):
container = tables.wrap_delimiter(self.request.POST['container_name'])
path = tables.wrap_delimiter(self.request.POST.get('path', ''))
container = utils.wrap_delimiter(self.request.POST['container_name'])
path = utils.wrap_delimiter(self.request.POST.get('path', ''))
args = (container, path)
return reverse(self.success_url, args=args)