all: implement black as code formatter

This commit is contained in:
Jens Langhammer
2019-12-31 12:51:16 +01:00
parent 8eb3f0f708
commit 3bd1eadd51
298 changed files with 4825 additions and 3145 deletions

View File

@ -8,9 +8,9 @@ def _get_client_ip_from_meta(meta: Dict[str, Any]) -> Optional[str]:
"""Attempt to get the client's IP by checking common HTTP Headers.
Returns none if no IP Could be found"""
headers = (
'HTTP_X_FORWARDED_FOR',
'HTTP_X_REAL_IP',
'REMOTE_ADDR',
"HTTP_X_FORWARDED_FOR",
"HTTP_X_REAL_IP",
"REMOTE_ADDR",
)
for _header in headers:
if _header in meta:

View File

@ -4,15 +4,15 @@ from importlib import import_module
def class_to_path(cls):
"""Turn Class (Class or instance) into module path"""
return '%s.%s' % (cls.__module__, cls.__name__)
return "%s.%s" % (cls.__module__, cls.__name__)
def path_to_class(path):
"""Import module and return class"""
if not path:
return None
parts = path.split('.')
package = '.'.join(parts[:-1])
parts = path.split(".")
package = ".".join(parts[:-1])
_class = getattr(import_module(package), parts[-1])
return _class
@ -20,11 +20,14 @@ def path_to_class(path):
def get_apps():
"""Get list of all passbook apps"""
from django.apps.registry import apps
for _app in apps.get_app_configs():
if _app.name.startswith('passbook'):
if _app.name.startswith("passbook"):
yield _app
def app(name):
"""Return true if app with `name` is enabled"""
from django.conf import settings
return name in settings.INSTALLED_APPS

View File

@ -1,7 +1,8 @@
"""passbook UI utils"""
def human_list(_list) -> str:
"""Convert a list of items into 'a, b or c'"""
last_item = _list.pop()
result = ', '.join(_list)
return '%s or %s' % (result, last_item)
result = ", ".join(_list)
return "%s or %s" % (result, last_item)