When automatically deleting news older than x days, only delete the book if it both has the tag News and the author calibre. This prevents accidental deletion of books tagged with News by the user.

This commit is contained in:
Kovid Goyal 2012-01-17 06:36:45 +05:30
parent 5c6016239a
commit 891c9b45af
2 changed files with 18 additions and 2 deletions

View File

@ -462,7 +462,7 @@ class Scheduler(QObject):
delta = timedelta(days=self.oldest) delta = timedelta(days=self.oldest)
try: try:
ids = list(self.db.tags_older_than(_('News'), ids = list(self.db.tags_older_than(_('News'),
delta)) delta, must_have_authors=['calibre']))
except: except:
# Happens if library is being switched # Happens if library is being switched
ids = [] ids = []

View File

@ -1925,7 +1925,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
############# End get_categories ############# End get_categories
def tags_older_than(self, tag, delta, must_have_tag=None): def tags_older_than(self, tag, delta, must_have_tag=None,
must_have_authors=None):
''' '''
Return the ids of all books having the tag ``tag`` that are older than Return the ids of all books having the tag ``tag`` that are older than
than the specified time. tag comparison is case insensitive. than the specified time. tag comparison is case insensitive.
@ -1934,6 +1935,9 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
the tag are returned. the tag are returned.
:param must_have_tag: If not None the list of matches will be :param must_have_tag: If not None the list of matches will be
restricted to books that have this tag restricted to books that have this tag
:param must_have_authors: A list of authors. If not None the list of
matches will be restricted to books that have these authors (case
insensitive).
''' '''
tag = tag.lower().strip() tag = tag.lower().strip()
mht = must_have_tag.lower().strip() if must_have_tag else None mht = must_have_tag.lower().strip() if must_have_tag else None
@ -1941,9 +1945,18 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
tindex = self.FIELD_MAP['timestamp'] tindex = self.FIELD_MAP['timestamp']
gindex = self.FIELD_MAP['tags'] gindex = self.FIELD_MAP['tags']
iindex = self.FIELD_MAP['id'] iindex = self.FIELD_MAP['id']
aindex = self.FIELD_MAP['authors']
mah = must_have_authors
if mah is not None:
mah = [x.replace(',', '|').lower() for x in mah]
mah = ','.join(mah)
for r in self.data._data: for r in self.data._data:
if r is not None: if r is not None:
if delta is None or (now - r[tindex]) > delta: if delta is None or (now - r[tindex]) > delta:
if mah:
authors = r[aindex] or ''
if authors.lower() != mah:
continue
tags = r[gindex] tags = r[gindex]
if tags: if tags:
tags = [x.strip() for x in tags.lower().split(',')] tags = [x.strip() for x in tags.lower().split(',')]
@ -3128,6 +3141,9 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
stream.seek(0) stream.seek(0)
mi = get_metadata(stream, format, use_libprs_metadata=False, mi = get_metadata(stream, format, use_libprs_metadata=False,
force_read_metadata=True) force_read_metadata=True)
# Force the author to calibre as the auto delete of old news checks for
# both the author==calibre and the tag News
mi.authors = ['calibre']
stream.seek(0) stream.seek(0)
if mi.series_index is None: if mi.series_index is None:
mi.series_index = self.get_next_series_num_for(mi.series) mi.series_index = self.get_next_series_num_for(mi.series)