updating image should redirect back to original page

* fix bug 960448
 * syspanel inherits nova UpdateImage view/form
 * add completion_view to form base object, and get_success_url()
   that reverse the proper url for redirection on success
   handling
 * syspanel AdminEditImage was pointless because it didn't
   override the 'url', now fixed

Change-Id: Ia8f24c7a895b397f11978a59232ab00da3e8813d
This commit is contained in:
Andy Chong 2012-03-21 12:02:33 +08:00
parent 325414ccb1
commit d3abf336ee
7 changed files with 51 additions and 4 deletions

View File

@ -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):

View File

@ -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 %}
<div class="left">

View File

@ -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'

View File

@ -26,6 +26,8 @@ class AdminDeleteImage(DeleteImage):
class AdminEditImage(EditImage):
url = "horizon:syspanel:images:update"
def allowed(self, request, image=None):
return True

View File

@ -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

View File

@ -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 %}

View File

@ -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. """