diff options
author | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-08-21 11:18:47 +0200 |
---|---|---|
committer | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-08-21 11:25:44 +0200 |
commit | aab70b0222c90d5a852c1d465be35f9591d4a48c (patch) | |
tree | 8f22cf3cb83445c91606171639712407c1d644cb | |
parent | 37efed8d30888d36461270a8c8d6d7f630c3a982 (diff) |
views: remove accents in image name
Remove accents in image name string. Special characters are not
supported for image names.
-rw-r--r-- | ogcp/views.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/ogcp/views.py b/ogcp/views.py index f964c1e..8b544eb 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -30,6 +30,7 @@ from ogcp.og_server import OGServer, servers from flask_babel import lazy_gettext as _l from flask_babel import gettext, _ from ogcp import app, ogcp_cfg_path +import unicodedata import ipaddress import requests import datetime @@ -123,6 +124,10 @@ def is_valid_ip(ip): return False return True +def remove_accents(text): + normalized_text = unicodedata.normalize('NFD', text) + return ''.join(c for c in normalized_text if unicodedata.category(c) != 'Mn') + def ogserver_down(view): flash(_('Cannot talk to ogserver. Is ogserver down?'), category='error') return redirect(url_for(view)) @@ -2380,7 +2385,7 @@ def action_image_create(): if r.status_code != requests.codes.ok: return ogserver_error('commands') - image_name = form.name.data.strip() + image_name = remove_accents(form.name.data.strip()) if ' ' in image_name: flash(_('No spaces allowed in image names'), category='error') return redirect(url_for('commands')) |