From af3518ad081b76ba301b9de5978c1bef6a3c284a Mon Sep 17 00:00:00 2001 From: David Larlet Date: Tue, 26 Sep 2023 09:40:41 -0400 Subject: [PATCH] Apply Black to settings files --- umap/settings/__init__.py | 35 ++-- umap/settings/base.py | 329 +++++++++++++++++----------------- umap/settings/dev.py | 14 +- umap/settings/local.py.sample | 64 +++---- 4 files changed, 220 insertions(+), 222 deletions(-) diff --git a/umap/settings/__init__.py b/umap/settings/__init__.py index 0eae30c9..97943a35 100644 --- a/umap/settings/__init__.py +++ b/umap/settings/__init__.py @@ -8,42 +8,41 @@ from .base import * # NOQA, default values # Allow to override setting from any file, may be out of the PYTHONPATH, # to make it easier for non python people. -path = os.environ.get('UMAP_SETTINGS') +path = os.environ.get("UMAP_SETTINGS") if not path: # Retrocompat - path = os.path.join('/etc', 'umap', 'umap.conf') + path = os.path.join("/etc", "umap", "umap.conf") if not os.path.exists(path): # Retrocompat - path = os.path.join(os.path.dirname(os.path.realpath(__file__)), - 'local.py') + path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "local.py") if not os.path.exists(path): - print(colorize('No valid UMAP_SETTINGS found', fg='yellow')) + print(colorize("No valid UMAP_SETTINGS found", fg="yellow")) path = None if path: - d = types.ModuleType('config') + d = types.ModuleType("config") d.__file__ = path try: with open(path) as config_file: - exec(compile(config_file.read(), path, 'exec'), d.__dict__) + exec(compile(config_file.read(), path, "exec"), d.__dict__) except IOError as e: - msg = 'Unable to import {} from UMAP_SETTINGS'.format(path) - print(colorize(msg, fg='red')) + msg = "Unable to import {} from UMAP_SETTINGS".format(path) + print(colorize(msg, fg="red")) sys.exit(e) else: - print('Loaded local config from', path) + print("Loaded local config from", path) for key in dir(d): if key.isupper(): value = getattr(d, key) - if key.startswith('LEAFLET_STORAGE'): + if key.startswith("LEAFLET_STORAGE"): # Retrocompat pre 1.0, remove me in 1.1. - globals()['UMAP' + key[15:]] = value - elif key == 'UMAP_CUSTOM_TEMPLATES': - if 'DIRS' in globals()['TEMPLATES'][0]: - globals()['TEMPLATES'][0]['DIRS'].insert(0, value) + globals()["UMAP" + key[15:]] = value + elif key == "UMAP_CUSTOM_TEMPLATES": + if "DIRS" in globals()["TEMPLATES"][0]: + globals()["TEMPLATES"][0]["DIRS"].insert(0, value) else: - globals()['TEMPLATES'][0]['DIRS'] = [value] - elif key == 'UMAP_CUSTOM_STATICS': - globals()['STATICFILES_DIRS'].insert(0, value) + globals()["TEMPLATES"][0]["DIRS"] = [value] + elif key == "UMAP_CUSTOM_STATICS": + globals()["STATICFILES_DIRS"].insert(0, value) else: globals()[key] = value diff --git a/umap/settings/base.py b/umap/settings/base.py index 1faa0aca..33451aaa 100644 --- a/umap/settings/base.py +++ b/umap/settings/base.py @@ -13,120 +13,121 @@ env = environ.Env() # ============================================================================= -INTERNAL_IPS = env.list('INTERNAL_IPS', default=['127.0.0.1']) -ALLOWED_HOSTS = env.list('ALLOWED_HOSTS', default=['*']) -ADMINS = tuple(parseaddr(email) for email in env.list('ADMINS', default=[])) +INTERNAL_IPS = env.list("INTERNAL_IPS", default=["127.0.0.1"]) +ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=["*"]) +ADMINS = tuple(parseaddr(email) for email in env.list("ADMINS", default=[])) -DEBUG = env.bool('DEBUG', default=False) +DEBUG = env.bool("DEBUG", default=False) SITE_ID = 1 # Add languages we're missing from Django -LANG_INFO.update({ - 'am-et': { - 'bidi': False, - 'name': 'Amharic', - 'code': 'am-et', - 'name_local': 'አማርኛ' - }, - 'zh': { - 'bidi': False, - 'code': 'zh', - 'name': 'Chinese', - 'name_local': '简体中文', - }, - 'si': { - 'bidi': False, - 'code': 'si', - 'name': 'Sinhala', - 'name_local': 'සිංහල', - }, - "ms": { - "bidi": False, - "code": "ms", - "name": "Malay", - "name_local": "Bahasa Melayu", - }, -}) +LANG_INFO.update( + { + "am-et": { + "bidi": False, + "name": "Amharic", + "code": "am-et", + "name_local": "አማርኛ", + }, + "zh": { + "bidi": False, + "code": "zh", + "name": "Chinese", + "name_local": "简体中文", + }, + "si": { + "bidi": False, + "code": "si", + "name": "Sinhala", + "name_local": "සිංහල", + }, + "ms": { + "bidi": False, + "code": "ms", + "name": "Malay", + "name_local": "Bahasa Melayu", + }, + } +) # Local time zone for this installation. Choices can be found here: # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name -TIME_ZONE = 'UTC' +TIME_ZONE = "UTC" USE_TZ = True USE_I18N = True -LANGUAGE_CODE = 'en' +LANGUAGE_CODE = "en" LANGUAGES = ( - ('am-et', 'Amharic'), - ('ar', 'Arabic'), - ('ast', 'Asturian'), - ('bg', 'Bulgarian'), - ('br', 'Breton'), - ('ca', 'Catalan'), - ('cs-cz', 'Czech'), - ('da', 'Danish'), - ('de', 'German'), - ('el', 'Greek'), - ('en', 'English'), - ('es', 'Spanish'), - ('et', 'Estonian'), - ('eu', 'Basque'), - ('fa-ir', 'Persian (Iran)'), - ('fi', 'Finnish'), - ('fr', 'French'), - ('gl', 'Galician'), - ('he', 'Hebrew'), - ('hr', 'Croatian'), - ('hu', 'Hungarian'), - ('id', 'Indonesian'), - ('is', 'Icelandic'), - ('it', 'Italian'), - ('ja', 'Japanese'), - ('ko', 'Korean'), - ('lt', 'Lithuanian'), - ('ms', 'Malay'), - ('nl', 'Dutch'), - ('no', 'Norwegian'), - ('pl', 'Polish'), - ('pt', 'Portuguese'), - ('pt-br', 'Portuguese (Brazil)'), - ('pt-pt', 'Portuguese (Portugal)'), - ('ro', 'Romanian'), - ('ru', 'Russian'), - ('si', 'Sinhala'), - ('sk-sk', 'Slovak'), - ('sl', 'Slovenian'), - ('sr', 'Serbian'), - ('sv', 'Swedish'), - ('th-th', 'Thai (Thailand)'), - ('tr', 'Turkish'), - ('uk-ua', 'Ukrainian'), - ('vi', 'Vietnamese'), - ('zh', 'Chinese'), - ('zh-tw', 'Chinese (Taiwan)'), + ("am-et", "Amharic"), + ("ar", "Arabic"), + ("ast", "Asturian"), + ("bg", "Bulgarian"), + ("br", "Breton"), + ("ca", "Catalan"), + ("cs-cz", "Czech"), + ("da", "Danish"), + ("de", "German"), + ("el", "Greek"), + ("en", "English"), + ("es", "Spanish"), + ("et", "Estonian"), + ("eu", "Basque"), + ("fa-ir", "Persian (Iran)"), + ("fi", "Finnish"), + ("fr", "French"), + ("gl", "Galician"), + ("he", "Hebrew"), + ("hr", "Croatian"), + ("hu", "Hungarian"), + ("id", "Indonesian"), + ("is", "Icelandic"), + ("it", "Italian"), + ("ja", "Japanese"), + ("ko", "Korean"), + ("lt", "Lithuanian"), + ("ms", "Malay"), + ("nl", "Dutch"), + ("no", "Norwegian"), + ("pl", "Polish"), + ("pt", "Portuguese"), + ("pt-br", "Portuguese (Brazil)"), + ("pt-pt", "Portuguese (Portugal)"), + ("ro", "Romanian"), + ("ru", "Russian"), + ("si", "Sinhala"), + ("sk-sk", "Slovak"), + ("sl", "Slovenian"), + ("sr", "Serbian"), + ("sv", "Swedish"), + ("th-th", "Thai (Thailand)"), + ("tr", "Turkish"), + ("uk-ua", "Ukrainian"), + ("vi", "Vietnamese"), + ("zh", "Chinese"), + ("zh-tw", "Chinese (Taiwan)"), ) # Make this unique, and don't share it with anybody. -SECRET_KEY = env('SECRET_KEY', default=None) +SECRET_KEY = env("SECRET_KEY", default=None) INSTALLED_APPS = ( - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.sites', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'django.contrib.admin', - 'django.contrib.gis', - - 'django_probes', - 'umap', - 'compressor', - 'social_django', + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.sites", + "django.contrib.messages", + "django.contrib.staticfiles", + "django.contrib.admin", + "django.contrib.gis", + "django_probes", + "umap", + "compressor", + "social_django", # See https://github.com/peopledoc/django-agnocomplete/commit/26eda2dfa4a2f8a805ca2ea19a0c504b9d773a1c # Django does not find the app config in the default place, so the app is not loaded # so the "autodiscover" is not run. - 'agnocomplete.app.AgnocompleteConfig', + "agnocomplete.app.AgnocompleteConfig", ) -DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' +DEFAULT_AUTO_FIELD = "django.db.models.AutoField" EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" FROM_EMAIL = None @@ -147,23 +148,23 @@ PROJECT_DIR = os.path.dirname(os.path.realpath(project_module.__file__)) # Project URLS and media settings # ============================================================================= -ROOT_URLCONF = 'umap.urls' -WSGI_APPLICATION = 'umap.wsgi.application' +ROOT_URLCONF = "umap.urls" +WSGI_APPLICATION = "umap.wsgi.application" -LOGIN_URL = '/login/' -LOGOUT_URL = '/logout/' -LOGIN_REDIRECT_URL = '/' +LOGIN_URL = "/login/" +LOGOUT_URL = "/logout/" +LOGIN_REDIRECT_URL = "/" -STATIC_URL = '/static/' -MEDIA_URL = '/uploads/' +STATIC_URL = "/static/" +MEDIA_URL = "/uploads/" -STATIC_ROOT = os.path.join('static') -MEDIA_ROOT = os.path.join('uploads') +STATIC_ROOT = os.path.join("static") +MEDIA_ROOT = os.path.join("uploads") STATICFILES_FINDERS = [ - 'django.contrib.staticfiles.finders.FileSystemFinder', - 'django.contrib.staticfiles.finders.AppDirectoriesFinder', - 'compressor.finders.CompressorFinder', + "django.contrib.staticfiles.finders.FileSystemFinder", + "django.contrib.staticfiles.finders.AppDirectoriesFinder", + "compressor.finders.CompressorFinder", ] STATICFILES_DIRS = [] # May be extended when using UMAP_CUSTOM_STATICS @@ -173,24 +174,24 @@ STATICFILES_DIRS = [] # May be extended when using UMAP_CUSTOM_STATICS TEMPLATES = [ { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': ( - 'django.contrib.auth.context_processors.auth', - 'django.template.context_processors.debug', - 'django.template.context_processors.i18n', - 'django.template.context_processors.request', - 'django.template.context_processors.media', - 'django.template.context_processors.static', - 'django.template.context_processors.tz', - 'django.contrib.messages.context_processors.messages', - 'social_django.context_processors.backends', - 'social_django.context_processors.login_redirect', - 'umap.context_processors.settings', - 'umap.context_processors.version', + "BACKEND": "django.template.backends.django.DjangoTemplates", + "APP_DIRS": True, + "OPTIONS": { + "context_processors": ( + "django.contrib.auth.context_processors.auth", + "django.template.context_processors.debug", + "django.template.context_processors.i18n", + "django.template.context_processors.request", + "django.template.context_processors.media", + "django.template.context_processors.static", + "django.template.context_processors.tz", + "django.contrib.messages.context_processors.messages", + "social_django.context_processors.backends", + "social_django.context_processors.login_redirect", + "umap.context_processors.settings", + "umap.context_processors.version", ) - } + }, }, ] @@ -200,13 +201,13 @@ TEMPLATES = [ # ============================================================================= MIDDLEWARE = ( - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.locale.LocaleMiddleware', - 'django.middleware.common.CommonMiddleware', - 'umap.middleware.readonly_middleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.locale.LocaleMiddleware", + "django.middleware.common.CommonMiddleware", + "umap.middleware.readonly_middleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", ) @@ -229,36 +230,36 @@ USER_URL_FIELD = "username" UMAP_ALLOW_ANONYMOUS = env.bool("UMAP_ALLOW_ANONYMOUS", default=False) UMAP_EXTRA_URLS = { - 'routing': 'http://www.openstreetmap.org/directions?engine=osrm_car&route={lat},{lng}&locale={locale}#map={zoom}/{lat}/{lng}', # noqa - 'ajax_proxy': '/ajax-proxy/?url={url}&ttl={ttl}', - 'search': 'https://photon.komoot.io/api/?', + "routing": "http://www.openstreetmap.org/directions?engine=osrm_car&route={lat},{lng}&locale={locale}#map={zoom}/{lat}/{lng}", # noqa + "ajax_proxy": "/ajax-proxy/?url={url}&ttl={ttl}", + "search": "https://photon.komoot.io/api/?", } -UMAP_KEEP_VERSIONS = env.int('UMAP_KEEP_VERSIONS', default=10) +UMAP_KEEP_VERSIONS = env.int("UMAP_KEEP_VERSIONS", default=10) SITE_URL = env("SITE_URL", default="http://umap.org") -SHORT_SITE_URL = env('SHORT_SITE_URL', default=None) -SITE_NAME = 'uMap' -UMAP_DEMO_SITE = env('UMAP_DEMO_SITE', default=False) +SHORT_SITE_URL = env("SHORT_SITE_URL", default=None) +SITE_NAME = "uMap" +UMAP_DEMO_SITE = env("UMAP_DEMO_SITE", default=False) UMAP_EXCLUDE_DEFAULT_MAPS = False UMAP_MAPS_PER_PAGE = 5 UMAP_MAPS_PER_SEARCH = 25 UMAP_MAPS_PER_PAGE_OWNER = 10 UMAP_SEARCH_CONFIGURATION = "simple" -UMAP_FEEDBACK_LINK = "https://wiki.openstreetmap.org/wiki/UMap#Feedback_and_help" # noqa -USER_MAPS_URL = 'user_maps' -DATABASES = { - 'default': env.db(default='postgis://localhost:5432/umap') -} +UMAP_FEEDBACK_LINK = ( + "https://wiki.openstreetmap.org/wiki/UMap#Feedback_and_help" # noqa +) +USER_MAPS_URL = "user_maps" +DATABASES = {"default": env.db(default="postgis://localhost:5432/umap")} UMAP_DEFAULT_SHARE_STATUS = None UMAP_DEFAULT_EDIT_STATUS = None UMAP_DEFAULT_FEATURES_HAVE_OWNERS = False -UMAP_READONLY = env('UMAP_READONLY', default=False) +UMAP_READONLY = env("UMAP_READONLY", default=False) UMAP_GZIP = True -LOCALE_PATHS = [os.path.join(PROJECT_DIR, 'locale')] +LOCALE_PATHS = [os.path.join(PROJECT_DIR, "locale")] -LEAFLET_LONGITUDE = env.int('LEAFLET_LONGITUDE', default=2) -LEAFLET_LATITUDE = env.int('LEAFLET_LATITUDE', default=51) -LEAFLET_ZOOM = env.int('LEAFLET_ZOOM', default=6) +LEAFLET_LONGITUDE = env.int("LEAFLET_LONGITUDE", default=2) +LEAFLET_LATITUDE = env.int("LEAFLET_LATITUDE", default=51) +LEAFLET_ZOOM = env.int("LEAFLET_ZOOM", default=6) # ============================================================================= @@ -272,31 +273,29 @@ SOCIAL_AUTH_LOGIN_REDIRECT_URL = "/login/popup/end/" AUTHENTICATION_BACKENDS = () -SOCIAL_AUTH_OPENSTREETMAP_KEY = env('SOCIAL_AUTH_OPENSTREETMAP_KEY', default="") -SOCIAL_AUTH_OPENSTREETMAP_SECRET = env('SOCIAL_AUTH_OPENSTREETMAP_SECRET', default="") +SOCIAL_AUTH_OPENSTREETMAP_KEY = env("SOCIAL_AUTH_OPENSTREETMAP_KEY", default="") +SOCIAL_AUTH_OPENSTREETMAP_SECRET = env("SOCIAL_AUTH_OPENSTREETMAP_SECRET", default="") if SOCIAL_AUTH_OPENSTREETMAP_KEY and SOCIAL_AUTH_OPENSTREETMAP_SECRET: AUTHENTICATION_BACKENDS += ( - 'social_core.backends.openstreetmap.OpenStreetMapOAuth', + "social_core.backends.openstreetmap.OpenStreetMapOAuth", ) -AUTHENTICATION_BACKENDS += ( - 'django.contrib.auth.backends.ModelBackend', -) +AUTHENTICATION_BACKENDS += ("django.contrib.auth.backends.ModelBackend",) LOGGING = { - 'version': 1, - 'disable_existing_loggers': False, - 'handlers': { - 'console': { - 'level': 'ERROR', - 'filters': None, - 'class': 'logging.StreamHandler', + "version": 1, + "disable_existing_loggers": False, + "handlers": { + "console": { + "level": "ERROR", + "filters": None, + "class": "logging.StreamHandler", }, }, - 'loggers': { - 'django': { - 'handlers': ['console'], - 'level': 'ERROR', + "loggers": { + "django": { + "handlers": ["console"], + "level": "ERROR", }, }, } diff --git a/umap/settings/dev.py b/umap/settings/dev.py index 9439e43b..47fd35c0 100644 --- a/umap/settings/dev.py +++ b/umap/settings/dev.py @@ -1,16 +1,16 @@ """Settings for Development Server""" -from umap.settings.base import * # pylint: disable=W0614,W0401 +from umap.settings.base import * # pylint: disable=W0614,W0401 DEBUG = True TEMPLATE_DEBUG = DEBUG -VAR_ROOT = '/var/www/umap' -MEDIA_ROOT = os.path.join(VAR_ROOT, 'uploads') -STATIC_ROOT = os.path.join(VAR_ROOT, 'static') +VAR_ROOT = "/var/www/umap" +MEDIA_ROOT = os.path.join(VAR_ROOT, "uploads") +STATIC_ROOT = os.path.join(VAR_ROOT, "static") DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'umap', + "default": { + "ENGINE": "django.db.backends.postgresql_psycopg2", + "NAME": "umap", } } diff --git a/umap/settings/local.py.sample b/umap/settings/local.py.sample index 1a8a846f..10e725ab 100644 --- a/umap/settings/local.py.sample +++ b/umap/settings/local.py.sample @@ -9,55 +9,55 @@ your code repository. """ -from umap.settings.base import * # pylint: disable=W0614,W0401 +from umap.settings.base import * # pylint: disable=W0614,W0401 -SECRET_KEY = '!!change me!!' -INTERNAL_IPS = ('127.0.0.1', ) -ALLOWED_HOSTS = ['*', ] +SECRET_KEY = "!!change me!!" +INTERNAL_IPS = ("127.0.0.1",) +ALLOWED_HOSTS = [ + "*", +] DEBUG = True -ADMINS = ( - ('You', 'your@email'), -) +ADMINS = (("You", "your@email"),) MANAGERS = ADMINS DATABASES = { - 'default': { - 'ENGINE': 'django.contrib.gis.db.backends.postgis', - 'NAME': 'umap', + "default": { + "ENGINE": "django.contrib.gis.db.backends.postgis", + "NAME": "umap", } } COMPRESS_ENABLED = False COMPRESS_OFFLINE = True -LANGUAGE_CODE = 'en' +LANGUAGE_CODE = "en" # Set to False if login into django account should not be possible. You can # administer accounts in the admin interface. ENABLE_ACCOUNT_LOGIN = True AUTHENTICATION_BACKENDS = ( - 'social_core.backends.github.GithubOAuth2', - 'social_core.backends.bitbucket.BitbucketOAuth', - 'social_core.backends.twitter.TwitterOAuth', - 'social_core.backends.openstreetmap.OpenStreetMapOAuth', - 'django.contrib.auth.backends.ModelBackend', + "social_core.backends.github.GithubOAuth2", + "social_core.backends.bitbucket.BitbucketOAuth", + "social_core.backends.twitter.TwitterOAuth", + "social_core.backends.openstreetmap.OpenStreetMapOAuth", + "django.contrib.auth.backends.ModelBackend", ) -SOCIAL_AUTH_GITHUB_KEY = 'xxx' -SOCIAL_AUTH_GITHUB_SECRET = 'xxx' -SOCIAL_AUTH_BITBUCKET_KEY = 'xxx' -SOCIAL_AUTH_BITBUCKET_SECRET = 'xxx' -# We need email to associate with other Oauth providers -SOCIAL_AUTH_GITHUB_SCOPE = ["user:email", ] +SOCIAL_AUTH_GITHUB_KEY = "xxx" +SOCIAL_AUTH_GITHUB_SECRET = "xxx" +SOCIAL_AUTH_BITBUCKET_KEY = "xxx" +SOCIAL_AUTH_BITBUCKET_SECRET = "xxx" +# We need email to associate with other Oauth providers +SOCIAL_AUTH_GITHUB_SCOPE = [ + "user:email", +] SOCIAL_AUTH_TWITTER_KEY = "xxx" SOCIAL_AUTH_TWITTER_SECRET = "xxx" -SOCIAL_AUTH_OPENSTREETMAP_KEY = 'xxx' -SOCIAL_AUTH_OPENSTREETMAP_SECRET = 'xxx' -MIDDLEWARE += ( - 'social_django.middleware.SocialAuthExceptionMiddleware', -) +SOCIAL_AUTH_OPENSTREETMAP_KEY = "xxx" +SOCIAL_AUTH_OPENSTREETMAP_SECRET = "xxx" +MIDDLEWARE += ("social_django.middleware.SocialAuthExceptionMiddleware",) SOCIAL_AUTH_REDIRECT_IS_HTTPS = True SOCIAL_AUTH_RAISE_EXCEPTIONS = False SOCIAL_AUTH_BACKEND_ERROR_URL = "/" @@ -94,17 +94,17 @@ SHORT_SITE_URL = "http://s.hort" # } # POSTGIS_VERSION = (2, 1, 0) -EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' +EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" # Put the site in readonly mode (useful for migration or any maintenance) UMAP_READONLY = False -# For static deployment -STATIC_ROOT = '/srv/umap/var/static' +# For static deployment +STATIC_ROOT = "/srv/umap/var/static" -# For users' statics (geojson mainly) -MEDIA_ROOT = '/srv/umap/var/data' +# For users' statics (geojson mainly) +MEDIA_ROOT = "/srv/umap/var/data" # Default map location for new maps LEAFLET_LONGITUDE = 2