diff --git a/horizon/dashboards/nova/images_and_snapshots/images/forms.py b/horizon/dashboards/nova/images_and_snapshots/images/forms.py index 7ab12e1b3..319ceb54b 100644 --- a/horizon/dashboards/nova/images_and_snapshots/images/forms.py +++ b/horizon/dashboards/nova/images_and_snapshots/images/forms.py @@ -39,6 +39,8 @@ LOG = logging.getLogger(__name__) class UpdateImageForm(forms.SelfHandlingForm): + completion_view = 'horizon:nova:images_and_snapshots:index' + image_id = forms.CharField(widget=forms.HiddenInput()) name = forms.CharField(max_length="255", label=_("Name")) kernel = forms.CharField(max_length="36", label=_("Kernel ID"), @@ -86,7 +88,7 @@ class UpdateImageForm(forms.SelfHandlingForm): messages.success(request, _('Image was successfully updated.')) except: exceptions.handle(request, error_updating % image_id) - return shortcuts.redirect('horizon:nova:images_and_snapshots:index') + return shortcuts.redirect(self.get_success_url()) class LaunchForm(forms.SelfHandlingForm): diff --git a/horizon/dashboards/nova/templates/nova/images_and_snapshots/images/_update.html b/horizon/dashboards/nova/templates/nova/images_and_snapshots/images/_update.html index eee6bb941..5b001d08a 100644 --- a/horizon/dashboards/nova/templates/nova/images_and_snapshots/images/_update.html +++ b/horizon/dashboards/nova/templates/nova/images_and_snapshots/images/_update.html @@ -4,7 +4,7 @@ {% block form_id %}update_image_form{% endblock %} {% block form_action %}{% url horizon:nova:images_and_snapshots:images:update image.id %}{% endblock %} -{% block modal-header %}Update Image{% endblock %} +{% block modal-header %}{% trans "Update Image" %}{% endblock %} {% block modal-body %}
diff --git a/horizon/dashboards/syspanel/images/forms.py b/horizon/dashboards/syspanel/images/forms.py new file mode 100644 index 000000000..4064959e0 --- /dev/null +++ b/horizon/dashboards/syspanel/images/forms.py @@ -0,0 +1,30 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2012 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# All Rights Reserved. +# +# Copyright 2012 Nebula, Inc. +# +# 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. + +import logging + +from horizon.dashboards.nova.images_and_snapshots.images import forms + + +LOG = logging.getLogger(__name__) + + +class AdminUpdateImageForm(forms.UpdateImageForm): + completion_view = 'horizon:syspanel:images:index' diff --git a/horizon/dashboards/syspanel/images/tables.py b/horizon/dashboards/syspanel/images/tables.py index d4cfe2100..d7f22c481 100644 --- a/horizon/dashboards/syspanel/images/tables.py +++ b/horizon/dashboards/syspanel/images/tables.py @@ -26,6 +26,8 @@ class AdminDeleteImage(DeleteImage): class AdminEditImage(EditImage): + url = "horizon:syspanel:images:update" + def allowed(self, request, image=None): return True diff --git a/horizon/dashboards/syspanel/images/views.py b/horizon/dashboards/syspanel/images/views.py index bf422ad7d..d4821c52c 100644 --- a/horizon/dashboards/syspanel/images/views.py +++ b/horizon/dashboards/syspanel/images/views.py @@ -27,6 +27,7 @@ from horizon import exceptions from horizon import tables from horizon.dashboards.nova.images_and_snapshots.images import views from .tables import AdminImagesTable +from .forms import AdminUpdateImageForm LOG = logging.getLogger(__name__) @@ -48,3 +49,4 @@ class IndexView(tables.DataTableView): class UpdateView(views.UpdateView): template_name = 'syspanel/images/update.html' + form_class = AdminUpdateImageForm diff --git a/horizon/dashboards/syspanel/templates/syspanel/images/_update.html b/horizon/dashboards/syspanel/templates/syspanel/images/_update.html index 49d63b431..80e661c29 100644 --- a/horizon/dashboards/syspanel/templates/syspanel/images/_update.html +++ b/horizon/dashboards/syspanel/templates/syspanel/images/_update.html @@ -1,8 +1,8 @@ {% extends "horizon/common/_modal_form.html" %} {% load i18n %} -{% block form_id %}udate_image_form{% endblock %} -{% block form_action %}{% url horizon:syspanel:images:update %}{% endblock %} +{% block form_id %}update_image_form{% endblock %} +{% block form_action %}{% url horizon:syspanel:images:update image.id %}{% endblock %} {% block modal_id %}update_image_modal{% endblock %} {% block modal-header %}{% trans "Update Image" %}{% endblock %} diff --git a/horizon/forms/base.py b/horizon/forms/base.py index d48e8f278..faec9af94 100644 --- a/horizon/forms/base.py +++ b/horizon/forms/base.py @@ -22,6 +22,7 @@ from datetime import date import logging from django import forms +from django.core.urlresolvers import reverse from django.utils import dates from horizon import exceptions @@ -54,6 +55,16 @@ class SelfHandlingForm(forms.Form): kwargs['initial'] = initial super(SelfHandlingForm, self).__init__(*args, **kwargs) + def get_success_url(self, request=None): + """ + Returns the URL to redirect to after a successful handling. + """ + if self.completion_view: + return reverse(self.completion_view) + if self.completion_url: + return self.completion_url + return request.get_full_path() + @classmethod def _instantiate(cls, request, *args, **kwargs): """ Instantiates the form. Allows customization in subclasses. """