views: remove accents in image name

Remove accents in image name string. Special characters are not
supported for image names.
master
Alejandro Sirgo Rica 2024-08-21 11:18:47 +02:00
parent 37efed8d30
commit aab70b0222
1 changed files with 6 additions and 1 deletions

View File

@ -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'))