Skip to content

Commit

Permalink
Move to f-strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Natim committed Apr 10, 2020
1 parent d771a21 commit b74c54c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
22 changes: 10 additions & 12 deletions tinymce/compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,41 +97,39 @@ def gzip_compressor(request):
'base': tinymce.settings.JS_BASE_URL,
'suffix': '',
}
content.append('var tinyMCEPreInit={!s};'.format(
json.dumps(tinyMCEPreInit)
))
content.append(f'var tinyMCEPreInit={json.dumps(tinyMCEPreInit)};')

# Add core
files = ['tiny_mce']

# Add core languages
for lang in languages:
files.append('langs/{!s}'.format(lang))
files.append(f'langs/{lang}')

# Add plugins
for plugin in plugins:
files.append('plugins/{!s}/editor_plugin{!s}'.format(plugin, suffix))
files.append(f'plugins/{plugin}/editor_plugin{suffix}')

for lang in languages:
files.append('plugins/{!s}/langs/{!s}'.format(plugin, lang))
files.append(f'plugins/{plugin}/langs/{lang}')

# Add themes
for theme in themes:
files.append('themes/{!s}/editor_template{!s}'.format(theme, suffix))
files.append(f'themes/{theme}/editor_template{suffix}')

for lang in languages:
files.append('themes/{!s}/langs/{!s}'.format(theme, lang))
files.append(f'themes/{theme}/langs/{lang}')

for f in files:
# Check for unsafe characters
if not safe_filename_re.match(f):
continue
content.append(get_file_contents('{!s}.js'.format(f)))
content.append(get_file_contents(f'{f}.js'))

# Restore loading functions
content.append('tinymce.each("{!s}".split(","), function(f){{'
content.append(f'tinymce.each("{",".join(files)}".split(","), function(f){{'
'tinymce.ScriptLoader.markDone(tinyMCE.baseURL+'
'"/"+f+".js");}});'.format(','.join(files)))
'"/"+f+".js");}});')

unicode_content = []
for i, c in enumerate(content):
Expand All @@ -144,7 +142,7 @@ def gzip_compressor(request):
try:
unicode_content.append(c.decode('utf-8'))
except Exception:
print('{!s} is nor latin-1 nor utf-8.'.format(files[i]))
print(f'{files[i]} is nor latin-1 nor utf-8.')
raise

# Compress
Expand Down
2 changes: 1 addition & 1 deletion tinymce/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
except AppRegistryNotReady:
JS_ROOT = getattr(settings, 'TINYMCE_JS_ROOT', os.path.join(settings.STATIC_ROOT, 'tiny_mce'))
else:
JS_URL = getattr(settings, 'TINYMCE_JS_URL', '{!s}js/tiny_mce/tiny_mce.js'.format(settings.MEDIA_URL))
JS_URL = getattr(settings, 'TINYMCE_JS_URL', f'{settings.MEDIA_URL}js/tiny_mce/tiny_mce.js')
JS_ROOT = getattr(settings, 'TINYMCE_JS_ROOT', os.path.join(settings.MEDIA_ROOT, 'js/tiny_mce'))

JS_BASE_URL = JS_URL[:JS_URL.rfind('/')]
6 changes: 3 additions & 3 deletions tinymce/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def spell_check(request):
arg = params[1]

if not enchant.dict_exists(str(lang)):
raise RuntimeError("dictionary not found for language {!r}".format(lang))
raise RuntimeError(f"dictionary not found for language {lang}")

checker = enchant.Dict(str(lang))

Expand All @@ -56,7 +56,7 @@ def spell_check(request):
elif method == 'getSuggestions':
result = checker.suggest(arg)
else:
raise RuntimeError("Unknown spellcheck method: {!r}".format(method))
raise RuntimeError(f"Unknown spellcheck method: {method}")
output = {
'id': id,
'result': result,
Expand Down Expand Up @@ -105,7 +105,7 @@ def render_to_image_list(image_list):


def render_to_js_vardef(var_name, var_value):
output = "var {!s} = {!s};".format(var_name, json.dumps(var_value))
output = f"var {var_name} = {json.dumps(var_value)};"
return HttpResponse(output, content_type='application/x-javascript')


Expand Down
4 changes: 2 additions & 2 deletions tinymce/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def render(self, name, value, attrs=None, renderer=None):
}
final_attrs['data-mce-gz-conf'] = json.dumps(compressor_config)
final_attrs['data-mce-conf'] = mce_json
html = ['<textarea{!s}>{!s}</textarea>'.format(flatatt(final_attrs), escape(value))]
html = [f'<textarea{flatatt(final_attrs)}>{escape(value)}</textarea>']
return mark_safe('\n'.join(html))

def _media(self):
Expand Down Expand Up @@ -142,7 +142,7 @@ def get_language_config(content_language=None):
default = '+'
else:
default = ''
sp_langs.append('{!s}{!s}={!s}'.format(default, ' / '.join(names), lang))
sp_langs.append(f'{default}{" / ".join(names)}={lang}')

config['spellchecker_languages'] = ','.join(sp_langs)

Expand Down

0 comments on commit b74c54c

Please sign in to comment.