Fix monasca-ui forms
Fix problem with unexpected keyword argument 'name' for build_attrs() from Django. 'name' was passed to the method as a kwargs. **kwargs in build_attrs() were removed. Pass 'name' in a dict. In Django 1.10+ passing Context to render is deprecated and gives an error, pass instead a dict. Remove one assertContains from alarm definition create. Tags in <input> where generated in random order every time the gates run: <input type="text" name="name" id="id_name" required maxlength="250" class="form-control" /> <input type="text" name="name" id="id_name" required class="form-control" maxlength="250" /> <input type="text" name="name" class="form-control" id="id_name" maxlength="250" required /> Change-Id: I2d39a10f08ac60c163f80cca3256a2bb24b4e0a2 Story: 2001133 Task: 4844
This commit is contained in:
parent
9dc87decbf
commit
57ddc80d05
|
@ -1,4 +1,5 @@
|
|||
# Copyright 2013 Hewlett-Packard Development Company, L.P.
|
||||
# Copyright 2017 FUJITSU LIMITED
|
||||
#
|
||||
# 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
|
||||
|
@ -16,7 +17,6 @@ import json
|
|||
from itertools import chain
|
||||
|
||||
from django.template.loader import get_template
|
||||
from django.template import Context
|
||||
from django.utils.translation import ugettext as _ # noqa
|
||||
|
||||
from horizon import exceptions
|
||||
|
@ -34,11 +34,7 @@ def _get_metrics(request):
|
|||
|
||||
def _get_notifications(request):
|
||||
notifications = api.monitor.notification_list(request)
|
||||
return [(notification['id'],
|
||||
notification['name'],
|
||||
notification['type'],
|
||||
notification['address'])
|
||||
for notification in notifications]
|
||||
return [(notification['id'], notification) for notification in notifications]
|
||||
|
||||
|
||||
class ExpressionWidget(forms.Widget):
|
||||
|
@ -54,7 +50,7 @@ class ExpressionWidget(forms.Widget):
|
|||
self.initial = initial
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
final_attrs = self.build_attrs(attrs, name=name)
|
||||
final_attrs = self.build_attrs(attrs, {'name': name})
|
||||
t = get_template(constants.TEMPLATE_PREFIX + 'expression_field.html')
|
||||
|
||||
local_attrs = {
|
||||
|
@ -65,8 +61,7 @@ class ExpressionWidget(forms.Widget):
|
|||
}
|
||||
|
||||
local_attrs.update(final_attrs)
|
||||
|
||||
return t.render(Context(local_attrs))
|
||||
return t.render(local_attrs)
|
||||
|
||||
|
||||
class ExpressionField(forms.CharField):
|
||||
|
@ -86,13 +81,12 @@ class MatchByWidget(forms.Widget):
|
|||
self.initial = initial
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
final_attrs = self.build_attrs(attrs, name=name)
|
||||
final_attrs = self.build_attrs(attrs, {'name': name})
|
||||
t = get_template(constants.TEMPLATE_PREFIX + 'match_by_field.html')
|
||||
|
||||
local_attrs = {'service': ''}
|
||||
local_attrs.update(final_attrs)
|
||||
context = Context(local_attrs)
|
||||
return t.render(context)
|
||||
return t.render(local_attrs)
|
||||
|
||||
|
||||
class NotificationField(forms.MultiValueField):
|
||||
|
@ -122,7 +116,7 @@ class NotificationCreateWidget(forms.Select):
|
|||
super(NotificationCreateWidget, self).__init__(*args, **kwargs)
|
||||
|
||||
def render(self, name, value, attrs=None, choices=()):
|
||||
final_attrs = self.build_attrs(attrs, name=name)
|
||||
final_attrs = self.build_attrs(attrs, {'name': name})
|
||||
tpl = get_template(constants.TEMPLATE_PREFIX + 'notification_field.html')
|
||||
|
||||
selected = {}
|
||||
|
@ -131,17 +125,22 @@ class NotificationCreateWidget(forms.Select):
|
|||
'ok': item['ok'],
|
||||
'undetermined': item['undetermined']}
|
||||
data = []
|
||||
for id, label, type, address in chain(self.choices, choices):
|
||||
if id in selected:
|
||||
actions = selected[id]
|
||||
data.append((id, label, type, address, actions['alarm'],
|
||||
|
||||
for pk, notification in chain(self.choices, choices):
|
||||
nt_label = notification['name']
|
||||
nt_address = notification['address']
|
||||
nt_type = notification['type']
|
||||
|
||||
if pk in selected:
|
||||
actions = selected[pk]
|
||||
data.append((pk, nt_label, nt_type, nt_address, actions['alarm'],
|
||||
actions['ok'], actions['undetermined'], True))
|
||||
else:
|
||||
data.append((id, label, type, address, True, True, True, False))
|
||||
data.append((pk, nt_label, nt_type, nt_address, True, True, True, False))
|
||||
|
||||
local_attrs = {'data': json.dumps(data)}
|
||||
local_attrs.update(final_attrs)
|
||||
return tpl.render(Context(local_attrs))
|
||||
return tpl.render(local_attrs)
|
||||
|
||||
def value_from_datadict(self, data, files, name):
|
||||
return [{"id": _id} for _id in data.getlist(name)]
|
||||
|
@ -229,11 +228,7 @@ class EditAlarmForm(forms.SelfHandlingForm):
|
|||
notifications = []
|
||||
exceptions.handle(request,
|
||||
_('Unable to retrieve notifications: %s') % e)
|
||||
notification_choices = [(notification['id'],
|
||||
notification['name'],
|
||||
notification['type'],
|
||||
notification['address'])
|
||||
for notification in notifications]
|
||||
notification_choices = [(notification['id'], notification) for notification in notifications]
|
||||
|
||||
self.fields['notifications'].choices = notification_choices
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright 2013 Hewlett-Packard Development Company, L.P.
|
||||
# Copyright 2016 FUJITSU LIMITED
|
||||
# Copyright 2016-2017 FUJITSU LIMITED
|
||||
#
|
||||
# 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
|
||||
|
@ -76,9 +76,8 @@ class AlarmDefinitionsTest(helpers.TestCase):
|
|||
step = workflow.get_step('setalarmnotificationsaction')
|
||||
self.assertIsNotNone(step)
|
||||
|
||||
self.assertContains(res, '<input class="form-control" id="id_name"')
|
||||
self.assertContains(res, '<input class="form-control" '
|
||||
'id="id_description"')
|
||||
self.assertContains(res, '<input type="text" name="description" '
|
||||
'id="id_description" class="form-control" />')
|
||||
self.assertContains(res, '<select class="form-control" '
|
||||
'id="id_severity"')
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# Copyright 2013 Hewlett-Packard Development Company, L.P.
|
||||
# Copyright 2017 FUJITSU LIMITED
|
||||
#
|
||||
# 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
|
||||
|
@ -16,7 +17,6 @@ import re
|
|||
|
||||
from django import forms as django_forms
|
||||
from django.template.loader import get_template
|
||||
from django.template import Context
|
||||
from django.utils import html
|
||||
from django.utils.translation import ugettext_lazy as _ # noqa
|
||||
|
||||
|
@ -34,7 +34,7 @@ class ExpressionWidget(forms.Widget):
|
|||
self.initial = initial
|
||||
|
||||
def render(self, name, value, attrs):
|
||||
final_attrs = self.build_attrs(attrs, name=name)
|
||||
final_attrs = self.build_attrs(attrs, {'name': name})
|
||||
if value:
|
||||
dim = value
|
||||
else:
|
||||
|
@ -45,8 +45,8 @@ class ExpressionWidget(forms.Widget):
|
|||
t = get_template(constants.TEMPLATE_PREFIX + 'expression_field.html')
|
||||
local_attrs = {'service': dim}
|
||||
local_attrs.update(final_attrs)
|
||||
context = Context(local_attrs)
|
||||
return t.render(context)
|
||||
|
||||
return t.render(local_attrs)
|
||||
|
||||
|
||||
class SimpleExpressionWidget(django_forms.MultiWidget):
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
# of appearance. Changing the order has an impact on the overall integration
|
||||
# process, which may cause wedges in the gate later.
|
||||
python-monascaclient>=1.1.0 # Apache-2.0
|
||||
Django<1.11,>=1.8 # BSD
|
||||
Django<2.0,>=1.8 # BSD
|
||||
|
|
Loading…
Reference in New Issue