Adding ability to download job binaries

There is now the ability to download job binaries both
from the job binaires table and from the job binaries
description page.

Closes-Bug: #1251288

Change-Id: Ie7dae47f2b682a0093bbfa40457c67eb94d070c7
This commit is contained in:
Chad Roberts 2013-11-14 14:58:56 -05:00
parent bef88b13de
commit 50f8dccbfb
4 changed files with 39 additions and 2 deletions

View File

@ -58,6 +58,13 @@ class DeleteJobBinary(tables.BatchAction):
savanna.job_binaries.delete(obj_id)
class DownloadJobBinary(tables.LinkAction):
name = "download job binary"
verbose_name = _("Download Job Binary")
url = "horizon:savanna:job_binaries:download"
classes = ("btn-edit")
class JobBinariesTable(tables.DataTable):
name = tables.Column("name",
verbose_name=_("Name"),
@ -72,4 +79,4 @@ class JobBinariesTable(tables.DataTable):
verbose_name = _("Job Binaries")
table_actions = (CreateJobBinary,
DeleteJobBinary)
row_actions = (DeleteJobBinary,)
row_actions = (DeleteJobBinary, DownloadJobBinary)

View File

@ -31,4 +31,7 @@ urlpatterns = patterns('',
name='create-job-binary'),
url(r'^(?P<job_binary_id>[^/]+)$',
views.JobBinaryDetailsView.as_view(),
name='details'))
name='details'),
url(r'^(?P<job_binary_id>[^/]+)/download/$',
views.DownloadJobBinaryView.as_view(),
name='download'))

View File

@ -17,8 +17,14 @@
import logging
from django.core.urlresolvers import reverse
from django.core.urlresolvers import reverse_lazy
from django import http
from django.template.defaultfilters import slugify
from django.utils.translation import ugettext_lazy as _
from django.views.generic import View
from horizon import exceptions
from horizon import forms
from horizon import tables
from horizon import tabs
@ -61,3 +67,23 @@ class JobBinaryDetailsView(tabs.TabView):
def get_data(self):
pass
class DownloadJobBinaryView(View):
def get(self, request, job_binary_id=None):
try:
savanna = savannaclient(request)
jb = savanna.job_binaries.get(job_binary_id)
data = savanna.job_binaries.get_file(job_binary_id)
except Exception:
redirect = reverse('horizon:savanna:job_binaries:index')
exceptions.handle(self.request,
_('Unable to fetch job binary: %(exc)s'),
redirect=redirect)
response = http.HttpResponse(mimetype='application/binary')
response['Content-Disposition'] = \
'attachment; filename=%s' % slugify(jb.name)
response.write(data)
response['Content-Length'] = str(len(data))
return response

View File

@ -15,4 +15,5 @@
<dt>{% trans "Create time" %}</dt>
<dd>{{ job_binary.created_at }}</dd>
</dl>
<a href="{% url 'horizon:savanna:job_binaries:download' job_binary.id %}">{% trans "Download Job Binary" %}</a>
</div>