Convert old-styled string formatting to f-string

This commit is contained in:
sfdye 2018-02-22 22:49:34 +08:00
parent f4cadeec97
commit 10e9d725ab
4 changed files with 10 additions and 10 deletions

View File

@ -23,7 +23,7 @@ if READ_DOT_ENV_FILE:
# that is to say variables from the .env files will only be used if not defined
# as environment variables.
env_file = str(ROOT_DIR.path('.env'))
print('Loading : {}'.format(env_file))
print(f'Loading : {env_file}')
env.read_env(env_file)
print('The .env file has been loaded. See base.py for more information')

View File

@ -104,13 +104,13 @@ AWS_QUERYSTRING_AUTH = False
AWS_EXPIRY = 60 * 60 * 24 * 7
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',
}
# URL that handles the media served from MEDIA_ROOT, used for managing
# stored files.
{% if cookiecutter.use_whitenoise == 'y' -%}
MEDIA_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME
MEDIA_URL = f'https://s3.amazonaws.com/{AWS_STORAGE_BUCKET_NAME}/'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
{% else %}
# See:http://stackoverflow.com/questions/10390244/
@ -119,7 +119,7 @@ StaticRootS3BotoStorage = lambda: S3Boto3Storage(location='static') # noqa
MediaRootS3BotoStorage = lambda: S3Boto3Storage(location='media', file_overwrite=False) # noqa
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 %}
# Static Assets
@ -127,7 +127,7 @@ MEDIA_URL = 'https://s3.amazonaws.com/%s/media/' % AWS_STORAGE_BUCKET_NAME
{% if cookiecutter.use_whitenoise == 'y' -%}
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
{% else %}
STATIC_URL = 'https://s3.amazonaws.com/%s/static/' % AWS_STORAGE_BUCKET_NAME
STATIC_URL = f'https://s3.amazonaws.com/{AWS_STORAGE_BUCKET_NAME}/static/'
STATICFILES_STORAGE = 'config.settings.production.StaticRootS3BotoStorage'
# See: https://github.com/antonagestam/collectfast
# For Django 1.7+, 'collectfast' should come before
@ -177,7 +177,7 @@ DATABASES['default']['ATOMIC_REQUESTS'] = True
# CACHING
# ------------------------------------------------------------------------------
REDIS_LOCATION = '{0}/{1}'.format(env('REDIS_URL', default='redis://127.0.0.1:6379'), 0)
REDIS_LOCATION = f'{env("REDIS_URL", default="redis://127.0.0.1:6379")}/{0}'
# Heroku URL does not pass the DB number, so we parse it in
CACHES = {

View File

@ -66,7 +66,7 @@ class CeleryConfig(AppConfig):
try:
opbeat_register_signal(opbeat_client)
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:
opbeat_register_handlers()
@ -75,7 +75,7 @@ class CeleryConfig(AppConfig):
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request)) # pragma: no cover
print(f'Request: {self.request!r}') # pragma: no cover
{% else %}
# Use this as a starting point for your project with celery.
# If you are not using celery, you can remove this app

View File

@ -2,8 +2,8 @@ import factory
class UserFactory(factory.django.DjangoModelFactory):
username = factory.Sequence(lambda n: 'user-{0}'.format(n))
email = factory.Sequence(lambda n: 'user-{0}@example.com'.format(n))
username = factory.Sequence(lambda n: f'user-{n}')
email = factory.Sequence(lambda n: f'user-{n}@example.com')
password = factory.PostGenerationMethodCall('set_password', 'password')
class Meta: