Browse Source

Evita padrões de sintaxe específicos do python 3

Evita a, *b = lista, entre outros padrões específicos do python 3.

Isso foi feito para que o código possa ser lido por ferramentas de
análise e manipulação de código que esperam a sintaxe do python 2.

Especificamente clonedigger e redbaron, que por enquanto não rodam em
python 3.
pull/237/head
Marcio Mazza 9 years ago
parent
commit
3ddb2b3302
  1. 10
      crispy_layout_mixin.py
  2. 3
      crud_tests/test_flux.py
  3. 3
      legacy/scripts/scrap_original_forms.py
  4. 2
      sapl/test_general.py

10
crispy_layout_mixin.py

@ -8,6 +8,11 @@ from crispy_forms.layout import HTML, Div, Fieldset, Layout, Submit
from django.utils.translation import ugettext as _
def heads_and_tails(list_of_lists):
for alist in list_of_lists:
yield alist[0], alist[1:]
def to_column(name_span):
fieldname, span = name_span
return Div(fieldname, css_class='col-md-%d' % span)
@ -20,7 +25,7 @@ def to_row(names_spans):
def to_fieldsets(fields):
for field in fields:
if isinstance(field, list):
legend, *row_specs = field
legend, row_specs = field[0], field[1:]
rows = [to_row(name_span_list) for name_span_list in row_specs]
yield Fieldset(legend, *rows)
else:
@ -103,12 +108,13 @@ class CrispyLayoutFormMixin(object):
@property
def layout_display(self):
return [
{'legend': legend,
'rows': [[self.get_column(fieldname, span)
for fieldname, span in row]
for row in rows]
} for legend, *rows in self.get_layout()]
} for legend, rows in heads_and_tails(self.get_layout())]
def read_yaml_from_file(filename):

3
crud_tests/test_flux.py

@ -212,7 +212,8 @@ def test_flux_list_paginate_detail(
assert_on_list_page(res)
table = res.html.find('table')
assert table
header, *trs = table.findAll('tr')
header_trs = table.findAll('tr')
header, trs = header_trs[0], header_trs[1:]
assert [c.text for c in header.findChildren('th')] == [
'name', 'continent', 'population', 'is cold']
rows = [[td.text.strip() for td in tr.findAll('td')]

3
legacy/scripts/scrap_original_forms.py

@ -9,6 +9,7 @@ from bs4 import BeautifulSoup
from bs4.element import NavigableString, Tag
from django.apps.config import AppConfig
from crispy_layout_mixin import heads_and_tails
from legacy.migration import appconfs, get_renames
from legacy.scripts.utils import getsourcelines
from sapl.utils import listify
@ -274,7 +275,7 @@ class %(name)sForm(forms.ModelForm):
self.helper.layout = SaplFormLayout(
""" % {'name': model.__name__})
for legend, *rows in fieldsets:
for legend, rows in heads_and_tails(fieldsets):
lines = pretty_printer.pformat([Under(legend)] + rows) + ',\n\n'
for line in lines.splitlines():
print(' ' * GAP + line if line.strip() else '')

2
sapl/test_general.py

@ -19,4 +19,4 @@ def test_str_sanity():
except Exception as exc:
msg = '%s.%s.__str__ is broken.' % (
model.__module__, model.__name__)
raise AssertionError(msg, exc) from exc
raise AssertionError(msg, exc)

Loading…
Cancel
Save