Fix Flake8 style warnings in horizon/

Warnings H904, H307 and H405 are new or considerably changed, and will
be fixed in a separate patch.

Partial-bug: #1347472

Change-Id: Id9325a40d443f77242d3634002789501afbfc35a
Co-Authored-By: Juan M. Olle <juan.m.olle@intel.com>
This commit is contained in:
Pawel Skowron 2014-07-29 20:59:41 +02:00 committed by Juan Manuel Olle
parent 91f3fe9973
commit 791f384e3e
12 changed files with 57 additions and 35 deletions

View File

@ -552,7 +552,7 @@ class Workflow(object):
try: try:
from django.utils.functional import empty # noqa from django.utils.functional import empty # noqa
except ImportError: except ImportError:
#Django 1.3 fallback # Django 1.3 fallback
empty = None empty = None

View File

@ -44,8 +44,10 @@ class ResourceBrowserView(MultiTableView):
def get_tables(self): def get_tables(self):
tables = super(ResourceBrowserView, self).get_tables() tables = super(ResourceBrowserView, self).get_tables()
# Tells the navigation table what is selected. # Tells the navigation table what is selected.
navigation_table = tables[self.browser_class.navigation_table_class._meta.name] navigation_table = tables[
navigation_item = self.kwargs.get(self.browser_class.navigation_kwarg_name) self.browser_class.navigation_table_class._meta.name]
navigation_item = self.kwargs.get(
self.browser_class.navigation_kwarg_name)
navigation_table.current_item_id = navigation_item navigation_table.current_item_id = navigation_item
return tables return tables

View File

