EPUB metadata: When setting authors, always move the new dc:creator element to the top so broken implementations don't get confused and make their anonymous creators look like fools

This commit is contained in:
Kovid Goyal 2010-05-21 22:31:38 -06:00
parent 7266cdd3c4
commit 7e56edf946

View File

@ -669,10 +669,19 @@ class OPF(object):
remove = list(self.authors_path(self.metadata))
for elem in remove:
elem.getparent().remove(elem)
elems = []
for author in val:
attrib = {'{%s}role'%self.NAMESPACES['opf']: 'aut'}
elem = self.create_metadata_element('creator', attrib=attrib)
self.set_text(elem, author.strip())
# Ensure new author element is at the top of the list
# for broken implementations that always use the first
# <dc:creator> element with no attention to the role
elems.append(elem)
for elem in reversed(elems):
parent = elem.getparent()
parent.remove(elem)
parent.insert(0, elem)
return property(fget=fget, fset=fset)