Fix all pep8 errors except demo code in views.

This commit is contained in:
Rob Raymond 2014-05-28 12:40:56 -06:00
parent 83cb98ac1c
commit 775ba50047
6 changed files with 40 additions and 24 deletions

View File

@ -16,4 +16,3 @@ ADD_INSTALLED_APPS = ['monitoring']
# A list of angular modules to be added as dependencies to horizon app.
#ADD_ANGULAR_MODULE = ['monitoringApp']

View File

@ -55,13 +55,16 @@ def monclient(request, password=None):
def alarm_list(request, marker=None, paginate=False):
return monclient(request).alarms.list()
def alarm_list_by_service(request, service_name, marker=None, paginate=False):
service_dim = {'service' : service_name}
service_dim = {'service': service_name}
return monclient(request).alarms.list(dimensions=service_dim)
def alarm_delete(request, alarm_id):
return monclient(request).alarms.delete(alarm_id=alarm_id)
def alarm_get(request, alarm_id):
return monclient(request).alarms.get(alarm_id=alarm_id)
@ -83,7 +86,8 @@ def notification_delete(request, notification_id):
def notification_get(request, notification_id):
return monclient(request).notifications.get(notification_id=notification_id)
return monclient(request).notifications. \
get(notification_id=notification_id)
def notification_create(request, **kwargs):
@ -96,5 +100,3 @@ def notification_update(request, notification_id, **kwargs):
def metrics_list(request, marker=None, paginate=False):
return monclient(request).metrics.list()

View File

@ -31,8 +31,7 @@ class NotificationType(object):
if choice[0] == key:
return choice[1]
return key
OVERCLOUD_SERVICES = ["Nova","Swift","Cinder","Glance","Neutron","MySQL","RabbitMQ","Monitoring"]
ß
PHONE_VALIDATOR = validators.RegexValidator(
regex=r"^\+[()0-9 ]{5,20}$",

View File

@ -26,6 +26,7 @@ from horizon import messages
from monitoring import api
from monitoring import constants
def get_expression(meter):
expr = meter['name']
args = None
@ -38,12 +39,14 @@ def get_expression(meter):
args += "%s=%s" % (name, value)
return "%s{%s}" % (expr, args)
class SimpleExpressionWidget(django_forms.MultiWidget):
def __init__(self, meters=None, attrs=None):
choices = [(get_expression(m), get_expression(m)) for m in meters]
comparators = [('>', '>'), ('<', '<'), ('=', '=')]
_widgets = (
django_forms.widgets.Select(attrs=attrs, choices=choices),
django_forms.widgets.Select(attrs=attrs, choices=[('>', '>'), ('<', '<'), ('=', '=')]),
django_forms.widgets.Select(attrs=attrs, choices=comparatorsß),
django_forms.widgets.TextInput(attrs=attrs),
)
super(SimpleExpressionWidget, self).__init__(_widgets, attrs)
@ -129,7 +132,7 @@ class NotificationCreateWidget(forms.Select):
for notification in value:
output += '<tr><td>'
output += ('<select id="id_notifications_%d" ' +
'name="notifications_%d"> ') % (idx, idx)
'name="notifications_%d"> ') % (idx, idx)
options = self.render_options(
choices,
[notification['notification_id']])
@ -206,8 +209,8 @@ class BaseAlarmForm(forms.SelfHandlingForm):
required=required,
widget=expressionWidget)
self.fields['description'] = forms.CharField(label=_("Description"),
required=False,
widget=textAreaWidget)
required=False,
widget=textAreaWidget)
sev_choices = [("Low", _("Low")),
("Medium", _("Medium")),
("High", _("High"))]
@ -218,9 +221,10 @@ class BaseAlarmForm(forms.SelfHandlingForm):
self.fields['state'] = forms.CharField(label=_("State"),
required=False,
widget=textWidget)
self.fields['actions_enabled'] = forms.BooleanField(label=_("Notifications Enabled"),
required=False,
initial=True)
self.fields['actions_enabled'] = \
forms.BooleanField(label=_("Notifications Enabled"),
required=False,
initial=True)
self.fields['notifications'] = NotificationField(
label=_("Notifications"),
required=False,
@ -304,7 +308,7 @@ class EditAlarmForm(BaseAlarmForm):
expression=data['expression'],
description=data['description'],
alarm_actions=alarm_actions,
)
)
messages.success(request,
_('Alarm has been edited successfully.'))
except Exception as e:

View File

@ -142,17 +142,21 @@ class AlarmsTable(tables.DataTable):
link_classes=('ajax-modal',))
host = tables.Column(transform=show_host, verbose_name=_('Host'))
service = tables.Column(transform=show_service, verbose_name=_('Service'))
state = tables.Column('state', verbose_name=_('State'))
state = tables.Column('state', verbose_name=_('State'))
expression = tables.Column('expression', verbose_name=_('Expression'))
enabled = tables.Column('actions_enabled', verbose_name=_('Notifications Enabled'))
enabled = tables.Column('actions_enabled',
verbose_name=_('Notifications Enabled'))
def get_object_id(self, obj):
return obj['id']
class Meta:
name = "alarms"
verbose_name = _("Alarms")
row_actions = (ShowAlarmHistory, ShowAlarmMeters, DeleteAlarm, EditAlarm, )
row_actions = (ShowAlarmHistory,
ShowAlarmMeters,
DeleteAlarm,
EditAlarm, )
table_actions = (CreateNotification, CreateAlarm, )
status_columns = ['status']

View File

@ -34,8 +34,16 @@ urlpatterns = patterns(
url(r'^meters/(?P<service>[^/]+)$',
views.AlarmMeterView.as_view(),
name='meters'),
url(r'^alarm_create$', views.AlarmCreateView.as_view(), name='alarm_create'),
url(r'^(?P<id>[^/]+)/alarm_detail/$', views.AlarmDetailView.as_view(), name='alarm_detail'),
url(r'^(?P<id>[^/]+)/alarm_edit/$', views.AlarmEditView.as_view(), name='alarm_edit'),
url(r'^notification_create$', views.NotificationCreateView.as_view(), name='notification_create'),
url(r'^alarm_create$',
views.AlarmCreateView.as_view(),
name='alarm_create'),
url(r'^(?P<id>[^/]+)/alarm_detail/$',
views.AlarmDetailView.as_view(),
name='alarm_detail'),
url(r'^(?P<id>[^/]+)/alarm_edit/$',
views.AlarmEditView.as_view(),
name='alarm_edit'),
url(r'^notification_create$',
views.NotificationCreateView.as_view(),
name='notification_create'),
)