Use new style form templates
This patch addresses two bugs by updating to the new style form template. By using the new style form the standard horizon common form is used for the footer and fixes the issue where the cancel button has the wrong font size. It also fixes the gate issue where there was a failing test due to the url not being accessible. Updating to the new style form with the url as a view attribute fixes that issue. Added code in the views to populate the new standard form attributes. Removed the code in the old style form templates and used the new style. Removed some unneeded icon attributes in the grow/shrink table actions. Added some code to suppress the output of expected exceptions in the tests. Change-Id: If04f24d46c251079bcbe232b94eaee4f30c73ed3 Closes-Bug: #1566506 Closes-Bug: #1568876
This commit is contained in:
@@ -76,7 +76,6 @@ class ClusterGrow(tables.LinkAction):
|
||||
name = "cluster_grow"
|
||||
verbose_name = _("Grow Cluster")
|
||||
url = "horizon:project:database_clusters:cluster_grow_details"
|
||||
icon = "plus"
|
||||
|
||||
def allowed(self, request, cluster=None):
|
||||
if (cluster and cluster.task["name"] == 'NONE' and
|
||||
@@ -89,8 +88,6 @@ class ClusterShrink(tables.LinkAction):
|
||||
name = "cluster_shrink"
|
||||
verbose_name = _("Shrink Cluster")
|
||||
url = "horizon:project:database_clusters:cluster_shrink_details"
|
||||
classes = ("btn-danger",)
|
||||
icon = "remove"
|
||||
|
||||
def allowed(self, request, cluster=None):
|
||||
if (cluster and cluster.task["name"] == 'NONE' and
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
{% extends "horizon/common/_modal_form.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block form_id %}launch_form{% endblock %}
|
||||
{% block form_action %}{% url "horizon:project:database_clusters:launch" %}{% endblock %}
|
||||
|
||||
{% block modal_id %}launch_modal{% endblock %}
|
||||
{% block modal-header %}{% trans "Launch Cluster" %}{% endblock %}
|
||||
|
||||
{% block modal-body %}
|
||||
<div class="center">
|
||||
@@ -14,8 +7,3 @@
|
||||
</fieldset>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block modal-footer %}
|
||||
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Launch" %}" />
|
||||
<a href="{% url "horizon:project:database_clusters:index" %}" class="btn btn-default secondary cancel close">{% trans "Cancel" %}</a>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Launch Cluster" %}{% endblock %}
|
||||
|
||||
{% block page_header %}
|
||||
{% include "horizon/common/_page_header.html" with title=_("Launch Cluster") %}
|
||||
{% endblock page_header %}
|
||||
|
||||
{% block main %}
|
||||
{% include 'project/database_clusters/_launch.html' %}
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django import http
|
||||
|
||||
@@ -489,12 +491,27 @@ class ClustersTests(test.TestCase):
|
||||
self.assertTemplateUsed(
|
||||
res, 'project/database_clusters/cluster_grow_details.html')
|
||||
|
||||
action = "".join([tables.ClusterGrowInstancesTable.Meta.name, '__',
|
||||
tables.ClusterGrowAction.name, '__',
|
||||
cluster.id])
|
||||
res = self.client.post(url, {'action': action})
|
||||
self.assertMessageCount(error=1)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
toSuppress = ["trove_dashboard.content.database_clusters.tables"]
|
||||
|
||||
# Suppress expected log messages in the test output
|
||||
loggers = []
|
||||
for cls in toSuppress:
|
||||
logger = logging.getLogger(cls)
|
||||
loggers.append((logger, logger.getEffectiveLevel()))
|
||||
logger.setLevel(logging.CRITICAL)
|
||||
|
||||
try:
|
||||
action = "".join([tables.ClusterGrowInstancesTable.Meta.name, '__',
|
||||
tables.ClusterGrowAction.name, '__',
|
||||
cluster.id])
|
||||
res = self.client.post(url, {'action': action})
|
||||
|
||||
self.assertMessageCount(error=1)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
finally:
|
||||
# Restore the previous log levels
|
||||
for (log, level) in loggers:
|
||||
log.setLevel(level)
|
||||
|
||||
@test.create_stubs({trove_api.trove: ('cluster_get',
|
||||
'cluster_shrink')})
|
||||
@@ -547,9 +564,24 @@ class ClustersTests(test.TestCase):
|
||||
action = "".join([tables.ClusterShrinkInstancesTable.Meta.name, '__',
|
||||
tables.ClusterShrinkAction.name, '__',
|
||||
cluster_id])
|
||||
res = self.client.post(url, {'action': action})
|
||||
self.assertMessageCount(error=1)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
toSuppress = ["trove_dashboard.content.database_clusters.tables"]
|
||||
|
||||
# Suppress expected log messages in the test output
|
||||
loggers = []
|
||||
for cls in toSuppress:
|
||||
logger = logging.getLogger(cls)
|
||||
loggers.append((logger, logger.getEffectiveLevel()))
|
||||
logger.setLevel(logging.CRITICAL)
|
||||
|
||||
try:
|
||||
res = self.client.post(url, {'action': action})
|
||||
self.assertMessageCount(error=1)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
finally:
|
||||
# Restore the previous log levels
|
||||
for (log, level) in loggers:
|
||||
log.setLevel(level)
|
||||
|
||||
def _get_filtered_datastores(self, datastore):
|
||||
filtered_datastore = []
|
||||
|
||||
@@ -93,7 +93,12 @@ class IndexView(horizon_tables.DataTableView):
|
||||
|
||||
class LaunchClusterView(horizon_forms.ModalFormView):
|
||||
form_class = forms.LaunchForm
|
||||
form_id = "launch_form"
|
||||
modal_header = _("Launch Cluster")
|
||||
modal_id = "launch_modal"
|
||||
template_name = 'project/database_clusters/launch.html'
|
||||
submit_label = _("Launch")
|
||||
submit_url = reverse_lazy('horizon:project:database_clusters:launch')
|
||||
success_url = reverse_lazy('horizon:project:database_clusters:index')
|
||||
|
||||
|
||||
|
||||
@@ -60,6 +60,14 @@ class ResizeVolumeForm(forms.SelfHandlingForm):
|
||||
)
|
||||
new_size = forms.IntegerField(label=_("New Size (GB)"))
|
||||
|
||||
def __init__(self, request, *args, **kwargs):
|
||||
super(ResizeVolumeForm, self).__init__(request, *args, **kwargs)
|
||||
|
||||
self.fields['instance_id'].initial = (kwargs.get('initial', {}).
|
||||
get('instance_id'))
|
||||
self.fields['orig_size'].initial = (kwargs.get('initial', {}).
|
||||
get('orig_size'))
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super(ResizeVolumeForm, self).clean()
|
||||
new_size = cleaned_data.get('new_size')
|
||||
|
||||
@@ -1,25 +1,6 @@
|
||||
{% extends "horizon/common/_modal_form.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block form_id %}resize_instance_form{% endblock %}
|
||||
{% block form_action %}{% url "horizon:project:databases:resize_instance" instance_id %}{% endblock %}
|
||||
|
||||
{% block modal_id %}resize_instance_modal{% endblock %}
|
||||
{% block modal-header %}{% trans "Resize Database Instance" %}{% endblock %}
|
||||
|
||||
{% block modal-body %}
|
||||
<div class="left">
|
||||
<fieldset>
|
||||
{% include "horizon/common/_form_fields.html" %}
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="right">
|
||||
<p>{% blocktrans %}Specify a new flavor for the database instance.{% endblocktrans %}</p>
|
||||
</div>
|
||||
{% block modal-body-right %}
|
||||
<p>{% trans "Specify a new flavor for the database instance." %}</p>
|
||||
{% endblock %}
|
||||
|
||||
{% block modal-footer %}
|
||||
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Resize Database Instance" %}" />
|
||||
<a href="{% url "horizon:project:databases:index" %}" class="btn btn-default secondary cancel close">{% trans "Cancel" %}</a>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
@@ -1,26 +1,7 @@
|
||||
{% extends "horizon/common/_modal_form.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block form_id %}resize_volume_form{% endblock %}
|
||||
{% block form_action %}{% url "horizon:project:databases:resize_volume" instance_id %}{% endblock %}
|
||||
|
||||
{% block modal_id %}resize_volume_modal{% endblock %}
|
||||
{% block modal-header %}{% trans "Resize Database Volume" %}{% endblock %}
|
||||
|
||||
{% block modal-body %}
|
||||
<div class="left">
|
||||
<fieldset>
|
||||
{% include "horizon/common/_form_fields.html" %}
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="right">
|
||||
<p>{% blocktrans %}Specify the new volume size for the database instance.{% endblocktrans %}</p>
|
||||
<p>{% blocktrans %}<strong>Please note:</strong> The new value must be greater than the existing volume size.{% endblocktrans %}</p>
|
||||
</div>
|
||||
{% block modal-body-right %}
|
||||
<p>{% trans "Specify the new volume size for the database instance." %}</p>
|
||||
<p><strong>{% trans "Please note:</strong> The new value must be greater than the existing volume size." %}</strong></p>
|
||||
{% endblock %}
|
||||
|
||||
{% block modal-footer %}
|
||||
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Resize Database Volume" %}" />
|
||||
<a href="{% url "horizon:project:databases:index" %}" class="btn btn-default secondary cancel close">{% trans "Cancel" %}</a>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Resize Database Instance" %}{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
{% include "project/databases/_resize_instance.html" %}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Resize Database Volume" %}{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
{% include "project/databases/_resize_volume.html" %}
|
||||
|
||||
@@ -276,7 +276,12 @@ class CreateDatabaseView(horizon_forms.ModalFormView):
|
||||
|
||||
class ResizeVolumeView(horizon_forms.ModalFormView):
|
||||
form_class = forms.ResizeVolumeForm
|
||||
form_id = "resize_volume_form"
|
||||
modal_header = _("Resize Database Volume")
|
||||
modal_id = "resize_volume_modal"
|
||||
template_name = 'project/databases/resize_volume.html'
|
||||
submit_label = "Resize Database Volume"
|
||||
submit_url = 'horizon:project:databases:resize_volume'
|
||||
success_url = reverse_lazy('horizon:project:databases:index')
|
||||
page_title = _("Resize Database Volume")
|
||||
|
||||
@@ -293,6 +298,8 @@ class ResizeVolumeView(horizon_forms.ModalFormView):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(ResizeVolumeView, self).get_context_data(**kwargs)
|
||||
context['instance_id'] = self.kwargs['instance_id']
|
||||
args = (self.kwargs['instance_id'],)
|
||||
context['submit_url'] = reverse(self.submit_url, args=args)
|
||||
return context
|
||||
|
||||
def get_initial(self):
|
||||
@@ -303,7 +310,12 @@ class ResizeVolumeView(horizon_forms.ModalFormView):
|
||||
|
||||
class ResizeInstanceView(horizon_forms.ModalFormView):
|
||||
form_class = forms.ResizeInstanceForm
|
||||
form_id = "resize_instance_form"
|
||||
modal_header = _("Resize Database Instance")
|
||||
modal_id = "resize_instance_modal"
|
||||
template_name = 'project/databases/resize_instance.html'
|
||||
submit_label = "Resize Database Instance"
|
||||
submit_url = 'horizon:project:databases:resize_instance'
|
||||
success_url = reverse_lazy('horizon:project:databases:index')
|
||||
page_title = _("Resize Database Instance")
|
||||
|
||||
@@ -332,6 +344,8 @@ class ResizeInstanceView(horizon_forms.ModalFormView):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(ResizeInstanceView, self).get_context_data(**kwargs)
|
||||
context['instance_id'] = self.kwargs['instance_id']
|
||||
args = (self.kwargs['instance_id'],)
|
||||
context['submit_url'] = reverse(self.submit_url, args=args)
|
||||
return context
|
||||
|
||||
@memoized.memoized_method
|
||||
|
||||
Reference in New Issue
Block a user