From 3ddb2b3302d689e552c7e77e3c892d8d331dcfec Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Wed, 2 Mar 2016 20:10:06 -0300 Subject: [PATCH] =?UTF-8?q?Evita=20padr=C3=B5es=20de=20sintaxe=20espec?= =?UTF-8?q?=C3=ADficos=20do=20python=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- crispy_layout_mixin.py | 10 ++++++++-- crud_tests/test_flux.py | 3 ++- legacy/scripts/scrap_original_forms.py | 3 ++- sapl/test_general.py | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/crispy_layout_mixin.py b/crispy_layout_mixin.py index e6eee5aed..9e30b56e8 100644 --- a/crispy_layout_mixin.py +++ b/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): diff --git a/crud_tests/test_flux.py b/crud_tests/test_flux.py index ba3f851d3..16a63948a 100644 --- a/crud_tests/test_flux.py +++ b/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')] diff --git a/legacy/scripts/scrap_original_forms.py b/legacy/scripts/scrap_original_forms.py index 767f2b204..d9fab3bf5 100644 --- a/legacy/scripts/scrap_original_forms.py +++ b/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 '') diff --git a/sapl/test_general.py b/sapl/test_general.py index a093b53ea..443cc40d4 100644 --- a/sapl/test_general.py +++ b/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)