From aab70b0222c90d5a852c1d465be35f9591d4a48c Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Wed, 21 Aug 2024 11:18:47 +0200 Subject: views: remove accents in image name Remove accents in image name string. Special characters are not supported for image names. --- ogcp/views.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'ogcp') 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')) -- cgit v1.2.3-18-g5258