mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Add API to get all data associated with a note including searchable_text
This commit is contained in:
parent
50019962b1
commit
8e8f038896
@ -972,6 +972,9 @@ class DB:
|
|||||||
def notes_for(self, field_name, item_id):
|
def notes_for(self, field_name, item_id):
|
||||||
return self.notes.get_note(self.conn, field_name, item_id) or ''
|
return self.notes.get_note(self.conn, field_name, item_id) or ''
|
||||||
|
|
||||||
|
def notes_data_for(self, field_name, item_id):
|
||||||
|
return self.notes.get_note_data(self.conn, field_name, item_id)
|
||||||
|
|
||||||
def set_notes_for(self, field, item_id, doc: str, searchable_text: str, resource_hashes, remove_unused_resources) -> int:
|
def set_notes_for(self, field, item_id, doc: str, searchable_text: str, resource_hashes, remove_unused_resources) -> int:
|
||||||
id_val = self.tables[field].id_map[item_id]
|
id_val = self.tables[field].id_map[item_id]
|
||||||
note_id = self.notes.set_note(self.conn, field, item_id, id_val, doc, resource_hashes, searchable_text)
|
note_id = self.notes.set_note(self.conn, field, item_id, id_val, doc, resource_hashes, searchable_text)
|
||||||
|
@ -680,6 +680,11 @@ class Cache:
|
|||||||
def notes_for(self, field, item_id) -> str:
|
def notes_for(self, field, item_id) -> str:
|
||||||
return self.backend.notes_for(field, item_id)
|
return self.backend.notes_for(field, item_id)
|
||||||
|
|
||||||
|
@read_api
|
||||||
|
def notes_data_for(self, field, item_id) -> str:
|
||||||
|
' Return all notes data as a dict or None if note does not exist '
|
||||||
|
return self.backend.notes_data_for(field, item_id)
|
||||||
|
|
||||||
@write_api
|
@write_api
|
||||||
def set_notes_for(self, field, item_id, doc: str, searchable_text: str = copy_marked_up_text, resource_hashes=(), remove_unused_resources=False) -> int:
|
def set_notes_for(self, field, item_id, doc: str, searchable_text: str = copy_marked_up_text, resource_hashes=(), remove_unused_resources=False) -> int:
|
||||||
return self.backend.set_notes_for(field, item_id, doc, searchable_text, resource_hashes, remove_unused_resources)
|
return self.backend.set_notes_for(field, item_id, doc, searchable_text, resource_hashes, remove_unused_resources)
|
||||||
|
@ -64,6 +64,8 @@ def test_cache_api(self: 'NotesTest'):
|
|||||||
h1 = cache.add_notes_resource(b'resource1', 'r1.jpg')
|
h1 = cache.add_notes_resource(b'resource1', 'r1.jpg')
|
||||||
h2 = cache.add_notes_resource(b'resource2', 'r1.jpg')
|
h2 = cache.add_notes_resource(b'resource2', 'r1.jpg')
|
||||||
cache.set_notes_for('authors', author_id, doc, resource_hashes=(h1, h2))
|
cache.set_notes_for('authors', author_id, doc, resource_hashes=(h1, h2))
|
||||||
|
nd = cache.notes_data_for('authors', author_id)
|
||||||
|
self.ae(nd, {'id': 1, 'searchable_text': authors[0] + '\n' + doc, 'doc': doc, 'resource_hashes': frozenset({h1, h2})})
|
||||||
# test renaming to a new author preserves notes
|
# test renaming to a new author preserves notes
|
||||||
cache.rename_items('authors', {author_id: 'renamed author'})
|
cache.rename_items('authors', {author_id: 'renamed author'})
|
||||||
raid = cache.get_item_id('authors', 'renamed author')
|
raid = cache.get_item_id('authors', 'renamed author')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user