mirror of
https://gitlab.crans.org/mediatek/med.git
synced 2024-12-24 17:42:23 +00:00
Remove special chars from side identifiers
This commit is contained in:
parent
e4d1ed852f
commit
dc23ac0396
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user