mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
New metadata:
1) remove 'category' from standard metadata fields 2) make isbn a classifier. Add ability to add more classifiers 3) fixup TODO: to make them easier to find.
This commit is contained in:
parent
a60d58f1c1
commit
65f8767057
@ -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
|
||||
|
@ -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
|
||||
]
|
||||
)
|
||||
|
||||
|
@ -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())]
|
||||
|
@ -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)
|
||||
|
@ -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 = {}
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user