summaryrefslogtreecommitdiffstats
path: root/accounts/utils/console.py
diff options
context:
space:
mode:
Diffstat (limited to 'accounts/utils/console.py')
-rw-r--r--accounts/utils/console.py47
1 files changed, 29 insertions, 18 deletions
diff --git a/accounts/utils/console.py b/accounts/utils/console.py
index 823ec33..1b539bd 100644
--- a/accounts/utils/console.py
+++ b/accounts/utils/console.py
@@ -1,13 +1,14 @@
# -*- coding: utf-8 -*-
-class TablePrinter():
+
+class TablePrinter:
separator: str
- def __init__(self, headers=None, separator='|'):
+ def __init__(self, headers=None, separator="|"):
self.headers = headers
self.separator = separator
- self.format_string = ''
+ self.format_string = ""
self.widths = list()
if headers is not None:
@@ -26,17 +27,19 @@ class TablePrinter():
while len(self.widths) < columns:
self.widths.append(0)
- self.widths = [_column_width(column, width)
- for column, width
- in zip(list(zip(*rows)), self.widths)]
+ self.widths = [
+ _column_width(column, width)
+ for column, width in zip(list(zip(*rows)), self.widths)
+ ]
self._update_format_string()
def _update_format_string(self) -> None:
- sep = ' %s ' % self.separator
- self.format_string = '%s %s %s' % (
+ sep = " %s " % self.separator
+ self.format_string = "%s %s %s" % (
+ self.separator,
+ sep.join(["%%-%ds" % width for width in self.widths]),
self.separator,
- sep.join(['%%-%ds' % width for width in self.widths]),
- self.separator)
+ )
def output(self, rows):
if len(rows) > 0:
@@ -50,10 +53,18 @@ class TablePrinter():
self._print_row(row)
def _print_headline(self) -> None:
- print(('%s%s%s' % (
- self.separator,
- self.separator.join(['-' * (width + 2) for width in self.widths]),
- self.separator)))
+ print(
+ (
+ "%s%s%s"
+ % (
+ self.separator,
+ self.separator.join(
+ ["-" * (width + 2) for width in self.widths]
+ ),
+ self.separator,
+ )
+ )
+ )
def _print_row(self, row) -> None:
print((self.format_string % tuple(row)))
@@ -63,7 +74,7 @@ class ConsoleForm(object):
_ready = False
def __init__(self, formcls, **kwargs):
- self.form = formcls(meta={'csrf': False})
+ self.form = formcls(meta={"csrf": False})
self._fill(kwargs)
self._ready = True
@@ -76,11 +87,11 @@ class ConsoleForm(object):
def print_errors(self):
for field, errors in list(self.form.errors.items()):
if len(errors) > 1:
- print(('%s:' % field))
+ print(("%s:" % field))
for error in errors:
- print((' %s' % error))
+ print((" %s" % error))
else:
- print(('%s: %s' % (field, errors[0])))
+ print(("%s: %s" % (field, errors[0])))
def __getattr__(self, name):
return getattr(self.form, name)