Bug fixes:

1) Only reset to initial values when None is assigned. Using 'if not var' is true for empty lists
2) Take unused values out of the to_html and unicode functions
3) add 'language' as a valid metadata field
This commit is contained in:
Charles Haley 2010-08-27 10:26:36 +01:00
parent b04faf70c2
commit 47fedcee36
2 changed files with 42 additions and 57 deletions

View File

@ -11,50 +11,39 @@ an empty list/dictionary for complex types and (None, None) for cover_data
''' '''
SOCIAL_METADATA_FIELDS = frozenset([ SOCIAL_METADATA_FIELDS = frozenset([
'tags', # Ordered list 'tags', # Ordered list
# A floating point number between 0 and 10 'rating', # A floating point number between 0 and 10
'rating', 'comments', # A simple HTML enabled string
# A simple HTML enabled string 'series', # A simple string
'comments', 'series_index', # A floating point number
# A simple string
'series',
# A floating point number
'series_index',
# Of the form { scheme1:value1, scheme2:value2} # Of the form { scheme1:value1, scheme2:value2}
# For example: {'isbn':'123456789', 'doi':'xxxx', ... } # For example: {'isbn':'123456789', 'doi':'xxxx', ... }
'classifiers', 'classifiers',
'isbn', # Pseudo field for convenience, should get/set isbn classifier 'isbn', # Pseudo field for convenience, should get/set isbn classifier
# TODO: not sure what this is, but it is used by OPF 'category', # TODO: not sure what this is, but it is used by OPF
'category',
]) ])
PUBLICATION_METADATA_FIELDS = frozenset([ PUBLICATION_METADATA_FIELDS = frozenset([
# title must never be None. Should be _('Unknown') 'title', # title must never be None. Should be _('Unknown')
'title',
# Pseudo field that can be set, but if not set is auto generated # Pseudo field that can be set, but if not set is auto generated
# from title and languages # from title and languages
'title_sort', 'title_sort',
# Ordered list of authors. Must never be None, can be [_('Unknown')] 'authors', # Ordered list. Must never be None, can be [_('Unknown')]
'authors', 'author_sort_map', # Map of sort strings for each author
# Map of sort strings for each author
'author_sort_map',
# Pseudo field that can be set, but if not set is auto generated # Pseudo field that can be set, but if not set is auto generated
# from authors and languages # from authors and languages
'author_sort', 'author_sort',
'book_producer', 'book_producer',
# Dates and times must be timezone aware 'timestamp', # Dates and times must be timezone aware
'timestamp',
'pubdate', 'pubdate',
'rights', 'rights',
# So far only known publication type is periodical:calibre # So far only known publication type is periodical:calibre
# If None, means book # If None, means book
'publication_type', 'publication_type',
# A UUID usually of type 4 'uuid', # A UUID usually of type 4
'uuid', 'language', # the primary language of this book
'languages', # ordered list 'languages', # ordered list
# Simple string, no special semantics 'publisher', # Simple string, no special semantics
'publisher',
# Absolute path to image file encoded in filesystem_encoding # Absolute path to image file encoded in filesystem_encoding
'cover', 'cover',
# Of the form (format, data) where format is, for e.g. 'jpeg', 'png', 'gif'... # Of the form (format, data) where format is, for e.g. 'jpeg', 'png', 'gif'...
@ -77,22 +66,18 @@ USER_METADATA_FIELDS = frozenset([
]) ])
DEVICE_METADATA_FIELDS = frozenset([ DEVICE_METADATA_FIELDS = frozenset([
# Ordered list of strings 'device_collections', # Ordered list of strings
'device_collections', 'lpath', # Unicode, / separated
'lpath', # Unicode, / separated 'size', # In bytes
# In bytes 'mime', # Mimetype of the book file being represented
'size',
# Mimetype of the book file being represented
'mime',
]) ])
CALIBRE_METADATA_FIELDS = frozenset([ CALIBRE_METADATA_FIELDS = frozenset([
# An application id 'application_id', # An application id, currently set to the db_id.
# Semantics to be defined. Is it a db key? a db name + key? A uuid? # the calibre primary key of the item.
# (It is currently set to the db_id.) 'db_id', # the calibre primary key of the item.
'application_id', # TODO: May want to remove once Sony's no longer use it
# the calibre primary key of the item. May want to remove this once Sony's no longer use it
'db_id',
] ]
) )
@ -124,7 +109,4 @@ SERIALIZABLE_FIELDS = SOCIAL_METADATA_FIELDS.union(
CALIBRE_METADATA_FIELDS).union( CALIBRE_METADATA_FIELDS).union(
DEVICE_METADATA_FIELDS) - \ DEVICE_METADATA_FIELDS) - \
frozenset(['device_collections']) frozenset(['device_collections'])
# I don't think we need device_collections # device_collections is rebuilt when needed
# Serialization of covers/thumbnails will have to be handled carefully, maybe
# as an option to the serializer class

View File

@ -24,6 +24,7 @@ NULL_VALUES = {
'author_sort_map': {}, 'author_sort_map': {},
'authors' : [_('Unknown')], 'authors' : [_('Unknown')],
'title' : _('Unknown'), 'title' : _('Unknown'),
'language' : 'und'
} }
class Metadata(object): class Metadata(object):
@ -68,14 +69,14 @@ class Metadata(object):
def __setattr__(self, field, val): def __setattr__(self, field, val):
_data = object.__getattribute__(self, '_data') _data = object.__getattribute__(self, '_data')
if field in STANDARD_METADATA_FIELDS: if field in STANDARD_METADATA_FIELDS:
if not val: if val is None:
val = NULL_VALUES.get(field, None) val = NULL_VALUES.get(field, None)
_data[field] = val _data[field] = val
elif field in _data['user_metadata'].iterkeys(): elif field in _data['user_metadata'].iterkeys():
_data['user_metadata'][field]['#value#'] = val _data['user_metadata'][field]['#value#'] = val
else: else:
# You are allowed to stick arbitrary attributes onto this object as # You are allowed to stick arbitrary attributes onto this object as
# long as they dont conflict with global or user metadata names # long as they don't conflict with global or user metadata names
# Don't abuse this privilege # Don't abuse this privilege
self.__dict__[field] = val self.__dict__[field] = val
@ -294,12 +295,13 @@ class Metadata(object):
fmt('Published', isoformat(self.pubdate)) fmt('Published', isoformat(self.pubdate))
if self.rights is not None: if self.rights is not None:
fmt('Rights', unicode(self.rights)) fmt('Rights', unicode(self.rights))
if self.lccn: # TODO: These are not in metadata. Should they be?
fmt('LCCN', unicode(self.lccn)) # if self.lccn:
if self.lcc: # fmt('LCCN', unicode(self.lccn))
fmt('LCC', unicode(self.lcc)) # if self.lcc:
if self.ddc: # fmt('LCC', unicode(self.lcc))
fmt('DDC', unicode(self.ddc)) # if self.ddc:
# fmt('DDC', unicode(self.ddc))
# CUSTFIELD: What to do about custom fields? # CUSTFIELD: What to do about custom fields?
return u'\n'.join(ans) return u'\n'.join(ans)
@ -311,12 +313,13 @@ class Metadata(object):
ans += [(_('Producer'), unicode(self.book_producer))] ans += [(_('Producer'), unicode(self.book_producer))]
ans += [(_('Comments'), unicode(self.comments))] ans += [(_('Comments'), unicode(self.comments))]
ans += [('ISBN', unicode(self.isbn))] ans += [('ISBN', unicode(self.isbn))]
if self.lccn: # TODO: These are not in metadata. Should they be?
ans += [('LCCN', unicode(self.lccn))] # if self.lccn:
if self.lcc: # ans += [('LCCN', unicode(self.lccn))]
ans += [('LCC', unicode(self.lcc))] # if self.lcc:
if self.ddc: # ans += [('LCC', unicode(self.lcc))]
ans += [('DDC', unicode(self.ddc))] # if self.ddc:
# ans += [('DDC', unicode(self.ddc))]
ans += [(_('Tags'), u', '.join([unicode(t) for t in self.tags]))] ans += [(_('Tags'), u', '.join([unicode(t) for t in self.tags]))]
if self.series: if self.series:
ans += [(_('Series'), unicode(self.series)+ ' #%s'%self.format_series_index())] ans += [(_('Series'), unicode(self.series)+ ' #%s'%self.format_series_index())]