mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Content server: When adding books and a duplicate is suspected provide more information about what books match the duplicate
This commit is contained in:
parent
9536ffe8cd
commit
cc8918d470
@ -69,9 +69,12 @@ def cdb_add_book(ctx, rd, job_id, add_duplicates, filename, library_id):
|
|||||||
Add a file as a new book. The file contents must be in the body of the request.
|
Add a file as a new book. The file contents must be in the body of the request.
|
||||||
|
|
||||||
The response will also have the title/authors/languages read from the
|
The response will also have the title/authors/languages read from the
|
||||||
metadata of the file/filename. It will contain a `book_id` field specifying the id of the newly added book,
|
metadata of the file/filename. It will contain a `book_id` field specifying
|
||||||
or if add_duplicates is not specified and a duplicate was found, no book_id will be present. It will also
|
the id of the newly added book, or if add_duplicates is not specified and a
|
||||||
return the value of `job_id` as the `id` field and `filename` as the `filename` field.
|
duplicate was found, no book_id will be present, instead there will be a
|
||||||
|
`duplicates` field specifying the title and authors for all duplicate
|
||||||
|
matches. It will also return the value of `job_id` as the `id` field and
|
||||||
|
`filename` as the `filename` field.
|
||||||
'''
|
'''
|
||||||
db = get_db(ctx, rd, library_id)
|
db = get_db(ctx, rd, library_id)
|
||||||
if ctx.restriction_for(rd, db):
|
if ctx.restriction_for(rd, db):
|
||||||
@ -96,6 +99,8 @@ def cdb_add_book(ctx, rd, job_id, add_duplicates, filename, library_id):
|
|||||||
if ids:
|
if ids:
|
||||||
ans['book_id'] = ids[0]
|
ans['book_id'] = ids[0]
|
||||||
ctx.notify_changes(db.backend.library_path, books_added(ids))
|
ctx.notify_changes(db.backend.library_path, books_added(ids))
|
||||||
|
else:
|
||||||
|
ans['duplicates'] = [{'title': m.title, 'authors': m.authors} for m, _ in duplicates]
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,7 +71,10 @@ def list_added_book(container, data):
|
|||||||
|
|
||||||
|
|
||||||
def list_duplicate_book(container, container_id, job_id, data, file):
|
def list_duplicate_book(container, container_id, job_id, data, file):
|
||||||
container.appendChild(E.div(style="padding: 1rem 1ex", _('A book with the title "{0}" already exists in the library.').format(data.title)))
|
container.appendChild(E.div(
|
||||||
|
style="padding: 1rem 1ex",
|
||||||
|
_('A book with the title "{0}" already exists in the library.'
|
||||||
|
).format(data.title)))
|
||||||
b = create_button(_('Add anyway'), action=def():
|
b = create_button(_('Add anyway'), action=def():
|
||||||
c = get_job_container(container_id, job_id)
|
c = get_job_container(container_id, job_id)
|
||||||
clear(c)
|
clear(c)
|
||||||
@ -79,7 +82,20 @@ def list_duplicate_book(container, container_id, job_id, data, file):
|
|||||||
c.appendChild(w)
|
c.appendChild(w)
|
||||||
send_file(file, container_id, job_id, True)
|
send_file(file, container_id, job_id, True)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def list_duplicates():
|
||||||
|
ans = E.ol(style='margin-left: 2rem')
|
||||||
|
for item in data.duplicates:
|
||||||
|
ans.appendChild(E.li(_('{0} by {1}').format(item.title, ' & '.join(item.authors))))
|
||||||
|
return ans
|
||||||
|
|
||||||
container.appendChild(b)
|
container.appendChild(b)
|
||||||
|
container.appendChild(E.div(
|
||||||
|
style='margin: 1rem 1ex; border-top: solid 1px currentColor; padding-top: 1ex',
|
||||||
|
_('The book you are trying to add is:'), E.span(' ', E.b(data.title), ' ', _('by'), ' ', E.i(' & '.join(data.authors))),
|
||||||
|
_('. Books already in the library with that title are:'),
|
||||||
|
E.div(style='padding-top:1ex', list_duplicates())
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
def write_access_error(msg, xhr):
|
def write_access_error(msg, xhr):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user