diff --git a/media/forms.py b/media/forms.py index 9aaf0bf..926a485 100644 --- a/media/forms.py +++ b/media/forms.py @@ -4,8 +4,8 @@ import json import re -import urllib.request import unicodedata +import urllib.request from django.forms import ModelForm @@ -103,16 +103,18 @@ class MediaAdminForm(ModelForm): self.download_data_openlibrary(isbn) if self.cleaned_data['title']: - self.cleaned_data['title'] = re.sub('\(AUT\) ', - '', self.cleaned_data['title']) + self.cleaned_data['title'] = re.sub(r'\(AUT\) ', + '', self.cleaned_data['title']) if self.cleaned_data['authors']: authors = self.cleaned_data['authors'] old_authors = authors.copy() + def sort(author): return str(-author.note) + "." \ + str(old_authors.index(author)) \ + "." + author.name + authors.sort(key=sort) author_name = self.cleaned_data['authors'][0].name if ',' not in author_name and ' ' in author_name: @@ -130,9 +132,9 @@ class MediaAdminForm(ModelForm): if self.cleaned_data['subtitle']: self.cleaned_data['subtitle'] = re.sub(r'', - '', self.cleaned_data['subtitle']) + '', self.cleaned_data['subtitle']) self.cleaned_data['subtitle'] = re.sub(r'', - '', self.cleaned_data['subtitle']) + '', self.cleaned_data['subtitle']) start = self.cleaned_data['subtitle'].split(' ')[0] \ .replace('.', '')