diff --git a/src/calibre/devices/usbms/books.py b/src/calibre/devices/usbms/books.py index e3c405ee4e..0efa507e09 100644 --- a/src/calibre/devices/usbms/books.py +++ b/src/calibre/devices/usbms/books.py @@ -135,6 +135,7 @@ class CollectionsBookList(BookList): elif isinstance(val, unicode): val = [val] for category in val: + # TODO: NEWMETA: format the custom fields if attr == 'tags' and len(category) > 1 and \ category[0] == '[' and category[-1] == ']': continue diff --git a/src/calibre/ebooks/metadata/book/__init__.py b/src/calibre/ebooks/metadata/book/__init__.py index fbcca79aba..47eb616394 100644 --- a/src/calibre/ebooks/metadata/book/__init__.py +++ b/src/calibre/ebooks/metadata/book/__init__.py @@ -19,8 +19,14 @@ SOCIAL_METADATA_FIELDS = frozenset([ # Of the form { scheme1:value1, scheme2:value2} # For example: {'isbn':'123456789', 'doi':'xxxx', ... } 'classifiers', - 'isbn', # Pseudo field for convenience, should get/set isbn classifier - 'category', # TODO: not sure what this is, but it is used by OPF +]) + +''' +The list of names that convert to classifiers when in get and set. +''' + +TOP_LEVEL_CLASSIFIERS = frozenset([ + 'isbn', ]) PUBLICATION_METADATA_FIELDS = frozenset([ @@ -77,7 +83,7 @@ CALIBRE_METADATA_FIELDS = frozenset([ 'application_id', # An application id, currently set to the db_id. # the calibre primary key of the item. 'db_id', # the calibre primary key of the item. - # TODO: May want to remove once Sony's no longer use it + # TODO: NEWMETA: May want to remove once Sony's no longer use it ] ) diff --git a/src/calibre/ebooks/metadata/book/base.py b/src/calibre/ebooks/metadata/book/base.py index a81ce46c34..6d89049bfb 100644 --- a/src/calibre/ebooks/metadata/book/base.py +++ b/src/calibre/ebooks/metadata/book/base.py @@ -11,6 +11,7 @@ import traceback from calibre import prints from calibre.ebooks.metadata.book import COPYABLE_METADATA_FIELDS from calibre.ebooks.metadata.book import STANDARD_METADATA_FIELDS +from calibre.ebooks.metadata.book import TOP_LEVEL_CLASSIFIERS from calibre.utils.date import isoformat @@ -55,6 +56,8 @@ class Metadata(object): def __getattribute__(self, field): _data = object.__getattribute__(self, '_data') + if field in TOP_LEVEL_CLASSIFIERS: + return _data.get('classifiers').get(field, None) if field in STANDARD_METADATA_FIELDS: return _data.get(field, None) try: @@ -68,7 +71,9 @@ class Metadata(object): def __setattr__(self, field, val, extra=None): _data = object.__getattribute__(self, '_data') - if field in STANDARD_METADATA_FIELDS: + if field in TOP_LEVEL_CLASSIFIERS: + _data['classifiers'].update({field: val}) + elif field in STANDARD_METADATA_FIELDS: if val is None: val = NULL_VALUES.get(field, None) _data[field] = val @@ -301,8 +306,6 @@ class Metadata(object): fmt('Publisher', self.publisher) if getattr(self, 'book_producer', False): fmt('Book Producer', self.book_producer) - if self.category: - fmt('Category', self.category) if self.comments: fmt('Comments', self.comments) if self.isbn: @@ -321,14 +324,7 @@ class Metadata(object): fmt('Published', isoformat(self.pubdate)) if self.rights is not None: fmt('Rights', unicode(self.rights)) -# TODO: These are not in metadata. Should they be? -# if self.lccn: -# fmt('LCCN', unicode(self.lccn)) -# if self.lcc: -# fmt('LCC', unicode(self.lcc)) -# if self.ddc: -# fmt('DDC', unicode(self.ddc)) - # CUSTFIELD: What to do about custom fields? + # TODO: NEWMETA: What to do about custom fields? return u'\n'.join(ans) def to_html(self): @@ -339,13 +335,6 @@ class Metadata(object): ans += [(_('Producer'), unicode(self.book_producer))] ans += [(_('Comments'), unicode(self.comments))] ans += [('ISBN', unicode(self.isbn))] -# TODO: These are not in metadata. Should they be? -# if self.lccn: -# ans += [('LCCN', unicode(self.lccn))] -# if self.lcc: -# ans += [('LCC', unicode(self.lcc))] -# if self.ddc: -# ans += [('DDC', unicode(self.ddc))] ans += [(_('Tags'), u', '.join([unicode(t) for t in self.tags]))] if self.series: ans += [(_('Series'), unicode(self.series)+ ' #%s'%self.format_series_index())] diff --git a/src/calibre/ebooks/metadata/opf2.py b/src/calibre/ebooks/metadata/opf2.py index 0ab6d3bbc0..54d97fc157 100644 --- a/src/calibre/ebooks/metadata/opf2.py +++ b/src/calibre/ebooks/metadata/opf2.py @@ -1188,7 +1188,7 @@ def metadata_to_opf(mi, as_string=True): factory(DC('contributor'), mi.book_producer, __appname__, 'bkp') if hasattr(mi.pubdate, 'isoformat'): factory(DC('date'), isoformat(mi.pubdate)) - if mi.category: + if hasattr(mi, 'category') and mi.category: factory(DC('type'), mi.category) if mi.comments: factory(DC('description'), mi.comments) diff --git a/src/calibre/gui2/dialogs/config/save_template.py b/src/calibre/gui2/dialogs/config/save_template.py index 2157d5b3bf..7e49e86d29 100644 --- a/src/calibre/gui2/dialogs/config/save_template.py +++ b/src/calibre/gui2/dialogs/config/save_template.py @@ -34,8 +34,8 @@ class SaveTemplate(QWidget, Ui_Form): self.option_name = name def validate(self): - # TODO: I haven't figured out how to get the custom columns into here, - # so for the moment make all templates valid. + # TODO: NEWMETA: I haven't figured out how to get the custom columns + # into here, so for the moment make all templates valid. return True # tmpl = preprocess_template(self.opt_template.text()) # fa = {} diff --git a/src/calibre/library/save_to_disk.py b/src/calibre/library/save_to_disk.py index 7a3515305b..963afd4085 100644 --- a/src/calibre/library/save_to_disk.py +++ b/src/calibre/library/save_to_disk.py @@ -131,7 +131,7 @@ def get_components(template, mi, id, timefmt='%b %Y', length=250, format_args['series_index'] = mi.format_series_index() else: template = re.sub(r'\{series_index[^}]*?\}', '', template) - ## TODO: format custom values. Check all the datatypes. + ## TODO: NEWMETA: format custom values. Check all the datatypes. if mi.rating is not None: format_args['rating'] = mi.format_rating()