diff --git a/horizon/horizon/dashboards/nova/keypairs/forms.py b/horizon/horizon/dashboards/nova/keypairs/forms.py index 1d1b5fdf9a2..bf559bbd35f 100644 --- a/horizon/horizon/dashboards/nova/keypairs/forms.py +++ b/horizon/horizon/dashboards/nova/keypairs/forms.py @@ -24,6 +24,7 @@ from django import shortcuts from django.contrib import messages from django.core import validators +from django.template.defaultfilters import slugify from django.utils.http import urlquote from django.utils.translation import ugettext as _ from novaclient import exceptions as novaclient_exceptions @@ -53,8 +54,12 @@ def handle(self, request, data): class CreateKeypair(forms.SelfHandlingForm): - name = forms.CharField(max_length="20", label=_("Keypair Name"), - validators=[validators.RegexValidator('\w+')]) + name = forms.CharField(max_length="20", + label=_("Keypair Name"), + validators=[validators.validate_slug], + error_messages={'invalid': _('Keypair names may ' + 'only contain letters, numbers, underscores ' + 'and hyphens.')}) def handle(self, request, data): try: @@ -62,8 +67,9 @@ def handle(self, request, data): keypair = api.keypair_create(request, data['name']) response = http.HttpResponse(mimetype='application/binary') response['Content-Disposition'] = \ - 'attachment; filename=%s.pem' % keypair.name + 'attachment; filename=%s.pem' % slugify(keypair.name) response.write(keypair.private_key) + response['Content-Length'] = str(len(response.content)) return response except novaclient_exceptions.ClientException, e: LOG.exception("ClientException in CreateKeyPair") diff --git a/horizon/horizon/dashboards/nova/templates/nova/keypairs/_delete.html b/horizon/horizon/dashboards/nova/templates/nova/keypairs/_delete.html index 17d447d107f..1471254ecac 100644 --- a/horizon/horizon/dashboards/nova/templates/nova/keypairs/_delete.html +++ b/horizon/horizon/dashboards/nova/templates/nova/keypairs/_delete.html @@ -5,5 +5,5 @@ {{hidden}} {% endfor %} - + diff --git a/openstack-dashboard/dashboard/static/dashboard/js/application.js b/openstack-dashboard/dashboard/static/dashboard/js/application.js index f57e802ccf3..f330142b0f9 100644 --- a/openstack-dashboard/dashboard/static/dashboard/js/application.js +++ b/openstack-dashboard/dashboard/static/dashboard/js/application.js @@ -127,7 +127,7 @@ $(function(){ $(document).on("submit", ".modal #create_keypair_form", function(e){ var $this = $(this); $this.closest(".modal").modal("hide"); - $('#main_content').prepend('
' + $('#main_content .page-header').after('
' + '

Info: The data on this page may have changed, ' + 'click here to refresh it.

' + '
');