Merge "updating image should redirect back to original page"

This commit is contained in:
Jenkins 2012-03-27 22:17:57 +00:00 committed by Gerrit Code Review
commit afd16018e6
7 changed files with 51 additions and 4 deletions

View File

@ -39,6 +39,8 @@ LOG = logging.getLogger(__name__)
class UpdateImageForm(forms.SelfHandlingForm): class UpdateImageForm(forms.SelfHandlingForm):
completion_view = 'horizon:nova:images_and_snapshots:index'
image_id = forms.CharField(widget=forms.HiddenInput()) image_id = forms.CharField(widget=forms.HiddenInput())
name = forms.CharField(max_length="255", label=_("Name")) name = forms.CharField(max_length="255", label=_("Name"))
kernel = forms.CharField(max_length="36", label=_("Kernel ID"), kernel = forms.CharField(max_length="36", label=_("Kernel ID"),
@ -86,7 +88,7 @@ class UpdateImageForm(forms.SelfHandlingForm):
messages.success(request, _('Image was successfully updated.')) messages.success(request, _('Image was successfully updated.'))
except: except:
exceptions.handle(request, error_updating % image_id) 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): class LaunchForm(forms.SelfHandlingForm):

View File

@ -4,7 +4,7 @@
{% block form_id %}update_image_form{% endblock %} {% block form_id %}update_image_form{% endblock %}
{% block form_action %}{% url horizon:nova:images_and_snapshots:images:update image.id %}{% 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 %} {% block modal-body %}
<div class="left"> <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): class AdminEditImage(EditImage):
url = "horizon:syspanel:images:update"
def allowed(self, request, image=None): def allowed(self, request, image=None):
return True return True

View File

@ -27,6 +27,7 @@ from horizon import exceptions
from horizon import tables from horizon import tables
from horizon.dashboards.nova.images_and_snapshots.images import views from horizon.dashboards.nova.images_and_snapshots.images import views
from .tables import AdminImagesTable from .tables import AdminImagesTable
from .forms import AdminUpdateImageForm
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -48,3 +49,4 @@ class IndexView(tables.DataTableView):
class UpdateView(views.UpdateView): class UpdateView(views.UpdateView):
template_name = 'syspanel/images/update.html' template_name = 'syspanel/images/update.html'
form_class = AdminUpdateImageForm

View File

@ -1,8 +1,8 @@
{% extends "horizon/common/_modal_form.html" %} {% extends "horizon/common/_modal_form.html" %}
{% load i18n %} {% load i18n %}
{% block form_id %}udate_image_form{% endblock %} {% block form_id %}update_image_form{% endblock %}
{% block form_action %}{% url horizon:syspanel:images:update %}{% endblock %} {% block form_action %}{% url horizon:syspanel:images:update image.id %}{% endblock %}
{% block modal_id %}update_image_modal{% endblock %} {% block modal_id %}update_image_modal{% endblock %}
{% block modal-header %}{% trans "Update Image" %}{% endblock %} {% block modal-header %}{% trans "Update Image" %}{% endblock %}

View File

@ -22,6 +22,7 @@ from datetime import date
import logging import logging
from django import forms from django import forms
from django.core.urlresolvers import reverse
from django.utils import dates from django.utils import dates
from horizon import exceptions from horizon import exceptions
@ -54,6 +55,16 @@ class SelfHandlingForm(forms.Form):
kwargs['initial'] = initial kwargs['initial'] = initial
super(SelfHandlingForm, self).__init__(*args, **kwargs) 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 @classmethod
def _instantiate(cls, request, *args, **kwargs): def _instantiate(cls, request, *args, **kwargs):
""" Instantiates the form. Allows customization in subclasses. """ """ Instantiates the form. Allows customization in subclasses. """