Upgrade to f-strings with 'flynt .'

This commit is contained in:
Hugo van Kemenade 2022-06-15 15:52:56 +03:00
parent 165ffd0b15
commit 9455b36281
6 changed files with 7 additions and 7 deletions

View file

@ -144,7 +144,7 @@ class TemplateAdmin(TemplateModelAdmin):
for template in queryset:
valid, error = check_template_syntax(template)
if not valid:
errors.append('{}: {}'.format(template.name, error))
errors.append(f'{template.name}: {error}')
if errors:
count = len(errors)
message = ungettext(

View file

@ -33,7 +33,7 @@ class Loader(BaseLoader):
def _load_and_store_template(self, template_name, cache_key, site, **params):
template = Template.objects.get(name__exact=template_name, **params)
db = router.db_for_read(Template, instance=template)
display_name = 'dbtemplates:{}:{}:{}'.format(db, template_name, site.domain)
display_name = f'dbtemplates:{db}:{template_name}:{site.domain}'
return set_and_return(cache_key, template.content, display_name)
def _load_template_source(self, template_name, template_dirs=None):

View file

@ -12,7 +12,7 @@ class Command(BaseCommand):
for template in Template.objects.all():
valid, error = check_template_syntax(template)
if not valid:
errors.append('{}: {}'.format(template.name, error))
errors.append(f'{template.name}: {error}')
if errors:
raise CommandError(
'Some templates contained errors\n%s' % '\n'.join(errors))

View file

@ -43,7 +43,7 @@ class Command(BaseCommand):
verbosity = int(options.get('verbosity', 1))
for error_code in (404, 500):
template, created = Template.objects.get_or_create(
name="%s.html" % error_code)
name=f"{error_code}.html")
if created or (not created and force):
template.content = TEMPLATES.get(error_code, '')
template.save()

View file

@ -52,7 +52,7 @@ class Command(BaseCommand):
delete = options.get('delete')
if not extension.startswith("."):
extension = ".%s" % extension
extension = f".{extension}"
try:
site = Site.objects.get_current()
@ -110,7 +110,7 @@ class Command(BaseCommand):
os.remove(path)
except OSError:
raise CommandError(
"Couldn't delete %s" % path)
f"Couldn't delete {path}")
elif confirm == DATABASE_TO_FILES:
with open(path, 'w', encoding='utf-8') as f:
f.write(t.content)

View file

@ -28,7 +28,7 @@ cache = get_cache_backend()
def get_cache_key(name):
current_site = Site.objects.get_current()
return 'dbtemplates::{}::{}'.format(slugify(name), current_site.pk)
return f'dbtemplates::{slugify(name)}::{current_site.pk}'
def get_cache_notfound_key(name):