@ -21,6 +21,7 @@ from django.conf.urls import include # noqa
from django.conf.urls import patterns # noqa from django.conf.urls import patterns # noqa
from django.conf.urls import url # noqa from django.conf.urls import url # noqa
from django.views.generic import TemplateView # noqa from django.views.generic import TemplateView # noqa
from horizon.test.jasmine import jasmine from horizon.test.jasmine import jasmine
urlpatterns = patterns('horizon.views', urlpatterns = patterns('horizon.views',

View File

@ -14,7 +14,7 @@
from collections import defaultdict from collections import defaultdict
import logging import logging
import new import types
from django.conf import settings from django.conf import settings
from django.core import urlresolvers from django.core import urlresolvers
@ -293,12 +293,12 @@ class Action(BaseAction):
if not has_single: if not has_single:
def single(self, data_table, request, object_id): def single(self, data_table, request, object_id):
return self.handle(data_table, request, [object_id]) return self.handle(data_table, request, [object_id])
self.single = new.instancemethod(single, self) self.single = types.MethodType(single, self)
if not has_multiple and self.handles_multiple: if not has_multiple and self.handles_multiple:
def multiple(self, data_table, request, object_ids): def multiple(self, data_table, request, object_ids):
return self.handle(data_table, request, object_ids) return self.handle(data_table, request, object_ids)
self.multiple = new.instancemethod(multiple, self) self.multiple = types.MethodType(multiple, self)
def get_param_name(self): def get_param_name(self):
"""Returns the full POST parameter name for this action. """Returns the full POST parameter name for this action.
@ -669,7 +669,7 @@ class BatchAction(Action):
continue continue
try: try:
self.action(request, datum_id) self.action(request, datum_id)
#Call update to invoke changes if needed # Call update to invoke changes if needed
self.update(request, datum) self.update(request, datum)
action_success.append(datum_display) action_success.append(datum_display)
self.success_ids.append(datum_id) self.success_ids.append(datum_id)

View File

@ -323,7 +323,7 @@ class Column(html.HTMLElement):
self.transform in datum: self.transform in datum:
data = datum.get(self.transform) data = datum.get(self.transform)
else: else:
# Basic object lookups # Basic object lookups
try: try:
data = getattr(datum, self.transform) data = getattr(datum, self.transform)
except AttributeError: except AttributeError:
@ -715,7 +715,7 @@ class Cell(html.HTMLElement):
if self.column.status or \ if self.column.status or \
self.column.name in self.column.table._meta.status_columns: self.column.name in self.column.table._meta.status_columns:
#returns the first matching status found # returns the first matching status found
data_status_lower = unicode( data_status_lower = unicode(
self.column.get_raw_data(self.datum)).lower() self.column.get_raw_data(self.datum)).lower()
for status_name, status_value in self.column.status_choices: for status_name, status_value in self.column.status_choices:
@ -1289,8 +1289,8 @@ class DataTable(object):
if not self.multi_select: if not self.multi_select:
return return
select_column = self.columns.values()[0] select_column = self.columns.values()[0]
#Try to find if the hidden class need to be # Try to find if the hidden class need to be
#removed or added based on visible flag. # removed or added based on visible flag.
hidden_found = 'hidden' in select_column.classes hidden_found = 'hidden' in select_column.classes
if hidden_found and visible: if hidden_found and visible:
select_column.classes.remove('hidden') select_column.classes.remove('hidden')

View File

@ -1,9 +1,20 @@
from django import forms # Licensed under the Apache License, Version 2.0 (the "License"); you may
from django.template import Context # not use this file except in compliance with the License. You may obtain
from django.template.loader import get_template # a copy of the License at
from django import template #
# 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 import forms
from django import template as django_template
register = django_template.Library()
register = template.Library()
@register.filter @register.filter
def bootstrap_form_field(element): def bootstrap_form_field(element):
@ -12,8 +23,10 @@ def bootstrap_form_field(element):
def add_input_classes(field): def add_input_classes(field):
if not is_checkbox(field) and not is_multiple_checkbox(field) and not is_radio(field) \ if (not is_checkbox(field) and
and not is_file(field): not is_multiple_checkbox(field) and
not is_radio(field) and
not is_file(field)):
field_classes = field.field.widget.attrs.get('class', '') field_classes = field.field.widget.attrs.get('class', '')
field_classes += ' form-control' field_classes += ' form-control'
field.field.widget.attrs['class'] = field_classes field.field.widget.attrs['class'] = field_classes
@ -21,8 +34,10 @@ def add_input_classes(field):
def render(element, markup_classes): def render(element, markup_classes):
add_input_classes(element) add_input_classes(element)
template = get_template("horizon/common/_bootstrap_form_field.html") template = django_template.loader.get_template(
context = Context({'field': element, 'classes': markup_classes}) "horizon/common/_bootstrap_form_field.html")
context = django_template.Context({'field': element,
'classes': markup_classes})
return template.render(context) return template.render(context)

View File

@ -21,6 +21,7 @@ Template tags for parsing date strings.
""" """
from datetime import datetime # noqa from datetime import datetime # noqa
from django import template from django import template
from django.utils import timezone from django.utils import timezone

View File

@ -37,9 +37,10 @@ LOG = logging.getLogger(__name__)
try: try:
from horizon.test.webdriver import WebDriver # noqa
from selenium.webdriver.support import ui as selenium_ui from selenium.webdriver.support import ui as selenium_ui
import xvfbwrapper # Only needed when running the Selenium tests headless import xvfbwrapper # Only needed when running the Selenium tests headless
from horizon.test.webdriver import WebDriver # noqa
except ImportError as e: except ImportError as e:
# NOTE(saschpe): Several distribution can't ship selenium due to its # NOTE(saschpe): Several distribution can't ship selenium due to its
# non-free license. So they have to patch it out of test-requirements.txt # non-free license. So they have to patch it out of test-requirements.txt
@ -170,7 +171,7 @@ class SeleniumTestCase(django_test.LiveServerTestCase):
socket.setdefaulttimeout(60) socket.setdefaulttimeout(60)
if os.environ.get('WITH_SELENIUM', False): if os.environ.get('WITH_SELENIUM', False):
time.sleep(1) time.sleep(1)
# Start a virtual display server for running the tests headless. # Start a virtual display server for running the tests headless.
if os.environ.get('SELENIUM_HEADLESS', False): if os.environ.get('SELENIUM_HEADLESS', False):
cls.vdisplay = xvfbwrapper.Xvfb(width=1280, height=720) cls.vdisplay = xvfbwrapper.Xvfb(width=1280, height=720)
cls.vdisplay.start() cls.vdisplay.start()

View File

@ -10,15 +10,16 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import django.shortcuts
import django.views.defaults
import inspect import inspect
import sys import sys
import django.shortcuts
import django.views.defaults
def dispatcher(request, test_name): def dispatcher(request, test_name):
#import is included in this non-standard location to avoid # import is included in this non-standard location to avoid
#problems importing mox. See bug/1288245 # problems importing mox. See bug/1288245
from horizon.test.jasmine import jasmine_tests as tests from horizon.test.jasmine import jasmine_tests as tests
classes = inspect.getmembers(sys.modules[tests.__name__], classes = inspect.getmembers(sys.modules[tests.__name__],
inspect.isclass) inspect.isclass)

View File

@ -22,10 +22,11 @@ import sys
import django import django
from django.utils import html_parser from django.utils import html_parser
from horizon.test import patches
import xstatic.main import xstatic.main
import xstatic.pkg.jquery import xstatic.pkg.jquery
from horizon.test import patches
# Patch django.utils.html_parser.HTMLParser as a workaround for bug 1273943 # Patch django.utils.html_parser.HTMLParser as a workaround for bug 1273943
if django.get_version() == '1.4' and sys.version_info[:3] > (2, 7, 3): if django.get_version() == '1.4' and sys.version_info[:3] > (2, 7, 3):

View File

@ -147,7 +147,7 @@ class MyToggleAction(tables.BatchAction):
def action(self, request, object_ids): def action(self, request, object_ids):
if self.down: if self.down:
#up it # up it
self.current_past_action = 1 self.current_past_action = 1
@ -1102,9 +1102,9 @@ class DataTableTests(test.TestCase):
def test_table_column_can_be_selected(self): def test_table_column_can_be_selected(self):
self.table = MyTableSelectable(self.request, TEST_DATA_6) self.table = MyTableSelectable(self.request, TEST_DATA_6)
#non selectable row # non selectable row
row = self.table.get_rows()[0] row = self.table.get_rows()[0]
#selectable # selectable
row1 = self.table.get_rows()[1] row1 = self.table.get_rows()[1]
id_col = self.table.columns['id'] id_col = self.table.columns['id']
@ -1139,11 +1139,11 @@ class DataTableTests(test.TestCase):
'<Cell: value, my_table__row__1>', '<Cell: value, my_table__row__1>',
'<Cell: status, my_table__row__1>', '<Cell: status, my_table__row__1>',
]) ])
#can_be_selected = False # can_be_selected = False
self.assertTrue(row.get_cells()[0].data == "") self.assertTrue(row.get_cells()[0].data == "")
#can_be_selected = True # can_be_selected = True
self.assertIn('checkbox', row1.get_cells()[0].data) self.assertIn('checkbox', row1.get_cells()[0].data)
#status # status
cell_status = row.cells['status'].status cell_status = row.cells['status'].status
self.assertEqual(row.cells['status'].get_status_class(cell_status), self.assertEqual(row.cells['status'].get_status_class(cell_status),
'status_down') 'status_down')

View File

@ -14,12 +14,12 @@
from __future__ import with_statement # Python 2.5 compliance from __future__ import with_statement # Python 2.5 compliance
import lockfile
import os import os
import random import random
import string import string
import lockfile
class FilePermissionError(Exception): class FilePermissionError(Exception):
"""The key file permissions are insecure.""" """The key file permissions are insecure."""