diff --git a/media/forms.py b/media/forms.py index d077219..a9fe699 100644 --- a/media/forms.py +++ b/media/forms.py @@ -4,6 +4,7 @@ import json import urllib.request +import unicodedata from django.forms import ModelForm @@ -102,8 +103,8 @@ class MediaAdminForm(ModelForm): if ',' not in author_name and ' ' in author_name: author_name = author_name.split(' ')[1] side_identifier = "{:.3} {:.3}".format( - author_name.upper(), - self.cleaned_data['title'].upper(), ) + author_name, + self.cleaned_data['title'], ) if self.cleaned_data['subtitle']: start = self.cleaned_data['subtitle'].split(' ')[0] \ @@ -112,6 +113,13 @@ class MediaAdminForm(ModelForm): if start.isnumeric(): side_identifier += " {:0>2}".format(start, ) + # Normalize side identifier, in order to remove accents + side_identifier = ''.join( + char + for char in unicodedata.normalize('NFKD', side_identifier.casefold()) + if all(not unicodedata.category(char).startswith(cat) + for cat in {'M', 'P', 'Z', 'C'}) or char == ' ' + ).casefold().upper() self.cleaned_data['side_identifier'] = side_identifier return self.cleaned_data