Skip to content

Commit

Permalink
updating image should redirect back to original page
Browse files Browse the repository at this point in the history
 * 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
  • Loading branch information
andycjw committed Mar 25, 2012
1 parent 325414c commit d3abf33
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 4 deletions.
4 changes: 3 additions & 1 deletion horizon/dashboards/nova/images_and_snapshots/images/forms.py
Expand Up @@ -39,6 +39,8 @@


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"),
Expand Down Expand Up @@ -86,7 +88,7 @@ def handle(self, request, data):
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):
Expand Down
Expand Up @@ -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">
Expand Down
30 changes: 30 additions & 0 deletions 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'
2 changes: 2 additions & 0 deletions horizon/dashboards/syspanel/images/tables.py
Expand Up @@ -26,6 +26,8 @@ def allowed(self, request, image=None):


class AdminEditImage(EditImage):
url = "horizon:syspanel:images:update"

def allowed(self, request, image=None):
return True

Expand Down
2 changes: 2 additions & 0 deletions horizon/dashboards/syspanel/images/views.py
Expand Up @@ -27,6 +27,7 @@
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__)
Expand All @@ -48,3 +49,4 @@ def get_data(self):

class UpdateView(views.UpdateView):
template_name = 'syspanel/images/update.html'
form_class = AdminUpdateImageForm
@@ -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 %}
Expand Down
11 changes: 11 additions & 0 deletions horizon/forms/base.py
Expand Up @@ -22,6 +22,7 @@
import logging

from django import forms
from django.core.urlresolvers import reverse
from django.utils import dates

from horizon import exceptions
Expand Down Expand Up @@ -54,6 +55,16 @@ def __init__(self, *args, **kwargs):
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. """
Expand Down

0 comments on commit d3abf33

Please sign in to comment.