# vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2013 Hewlett-Packard Development Company, L.P. # # 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. from django.utils.html import escape from django.utils.html import format_html from django.utils.translation import ugettext_lazy as _ # noqa from horizon import exceptions from horizon import forms from horizon import messages from monitoring import api from monitoring import constants class NotificationTableWidget(forms.Widget): FIELD_ID_IDX = 0 FIELD_NAME_IDX = 1 def __init__(self, *args, **kwargs): self.fields = kwargs.pop('fields') super(NotificationTableWidget, self).__init__(*args, **kwargs) def render(self, name, value, attrs): output = '' for field in self.fields: output += '' % unicode(field[self.FIELD_NAME_IDX]) output += '' if value: for notification in value: output += "" for field in self.fields: field_value = notification[field[self.FIELD_ID_IDX]] output += '' % escape(field_value) output += "" output += '
%s
%s
' return format_html(output) class NotificationField(forms.MultiValueField): def __init__(self, *args, **kwargs): super(NotificationField, self).__init__(*args, **kwargs) def _get_choices(self): return self._choices def _set_choices(self, value): # Setting choices also sets the choices on the widget. # choices can be any iterable, but we call list() on it because # it will be consumed more than once. self._choices = self.widget.choices = list(value) choices = property(_get_choices, _set_choices) def compress(self, data_list): return data_list def clean(self, value): return value class NotificationCreateWidget(forms.Select): def __init__(self, *args, **kwargs): super(NotificationCreateWidget, self).__init__(*args, **kwargs) def render(self, name, value, attrs=None, choices=()): output = '' output += '' % \ unicode(_("Name")) if value: idx = 1 for notification in value: output += '' idx += 1 else: output += '
%s
' output += ('' output += '
' output += '