mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix handing of title_sort and custom columns when creating a BiBTeX catalg. Fixes #853249 (export bibitex error)
This commit is contained in:
commit
b2e794343f
@ -110,9 +110,9 @@
|
|||||||
<string>Some explanation about this template:
|
<string>Some explanation about this template:
|
||||||
-The fields availables are 'author_sort', 'authors', 'id',
|
-The fields availables are 'author_sort', 'authors', 'id',
|
||||||
'isbn', 'pubdate', 'publisher', 'series_index', 'series',
|
'isbn', 'pubdate', 'publisher', 'series_index', 'series',
|
||||||
'tags', 'timestamp', 'title', 'uuid'
|
'tags', 'timestamp', 'title', 'uuid', 'title_sort'
|
||||||
-For list types ie authors and tags, only the first element
|
-For list types ie authors and tags, only the first element
|
||||||
wil be selected.
|
will be selected.
|
||||||
-For time field, only the date will be used. </string>
|
-For time field, only the date will be used. </string>
|
||||||
</property>
|
</property>
|
||||||
<property name="scaledContents">
|
<property name="scaledContents">
|
||||||
|
@ -29,7 +29,7 @@ class PluginWidget(QWidget, Ui_Form):
|
|||||||
QListWidgetItem(x, self.db_fields)
|
QListWidgetItem(x, self.db_fields)
|
||||||
|
|
||||||
db = db_()
|
db = db_()
|
||||||
for x in sorted(db.custom_field_keys()):
|
for x in sorted(db.custom_field_keys()):
|
||||||
self.all_fields.append(x)
|
self.all_fields.append(x)
|
||||||
QListWidgetItem(x, self.db_fields)
|
QListWidgetItem(x, self.db_fields)
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ FIELDS = ['all', 'title', 'title_sort', 'author_sort', 'authors', 'comments',
|
|||||||
'rating', 'series_index', 'series', 'size', 'tags', 'timestamp', 'uuid']
|
'rating', 'series_index', 'series', 'size', 'tags', 'timestamp', 'uuid']
|
||||||
|
|
||||||
#Allowed fields for template
|
#Allowed fields for template
|
||||||
TEMPLATE_ALLOWED_FIELDS = [ 'author_sort', 'authors', 'id', 'isbn', 'pubdate',
|
TEMPLATE_ALLOWED_FIELDS = [ 'author_sort', 'authors', 'id', 'isbn', 'pubdate', 'title_sort',
|
||||||
'publisher', 'series_index', 'series', 'tags', 'timestamp', 'title', 'uuid' ]
|
'publisher', 'series_index', 'series', 'tags', 'timestamp', 'title', 'uuid' ]
|
||||||
|
|
||||||
class CSV_XML(CatalogPlugin): # {{{
|
class CSV_XML(CatalogPlugin): # {{{
|
||||||
@ -324,7 +324,7 @@ class BIBTEX(CatalogPlugin): # {{{
|
|||||||
def run(self, path_to_output, opts, db, notification=DummyReporter()):
|
def run(self, path_to_output, opts, db, notification=DummyReporter()):
|
||||||
|
|
||||||
def create_bibtex_entry(entry, fields, mode, template_citation,
|
def create_bibtex_entry(entry, fields, mode, template_citation,
|
||||||
bibtexdict, citation_bibtex=True, calibre_files=True):
|
bibtexdict, db, citation_bibtex=True, calibre_files=True):
|
||||||
|
|
||||||
#Bibtex doesn't like UTF-8 but keep unicode until writing
|
#Bibtex doesn't like UTF-8 but keep unicode until writing
|
||||||
#Define starting chain or if book valid strict and not book return a Fail string
|
#Define starting chain or if book valid strict and not book return a Fail string
|
||||||
@ -345,7 +345,13 @@ class BIBTEX(CatalogPlugin): # {{{
|
|||||||
bibtex_entry = [u' '.join(bibtex_entry)]
|
bibtex_entry = [u' '.join(bibtex_entry)]
|
||||||
|
|
||||||
for field in fields:
|
for field in fields:
|
||||||
item = entry[field]
|
if field.startswith('#'):
|
||||||
|
item = db.get_field(entry['id'],field,index_is_id=True)
|
||||||
|
elif field == 'title_sort':
|
||||||
|
item = entry['sort']
|
||||||
|
else:
|
||||||
|
item = entry[field]
|
||||||
|
|
||||||
#check if the field should be included (none or empty)
|
#check if the field should be included (none or empty)
|
||||||
if item is None:
|
if item is None:
|
||||||
continue
|
continue
|
||||||
@ -358,10 +364,6 @@ class BIBTEX(CatalogPlugin): # {{{
|
|||||||
if field == 'authors' :
|
if field == 'authors' :
|
||||||
bibtex_entry.append(u'author = "%s"' % bibtexdict.bibtex_author_format(item))
|
bibtex_entry.append(u'author = "%s"' % bibtexdict.bibtex_author_format(item))
|
||||||
|
|
||||||
elif field in ['title', 'publisher', 'cover', 'uuid', 'ondevice',
|
|
||||||
'author_sort', 'series'] :
|
|
||||||
bibtex_entry.append(u'%s = "%s"' % (field, bibtexdict.utf8ToBibtex(item)))
|
|
||||||
|
|
||||||
elif field == 'id' :
|
elif field == 'id' :
|
||||||
bibtex_entry.append(u'calibreid = "%s"' % int(item))
|
bibtex_entry.append(u'calibreid = "%s"' % int(item))
|
||||||
|
|
||||||
@ -409,6 +411,14 @@ class BIBTEX(CatalogPlugin): # {{{
|
|||||||
bibtex_entry.append(u'year = "%s"' % item.year)
|
bibtex_entry.append(u'year = "%s"' % item.year)
|
||||||
bibtex_entry.append(u'month = "%s"' % bibtexdict.utf8ToBibtex(strftime("%b", item)))
|
bibtex_entry.append(u'month = "%s"' % bibtexdict.utf8ToBibtex(strftime("%b", item)))
|
||||||
|
|
||||||
|
elif field.startswith('#') :
|
||||||
|
bibtex_entry.append(u'%s = "%s"' % (field[1:], bibtexdict.utf8ToBibtex(item)))
|
||||||
|
|
||||||
|
else:
|
||||||
|
# elif field in ['title', 'publisher', 'cover', 'uuid', 'ondevice',
|
||||||
|
# 'author_sort', 'series', 'title_sort'] :
|
||||||
|
bibtex_entry.append(u'%s = "%s"' % (field, bibtexdict.utf8ToBibtex(item)))
|
||||||
|
|
||||||
bibtex_entry = u',\n '.join(bibtex_entry)
|
bibtex_entry = u',\n '.join(bibtex_entry)
|
||||||
bibtex_entry += u' }\n\n'
|
bibtex_entry += u' }\n\n'
|
||||||
|
|
||||||
@ -588,7 +598,7 @@ class BIBTEX(CatalogPlugin): # {{{
|
|||||||
|
|
||||||
for entry in data:
|
for entry in data:
|
||||||
outfile.write(create_bibtex_entry(entry, fields, bib_entry, template_citation,
|
outfile.write(create_bibtex_entry(entry, fields, bib_entry, template_citation,
|
||||||
bibtexc, citation_bibtex, addfiles_bibtex))
|
bibtexc, db, citation_bibtex, addfiles_bibtex))
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
class EPUB_MOBI(CatalogPlugin):
|
class EPUB_MOBI(CatalogPlugin):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user