Resolve all pep8 issues
This commit is contained in:
parent
125ee4b768
commit
1afb03ff0f
@ -15,8 +15,7 @@
|
||||
# under the License.
|
||||
|
||||
from django import forms as django_forms
|
||||
from django.utils.html import escape
|
||||
from django.utils.html import format_html
|
||||
from django.utils import html
|
||||
from django.utils.translation import ugettext_lazy as _ # noqa
|
||||
|
||||
from horizon import exceptions
|
||||
@ -42,14 +41,19 @@ class ExpressionWidget(forms.Widget):
|
||||
output = '''
|
||||
<div ng-controller="alarmEditController" ng-init="init('%(service)s')">
|
||||
<input type="hidden" name="%(name)s" id="dimension"/>
|
||||
<select id="metric-chooser" ng-model="currentMetric" ng-options="metric.name for metric in metrics | orderBy:'name'" ng-change="metricChanged()"></select>
|
||||
<tags-input id="dimension-chooser" ng-model="tags" placeholder="%(placeholder)s" add-from-autocomplete-only="true" max-results-to-show="20" on-tag-added="saveDimension()" on-tag-removed="saveDimension()">
|
||||
<select id="metric-chooser" ng-model="currentMetric"
|
||||
ng-options="metric.name for metric in metrics | orderBy:'name'"
|
||||
ng-change="metricChanged()"></select>
|
||||
<tags-input id="dimension-chooser" ng-model="tags"
|
||||
placeholder="%(placeholder)s"
|
||||
add-from-autocomplete-only="true" max-results-to-show="20"
|
||||
on-tag-added="saveDimension()" on-tag-removed="saveDimension()">
|
||||
<auto-complete source="possibleDimensions()" min-length="1">
|
||||
</auto-complete>
|
||||
</tags-input>
|
||||
</div>
|
||||
''' % final_attrs
|
||||
return format_html(output)
|
||||
return html.format_html(output)
|
||||
|
||||
|
||||
class SimpleExpressionWidget(django_forms.MultiWidget):
|
||||
@ -104,10 +108,10 @@ class NotificationTableWidget(forms.Widget):
|
||||
output += "<tr>"
|
||||
for field in self.fields:
|
||||
field_value = notification[field[self.FIELD_ID_IDX]]
|
||||
output += '<td>%s</td>' % escape(field_value)
|
||||
output += '<td>%s</td>' % html.escape(field_value)
|
||||
output += "</tr>"
|
||||
output += '</table>'
|
||||
return format_html(output)
|
||||
return html.format_html(output)
|
||||
|
||||
|
||||
class NotificationField(forms.MultiValueField):
|
||||
@ -169,7 +173,7 @@ class NotificationCreateWidget(forms.Select):
|
||||
output += '</table>'
|
||||
label = unicode(_("+ Add more"))
|
||||
output += '<a href="" id="add_notification_button">%s</a>' % (label)
|
||||
return format_html(output)
|
||||
return html.format_html(output)
|
||||
|
||||
def value_from_datadict(self, data, files, name):
|
||||
notifications = []
|
||||
|
@ -14,7 +14,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _ # noqa
|
||||
|
||||
import horizon
|
||||
|
||||
|
@ -16,14 +16,14 @@
|
||||
|
||||
import logging
|
||||
|
||||
from django.core import urlresolvers
|
||||
from django import template
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _ # noqa
|
||||
|
||||
from horizon import tables
|
||||
from horizon import exceptions
|
||||
from horizon import tables
|
||||
|
||||
from . import constants
|
||||
from monitoring.alarms import constants
|
||||
from monitoring import api
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -84,8 +84,8 @@ class ShowAlarmHistory(tables.LinkAction):
|
||||
classes = ('btn-edit',)
|
||||
|
||||
def get_link_url(self, datum):
|
||||
return reverse(constants.URL_PREFIX + 'history',
|
||||
args=(datum['name'], datum['id'], ))
|
||||
return urlresolvers.reverse(constants.URL_PREFIX + 'history',
|
||||
args=(datum['name'], datum['id'], ))
|
||||
|
||||
def allowed(self, request, datum=None):
|
||||
return True
|
||||
@ -104,8 +104,8 @@ class CreateAlarm(tables.LinkAction):
|
||||
classes = ("ajax-modal", "btn-create")
|
||||
|
||||
def get_link_url(self):
|
||||
return reverse(constants.URL_PREFIX + 'alarm_create',
|
||||
args=(self.table.kwargs['service'],))
|
||||
return urlresolvers.reverse(constants.URL_PREFIX + 'alarm_create',
|
||||
args=(self.table.kwargs['service'],))
|
||||
|
||||
def allowed(self, request, datum=None):
|
||||
return True
|
||||
@ -117,8 +117,9 @@ class EditAlarm(tables.LinkAction):
|
||||
classes = ("ajax-modal", "btn-create")
|
||||
|
||||
def get_link_url(self, datum):
|
||||
return reverse(constants.URL_PREFIX + 'alarm_edit',
|
||||
args=(self.table.kwargs['service'], datum['id'], ))
|
||||
return urlresolvers.reverse(constants.URL_PREFIX + 'alarm_edit',
|
||||
args=(self.table.kwargs['service'],
|
||||
datum['id'], ))
|
||||
|
||||
def allowed(self, request, datum=None):
|
||||
return True
|
||||
|
@ -13,10 +13,10 @@
|
||||
# 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.conf.urls import patterns
|
||||
from django.conf.urls import url
|
||||
from django.conf.urls import patterns # noqa
|
||||
from django.conf.urls import url # noqa
|
||||
|
||||
from . import views
|
||||
from monitoring.alarms import views
|
||||
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
|
@ -14,31 +14,26 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.import logging
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
from collections import defaultdict # noqa
|
||||
import json
|
||||
import random
|
||||
from collections import defaultdict
|
||||
import logging
|
||||
|
||||
from django.contrib import messages
|
||||
from django.core.urlresolvers import reverse_lazy, reverse # noqa
|
||||
from django.http import HttpResponse # noqa
|
||||
from django.template import defaultfilters as filters
|
||||
from django.http import HttpResponse # noqa
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.generic import TemplateView
|
||||
from django.utils.translation import ugettext as _ # noqa
|
||||
from django.views.generic import TemplateView # noqa
|
||||
|
||||
from horizon import exceptions
|
||||
from horizon import forms
|
||||
from horizon import tables
|
||||
|
||||
import monclient.exc as exc
|
||||
from monitoring.alarms import constants
|
||||
from monitoring.alarms import forms as alarm_forms
|
||||
from monitoring.alarms import tables as alarm_tables
|
||||
from monitoring import api
|
||||
from .tables import AlarmsTable
|
||||
from .tables import AlarmHistoryTable
|
||||
from .tables import show_service
|
||||
from .tables import show_severity
|
||||
from . import forms as alarm_forms
|
||||
from . import constants
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -126,7 +121,7 @@ def get_status(alarms):
|
||||
return 'chicklet-notfound'
|
||||
status_index = 0
|
||||
for a in alarms:
|
||||
severity = show_severity(a)
|
||||
severity = alarm_tables.show_severity(a)
|
||||
severity_index = index_by_severity[severity]
|
||||
status_index = max(status_index, severity_index)
|
||||
return priorities[status_index]['status']
|
||||
@ -136,7 +131,7 @@ def generate_status(request):
|
||||
alarms = api.monitor.alarm_list(request)
|
||||
alarms_by_service = {}
|
||||
for a in alarms:
|
||||
service = show_service(a)
|
||||
service = alarm_tables.show_service(a)
|
||||
service_alarms = alarms_by_service.setdefault(service, [])
|
||||
service_alarms.append(a)
|
||||
for row in SAMPLE:
|
||||
@ -165,7 +160,7 @@ class StatusView(TemplateView):
|
||||
|
||||
|
||||
class AlarmServiceView(tables.DataTableView):
|
||||
table_class = AlarmsTable
|
||||
table_class = alarm_tables.AlarmsTable
|
||||
template_name = constants.TEMPLATE_PREFIX + 'alarm.html'
|
||||
|
||||
def dispatch(self, *args, **kwargs):
|
||||
@ -182,7 +177,7 @@ class AlarmServiceView(tables.DataTableView):
|
||||
results = api.monitor.alarm_list_by_service(
|
||||
self.request,
|
||||
self.service)
|
||||
except:
|
||||
except Exception:
|
||||
messages.error(self.request, _("Could not retrieve alarms"))
|
||||
return results
|
||||
|
||||
@ -211,14 +206,15 @@ class AlarmCreateView(forms.ModalFormView):
|
||||
metrics = api.monitor.metrics_list(self.request)
|
||||
# Filter out metrics for other services
|
||||
if self.service != 'all':
|
||||
meters = [m for m in metrics
|
||||
if m.setdefault('dimensions', {}).
|
||||
setdefault('service', '') == self.service]
|
||||
metrics = [m for m in metrics
|
||||
if m.setdefault('dimensions', {}).
|
||||
setdefault('service', '') == self.service]
|
||||
|
||||
# Aggregate all dimensions for each metric name
|
||||
d = defaultdict(set)
|
||||
for metric in metrics:
|
||||
dim_list = ['%s=%s' % (n, l) for n, l in metric["dimensions"].items()]
|
||||
dim_list = ['%s=%s' % (n, l)
|
||||
for n, l in metric["dimensions"].items()]
|
||||
d[metric["name"]].update(dim_list)
|
||||
unique_metrics = [{'name': k, 'dimensions': sorted(list(v))}
|
||||
for k, v in d.items()]
|
||||
@ -333,6 +329,7 @@ class AlarmEditView(forms.ModalFormView):
|
||||
# except exceptions.NOT_FOUND:
|
||||
except exc.HTTPException:
|
||||
msg = _("Notification %s has already been deleted.") % id
|
||||
messages.warning(self.request, msg)
|
||||
self._object["notifications"] = notifications
|
||||
return self._object
|
||||
except Exception:
|
||||
@ -360,7 +357,7 @@ class AlarmEditView(forms.ModalFormView):
|
||||
|
||||
|
||||
class AlarmHistoryView(tables.DataTableView):
|
||||
table_class = AlarmHistoryTable
|
||||
table_class = alarm_tables.AlarmHistoryTable
|
||||
template_name = constants.TEMPLATE_PREFIX + 'alarm_history.html'
|
||||
|
||||
def dispatch(self, *args, **kwargs):
|
||||
@ -372,7 +369,7 @@ class AlarmHistoryView(tables.DataTableView):
|
||||
results = []
|
||||
try:
|
||||
results = api.monitor.alarm_history(self.request, id)
|
||||
except:
|
||||
except Exception:
|
||||
messages.error(self.request,
|
||||
_("Could not retrieve alarm history for %s") % id)
|
||||
return transform_alarm_history(results, name)
|
||||
@ -384,19 +381,3 @@ class AlarmHistoryView(tables.DataTableView):
|
||||
|
||||
class AlarmMeterView(TemplateView):
|
||||
template_name = constants.TEMPLATE_PREFIX + 'alarm_meter.html'
|
||||
|
||||
|
||||
def get_random_status():
|
||||
distribution = [
|
||||
{'prob': .04, 'value': 'chicklet-error'},
|
||||
{'prob': .04, 'value': 'chicklet-warning'},
|
||||
{'prob': .04, 'value': 'chicklet-unknown'},
|
||||
{'prob': .04, 'value': 'chicklet-notfound'},
|
||||
{'prob': 1.0, 'value': 'chicklet-success'},
|
||||
]
|
||||
num = random.random()
|
||||
for dist in distribution:
|
||||
if num < dist["prob"]:
|
||||
return dist["value"]
|
||||
num = num - dist["prob"]
|
||||
return distribution[len(distribution) - 1]["value"]
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
from django.conf import settings # noqa
|
||||
from monclient import client as mon_client
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -21,7 +21,7 @@ from horizon import forms
|
||||
from horizon import messages
|
||||
|
||||
from monitoring import api
|
||||
from . import constants
|
||||
from monitoring.notifications import constants
|
||||
|
||||
|
||||
READONLY_TEXTINPUT = forms.TextInput(attrs={'readonly': 'readonly'})
|
||||
|
@ -14,7 +14,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _ # noqa
|
||||
|
||||
import horizon
|
||||
|
||||
|
@ -16,15 +16,14 @@
|
||||
|
||||
import logging
|
||||
|
||||
from django import template
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.core import urlresolvers
|
||||
from django.utils.translation import ugettext_lazy as _ # noqa
|
||||
|
||||
from horizon import exceptions
|
||||
from horizon import tables
|
||||
|
||||
from . import constants
|
||||
from monitoring import api
|
||||
from monitoring.notifications import constants
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -54,7 +53,8 @@ class CreateNotification(tables.LinkAction):
|
||||
classes = ("ajax-modal", "btn-create")
|
||||
|
||||
def get_link_url(self):
|
||||
return reverse(constants.URL_PREFIX + 'notification_create',)
|
||||
url = constants.URL_PREFIX + 'notification_create'
|
||||
return urlresolvers.reverse(url)
|
||||
|
||||
def allowed(self, request, datum=None):
|
||||
return True
|
||||
@ -66,8 +66,8 @@ class EditNotification(tables.LinkAction):
|
||||
classes = ("ajax-modal", "btn-create")
|
||||
|
||||
def get_link_url(self, datum):
|
||||
return reverse(constants.URL_PREFIX + 'notification_edit',
|
||||
args=(datum['id'], ))
|
||||
return urlresolvers.reverse(constants.URL_PREFIX + 'notification_edit',
|
||||
args=(datum['id'], ))
|
||||
|
||||
def allowed(self, request, datum=None):
|
||||
return True
|
||||
|
@ -13,10 +13,10 @@
|
||||
# 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.conf.urls import patterns
|
||||
from django.conf.urls import url
|
||||
from django.conf.urls import patterns # noqa
|
||||
from django.conf.urls import url # noqa
|
||||
|
||||
from . import views
|
||||
from monitoring.notifications import views
|
||||
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
|
@ -18,22 +18,23 @@ import logging
|
||||
|
||||
from django.contrib import messages
|
||||
from django.core.urlresolvers import reverse_lazy, reverse # noqa
|
||||
from django.utils.translation import ugettext as _ # noqa
|
||||
|
||||
from horizon import exceptions
|
||||
from horizon import forms
|
||||
from horizon import tables
|
||||
|
||||
from . import forms as notification_forms
|
||||
from . import constants
|
||||
from monitoring.notifications import constants
|
||||
from monitoring.notifications import forms as notification_forms
|
||||
from monitoring.notifications import tables as notification_tables
|
||||
|
||||
from monitoring import api
|
||||
from .tables import NotificationsTable
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IndexView(tables.DataTableView):
|
||||
table_class = NotificationsTable
|
||||
table_class = notification_tables.NotificationsTable
|
||||
template_name = constants.TEMPLATE_PREFIX + 'index.html'
|
||||
|
||||
def dispatch(self, *args, **kwargs):
|
||||
@ -43,7 +44,7 @@ class IndexView(tables.DataTableView):
|
||||
results = []
|
||||
try:
|
||||
results = api.monitor.notification_list(self.request)
|
||||
except:
|
||||
except Exception:
|
||||
messages.error(self.request, _("Could not retrieve notifications"))
|
||||
return results
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
import os
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _ # noqa
|
||||
|
||||
from horizon.test.settings import * # noqa
|
||||
from horizon.utils import secret_key as secret_key_utils
|
||||
|
Loading…
x
Reference in New Issue
Block a user