Fix Downloading Package blocks downloading next package

Fix Downloading Package blocks downloading next package,
Use 'tables.LinkAction' instead of 'tables.Action' for
DownloadPackage table action.

Change-Id: I6ca3c628e518cf6e381904f97dd13a1602ba26b9
Closes-Bug: #1579220
(cherry picked from commit 43653f3e50)
This commit is contained in:
zhurong 2016-05-07 07:07:13 -04:00 committed by Kirill Zaitsev
parent ecb1bf7945
commit a57b1be6f5
4 changed files with 30 additions and 27 deletions

View File

@ -13,7 +13,6 @@
# under the License.
from django.core.urlresolvers import reverse
from django import http
from django.template import defaultfilters
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
@ -60,38 +59,17 @@ class PackagesFilterAction(tables.FilterAction):
('name', _("Name"), True))
class DownloadPackage(tables.Action):
class DownloadPackage(tables.LinkAction):
name = 'download_package'
verbose_name = _('Download Package')
url = 'horizon:murano:packages:download'
def allowed(self, request, package):
return True
@staticmethod
def get_package_name(data_table, app_id):
# TODO(tsufiev): should use more optimal search here
name = None
for pkg in data_table.data:
if pkg.id == app_id:
name = defaultfilters.slugify(pkg.name)
break
return name if name is not None else app_id
def single(self, data_table, request, app_id):
try:
body = api.muranoclient(request).packages.download(app_id)
content_type = 'application/octet-stream'
response = http.HttpResponse(body, content_type=content_type)
response['Content-Disposition'] = 'filename={name}.zip'.format(
name=self.get_package_name(data_table, app_id))
return response
except exc.HTTPException:
LOG.exception(_('Something went wrong during package downloading'))
redirect = reverse('horizon:murano:packages:index')
exceptions.handle(request,
_('Unable to download package.'),
redirect=redirect)
def get_link_url(self, app):
app_name = defaultfilters.slugify(app.name)
return reverse(self.url, args=(app_name, app.id))
class ToggleEnabled(tables.BatchAction):

View File

@ -27,4 +27,6 @@ urlpatterns = [
views.ModifyPackageView.as_view(), name='modify'),
urls.url(r'^(?P<app_id>[^/]+)?$',
views.DetailView.as_view(), name='detail'),
urls.url(r'^download/(?P<app_name>[^/]+)/(?P<app_id>[^/]+)?$',
views.download_packge, name='download'),
]

View File

@ -588,3 +588,21 @@ class DetailView(horizon_views.HorizonTemplateView):
_('Unable to retrieve package details.'),
redirect=reverse(INDEX_URL))
return app
def download_packge(request, app_name, app_id):
try:
body = api.muranoclient(request).packages.download(app_id)
content_type = 'application/octet-stream'
response = http.HttpResponse(body, content_type=content_type)
response['Content-Disposition'] = 'filename={name}.zip'.format(
name=app_name)
return response
except exc.HTTPException:
LOG.exception(_('Something went wrong during package downloading'))
redirect = reverse('horizon:murano:packages:index')
exceptions.handle(request,
_('Unable to download package.'),
redirect=redirect)

View File

@ -0,0 +1,5 @@
---
fixes:
- Fix Downloading Package blocks downloading next package.
Use 'tables.LinkAction' instead of 'tables.Action' for
DownloadPackage table action.