mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-02-18 04:20:51 +03:00
Convert old-styled string formatting to f-string (#1528)
* Convert old-styled string formatting to f-string * Update flake8 explicit version to 3.5.0 * Make tox.ini in sync with requirements.txt * Fix annoying flake8 F405
This commit is contained in:
parent
ee04c5cf09
commit
9cb7e50b8e
6
tox.ini
6
tox.ini
|
@ -3,9 +3,5 @@ skipsdist = true
|
||||||
envlist = py36
|
envlist = py36
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
deps =
|
deps = -rrequirements.txt
|
||||||
binaryornot
|
|
||||||
flake8==2.5.5
|
|
||||||
pytest-cookies
|
|
||||||
sh
|
|
||||||
commands = pytest {posargs:./tests}
|
commands = pytest {posargs:./tests}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from .base import * # noqa
|
from .base import * # noqa
|
||||||
|
from .base import env
|
||||||
|
|
||||||
# GENERAL
|
# GENERAL
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -25,7 +26,7 @@ CACHES = {
|
||||||
# TEMPLATES
|
# TEMPLATES
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# https://docs.djangoproject.com/en/dev/ref/settings/#templates
|
# https://docs.djangoproject.com/en/dev/ref/settings/#templates
|
||||||
TEMPLATES[0]['OPTIONS']['debug'] = DEBUG
|
TEMPLATES[0]['OPTIONS']['debug'] = DEBUG # noqa F405
|
||||||
|
|
||||||
# EMAIL
|
# EMAIL
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -47,9 +48,9 @@ EMAIL_PORT = 1025
|
||||||
# django-debug-toolbar
|
# django-debug-toolbar
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#prerequisites
|
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#prerequisites
|
||||||
INSTALLED_APPS += ['debug_toolbar']
|
INSTALLED_APPS += ['debug_toolbar'] # noqa F405
|
||||||
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#middleware
|
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#middleware
|
||||||
MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware']
|
MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware'] # noqa F405
|
||||||
# https://django-debug-toolbar.readthedocs.io/en/latest/configuration.html#debug-toolbar-config
|
# https://django-debug-toolbar.readthedocs.io/en/latest/configuration.html#debug-toolbar-config
|
||||||
DEBUG_TOOLBAR_CONFIG = {
|
DEBUG_TOOLBAR_CONFIG = {
|
||||||
'DISABLE_PANELS': [
|
'DISABLE_PANELS': [
|
||||||
|
@ -70,7 +71,7 @@ if os.environ.get('USE_DOCKER') == 'yes':
|
||||||
# django-extensions
|
# django-extensions
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# https://django-extensions.readthedocs.io/en/latest/installation_instructions.html#configuration
|
# https://django-extensions.readthedocs.io/en/latest/installation_instructions.html#configuration
|
||||||
INSTALLED_APPS += ['django_extensions']
|
INSTALLED_APPS += ['django_extensions'] # noqa F405
|
||||||
{% if cookiecutter.use_celery == 'y' -%}
|
{% if cookiecutter.use_celery == 'y' -%}
|
||||||
|
|
||||||
# Celery
|
# Celery
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from .base import * # noqa
|
from .base import * # noqa
|
||||||
|
from .base import env
|
||||||
|
|
||||||
# GENERAL
|
# GENERAL
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -11,16 +12,16 @@ ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS', default=['{{ cookiecutter.domai
|
||||||
|
|
||||||
# DATABASES
|
# DATABASES
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
DATABASES['default'] = env.db('DATABASE_URL')
|
DATABASES['default'] = env.db('DATABASE_URL') # noqa F405
|
||||||
DATABASES['default']['ATOMIC_REQUESTS'] = True
|
DATABASES['default']['ATOMIC_REQUESTS'] = True # noqa F405
|
||||||
DATABASES['default']['CONN_MAX_AGE'] = env.int('CONN_MAX_AGE', default=60)
|
DATABASES['default']['CONN_MAX_AGE'] = env.int('CONN_MAX_AGE', default=60) # noqa F405
|
||||||
|
|
||||||
# CACHES
|
# CACHES
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
CACHES = {
|
CACHES = {
|
||||||
'default': {
|
'default': {
|
||||||
'BACKEND': 'django_redis.cache.RedisCache',
|
'BACKEND': 'django_redis.cache.RedisCache',
|
||||||
'LOCATION': "{}/0".format(env('REDIS_URL', default='redis://127.0.0.1:6379')),
|
'LOCATION': f'{env("REDIS_URL", default="redis://127.0.0.1:6379")}/{0}',
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
|
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
|
||||||
# Mimicing memcache behavior.
|
# Mimicing memcache behavior.
|
||||||
|
@ -62,7 +63,7 @@ X_FRAME_OPTIONS = 'DENY'
|
||||||
# STORAGES
|
# STORAGES
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# https://django-storages.readthedocs.io/en/latest/#installation
|
# https://django-storages.readthedocs.io/en/latest/#installation
|
||||||
INSTALLED_APPS += ['storages']
|
INSTALLED_APPS += ['storages'] # noqa F405
|
||||||
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
|
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
|
||||||
AWS_ACCESS_KEY_ID = env('DJANGO_AWS_ACCESS_KEY_ID')
|
AWS_ACCESS_KEY_ID = env('DJANGO_AWS_ACCESS_KEY_ID')
|
||||||
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
|
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
|
||||||
|
@ -77,7 +78,7 @@ AWS_QUERYSTRING_AUTH = False
|
||||||
_AWS_EXPIRY = 60 * 60 * 24 * 7
|
_AWS_EXPIRY = 60 * 60 * 24 * 7
|
||||||
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
|
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
|
||||||
AWS_S3_OBJECT_PARAMETERS = {
|
AWS_S3_OBJECT_PARAMETERS = {
|
||||||
'CacheControl': 'max-age=%d, s-maxage=%d, must-revalidate' % (_AWS_EXPIRY, _AWS_EXPIRY),
|
'CacheControl': f'max-age={_AWS_EXPIRY}, s-maxage={_AWS_EXPIRY}, must-revalidate',
|
||||||
}
|
}
|
||||||
|
|
||||||
# STATIC
|
# STATIC
|
||||||
|
@ -93,7 +94,7 @@ STATIC_URL = 'https://s3.amazonaws.com/%s/static/' % AWS_STORAGE_BUCKET_NAME
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
{% if cookiecutter.use_whitenoise == 'y' -%}
|
{% if cookiecutter.use_whitenoise == 'y' -%}
|
||||||
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
|
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
|
||||||
MEDIA_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME
|
MEDIA_URL = f'https://s3.amazonaws.com/{AWS_STORAGE_BUCKET_NAME}/'
|
||||||
{%- else %}
|
{%- else %}
|
||||||
# region http://stackoverflow.com/questions/10390244/
|
# region http://stackoverflow.com/questions/10390244/
|
||||||
from storages.backends.s3boto3 import S3Boto3Storage
|
from storages.backends.s3boto3 import S3Boto3Storage
|
||||||
|
@ -101,13 +102,13 @@ StaticRootS3BotoStorage = lambda: S3Boto3Storage(location='static') # noqa
|
||||||
MediaRootS3BotoStorage = lambda: S3Boto3Storage(location='media', file_overwrite=False) # noqa
|
MediaRootS3BotoStorage = lambda: S3Boto3Storage(location='media', file_overwrite=False) # noqa
|
||||||
# endregion
|
# endregion
|
||||||
DEFAULT_FILE_STORAGE = 'config.settings.production.MediaRootS3BotoStorage'
|
DEFAULT_FILE_STORAGE = 'config.settings.production.MediaRootS3BotoStorage'
|
||||||
MEDIA_URL = 'https://s3.amazonaws.com/%s/media/' % AWS_STORAGE_BUCKET_NAME
|
MEDIA_URL = f'https://s3.amazonaws.com/{AWS_STORAGE_BUCKET_NAME}/media/'
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
# TEMPLATES
|
# TEMPLATES
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# https://docs.djangoproject.com/en/dev/ref/settings/#templates
|
# https://docs.djangoproject.com/en/dev/ref/settings/#templates
|
||||||
TEMPLATES[0]['OPTIONS']['loaders'] = [
|
TEMPLATES[0]['OPTIONS']['loaders'] = [ # noqa F405
|
||||||
(
|
(
|
||||||
'django.template.loaders.cached.Loader',
|
'django.template.loaders.cached.Loader',
|
||||||
[
|
[
|
||||||
|
@ -137,7 +138,7 @@ ADMIN_URL = env('DJANGO_ADMIN_URL')
|
||||||
# Anymail (Mailgun)
|
# Anymail (Mailgun)
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# https://anymail.readthedocs.io/en/stable/installation/#installing-anymail
|
# https://anymail.readthedocs.io/en/stable/installation/#installing-anymail
|
||||||
INSTALLED_APPS += ['anymail']
|
INSTALLED_APPS += ['anymail'] # noqa F405
|
||||||
EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend'
|
EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend'
|
||||||
# https://anymail.readthedocs.io/en/stable/installation/#anymail-settings-reference
|
# https://anymail.readthedocs.io/en/stable/installation/#anymail-settings-reference
|
||||||
ANYMAIL = {
|
ANYMAIL = {
|
||||||
|
@ -147,13 +148,13 @@ ANYMAIL = {
|
||||||
|
|
||||||
# Gunicorn
|
# Gunicorn
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
INSTALLED_APPS += ['gunicorn']
|
INSTALLED_APPS += ['gunicorn'] # noqa F405
|
||||||
|
|
||||||
{% if cookiecutter.use_whitenoise == 'y' -%}
|
{% if cookiecutter.use_whitenoise == 'y' -%}
|
||||||
# WhiteNoise
|
# WhiteNoise
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# http://whitenoise.evans.io/en/latest/django.html#enable-whitenoise
|
# http://whitenoise.evans.io/en/latest/django.html#enable-whitenoise
|
||||||
MIDDLEWARE = ['whitenoise.middleware.WhiteNoiseMiddleware'] + MIDDLEWARE
|
MIDDLEWARE = ['whitenoise.middleware.WhiteNoiseMiddleware'] + MIDDLEWARE # noqa F405
|
||||||
|
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{% if cookiecutter.use_compressor == 'y' -%}
|
{% if cookiecutter.use_compressor == 'y' -%}
|
||||||
|
@ -171,7 +172,7 @@ COMPRESS_URL = STATIC_URL
|
||||||
# Collectfast
|
# Collectfast
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# https://github.com/antonagestam/collectfast#installation
|
# https://github.com/antonagestam/collectfast#installation
|
||||||
INSTALLED_APPS = ['collectfast'] + INSTALLED_APPS
|
INSTALLED_APPS = ['collectfast'] + INSTALLED_APPS # noqa F405
|
||||||
AWS_PRELOAD_METADATA = True
|
AWS_PRELOAD_METADATA = True
|
||||||
|
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
@ -179,7 +180,7 @@ AWS_PRELOAD_METADATA = True
|
||||||
# raven
|
# raven
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# https://docs.sentry.io/clients/python/integrations/django/
|
# https://docs.sentry.io/clients/python/integrations/django/
|
||||||
INSTALLED_APPS += ['raven.contrib.django.raven_compat']
|
INSTALLED_APPS += ['raven.contrib.django.raven_compat'] # noqa F405
|
||||||
MIDDLEWARE = ['raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware'] + MIDDLEWARE
|
MIDDLEWARE = ['raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware'] + MIDDLEWARE
|
||||||
|
|
||||||
# Sentry
|
# Sentry
|
||||||
|
@ -293,7 +294,7 @@ LOGGING = {
|
||||||
# opbeat
|
# opbeat
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# https://opbeat.com/docs/articles/get-started-with-django/#setup
|
# https://opbeat.com/docs/articles/get-started-with-django/#setup
|
||||||
INSTALLED_APPS += ['opbeat.contrib.django']
|
INSTALLED_APPS += ['opbeat.contrib.django'] # noqa F405
|
||||||
# https://opbeat.com/docs/articles/get-started-with-django/#setup
|
# https://opbeat.com/docs/articles/get-started-with-django/#setup
|
||||||
OPBEAT = {
|
OPBEAT = {
|
||||||
'ORGANIZATION_ID': env('DJANGO_OPBEAT_ORGANIZATION_ID'),
|
'ORGANIZATION_ID': env('DJANGO_OPBEAT_ORGANIZATION_ID'),
|
||||||
|
|
|
@ -3,6 +3,7 @@ With these settings, tests run faster.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .base import * # noqa
|
from .base import * # noqa
|
||||||
|
from .base import env
|
||||||
|
|
||||||
# GENERAL
|
# GENERAL
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -33,8 +34,8 @@ PASSWORD_HASHERS = [
|
||||||
# TEMPLATES
|
# TEMPLATES
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# https://docs.djangoproject.com/en/dev/ref/settings/#templates
|
# https://docs.djangoproject.com/en/dev/ref/settings/#templates
|
||||||
TEMPLATES[0]['OPTIONS']['debug'] = DEBUG
|
TEMPLATES[0]['OPTIONS']['debug'] = DEBUG # noqa F405
|
||||||
TEMPLATES[0]['OPTIONS']['loaders'] = [
|
TEMPLATES[0]['OPTIONS']['loaders'] = [ # noqa F405
|
||||||
(
|
(
|
||||||
'django.template.loaders.cached.Loader',
|
'django.template.loaders.cached.Loader',
|
||||||
[
|
[
|
||||||
|
|
|
@ -66,7 +66,7 @@ class CeleryConfig(AppConfig):
|
||||||
try:
|
try:
|
||||||
opbeat_register_signal(opbeat_client)
|
opbeat_register_signal(opbeat_client)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
opbeat_logger.exception('Failed installing celery hook: %s' % e)
|
opbeat_logger.exception(f'Failed installing celery hook: {e}')
|
||||||
|
|
||||||
if 'opbeat.contrib.django' in settings.INSTALLED_APPS:
|
if 'opbeat.contrib.django' in settings.INSTALLED_APPS:
|
||||||
opbeat_register_handlers()
|
opbeat_register_handlers()
|
||||||
|
@ -75,7 +75,7 @@ class CeleryConfig(AppConfig):
|
||||||
|
|
||||||
@app.task(bind=True)
|
@app.task(bind=True)
|
||||||
def debug_task(self):
|
def debug_task(self):
|
||||||
print('Request: {0!r}'.format(self.request)) # pragma: no cover
|
print(f'Request: {self.request!r}') # pragma: no cover
|
||||||
{% else %}
|
{% else %}
|
||||||
# Use this as a starting point for your project with celery.
|
# Use this as a starting point for your project with celery.
|
||||||
# If you are not using celery, you can remove this app
|
# If you are not using celery, you can remove this app
|
||||||
|
|
|
@ -2,8 +2,8 @@ import factory
|
||||||
|
|
||||||
|
|
||||||
class UserFactory(factory.django.DjangoModelFactory):
|
class UserFactory(factory.django.DjangoModelFactory):
|
||||||
username = factory.Sequence(lambda n: 'user-{0}'.format(n))
|
username = factory.Sequence(lambda n: f'user-{n}')
|
||||||
email = factory.Sequence(lambda n: 'user-{0}@example.com'.format(n))
|
email = factory.Sequence(lambda n: f'user-{n}@example.com')
|
||||||
password = factory.PostGenerationMethodCall('set_password', 'password')
|
password = factory.PostGenerationMethodCall('set_password', 'password')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user