Fix bug that caused error message when automatically sending news to device, if the news had been previously deleted

This commit is contained in:
Kovid Goyal 2008-12-05 15:37:49 -08:00
parent e48113d5a7
commit 9f5bf522bd
2 changed files with 7 additions and 1 deletions

View File

@ -755,6 +755,7 @@ class Main(MainWindow, Ui_MainWindow):
def sync_news(self):
if self.device_connected:
ids = list(dynamic.get('news_to_be_synced', set([])))
ids = [id for id in ids if self.library_view.model().db.has_id(id)]
files = [self.library_view.model().db.format(id, prefs['output_format'], index_is_id=True, as_file=True) for id in ids]
files = [f for f in files if f is not None]
metadata = self.library_view.model().get_metadata(ids, rows_are_ids=True)
@ -889,6 +890,7 @@ class Main(MainWindow, Ui_MainWindow):
self.job_exception(job)
return
id = self.library_view.model().add_news(pt.name, recipe)
self.library_view.model().reset()
sync = dynamic.get('news_to_be_synced', set([]))
sync.add(id)
dynamic.set('news_to_be_synced', sync)

View File

@ -232,6 +232,9 @@ class ResultCache(SearchQueryParser):
def row(self, id):
return self.index(id)
def has_id(self, id):
return self._data[id] is not None
def refresh_ids(self, conn, ids):
for id in ids:
self._data[id] = conn.get('SELECT * from meta WHERE id=?', (id,))[0]
@ -371,6 +374,7 @@ class LibraryDatabase2(LibraryDatabase):
self.index = self.data.index
self.refresh_ids = functools.partial(self.data.refresh_ids, self.conn)
self.row = self.data.row
self.has_id = self.data.has_id
self.refresh()
@ -589,7 +593,7 @@ class LibraryDatabase2(LibraryDatabase):
data = data.read()
p.loadFromData(data)
p.save(path)
def all_formats(self):
formats = self.conn.get('SELECT format from data')
if not formats: