mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
When keeping x periodical issues be a little more careful about what we delete
This commit is contained in:
parent
f962167b5c
commit
e16f04e7b7
@ -67,7 +67,8 @@ class FetchNewsAction(InterfaceAction):
|
|||||||
keep_issues = 0
|
keep_issues = 0
|
||||||
if keep_issues > 0:
|
if keep_issues > 0:
|
||||||
ids_with_tag = list(sorted(self.gui.library_view.model().
|
ids_with_tag = list(sorted(self.gui.library_view.model().
|
||||||
db.tags_older_than(arg['title'], None), reverse=True))
|
db.tags_older_than(arg['title'],
|
||||||
|
None, must_have_tag=_('News')), reverse=True))
|
||||||
ids_to_delete = ids_with_tag[keep_issues:]
|
ids_to_delete = ids_with_tag[keep_issues:]
|
||||||
if ids_to_delete:
|
if ids_to_delete:
|
||||||
self.gui.library_view.model().delete_books_by_id(ids_to_delete)
|
self.gui.library_view.model().delete_books_by_id(ids_to_delete)
|
||||||
|
@ -1503,25 +1503,30 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
|
|
||||||
############# End get_categories
|
############# End get_categories
|
||||||
|
|
||||||
def tags_older_than(self, tag, delta):
|
def tags_older_than(self, tag, delta, must_have_tag=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.
|
||||||
|
|
||||||
:param delta: A timedelta object or None. If None, then all ids with
|
:param delta: A timedelta object or None. If None, then all ids with
|
||||||
the tag are returned.
|
the tag are returned.
|
||||||
|
:param must_have_tag: If not None the list of matches will be
|
||||||
|
restricted to books that have this tag
|
||||||
'''
|
'''
|
||||||
tag = tag.lower().strip()
|
tag = tag.lower().strip()
|
||||||
|
mht = must_have_tag.lower().strip() if must_have_tag else None
|
||||||
now = nowf()
|
now = nowf()
|
||||||
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']
|
||||||
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:
|
||||||
tags = r[gindex]
|
tags = r[gindex]
|
||||||
if tags and tag in [x.strip() for x in
|
if tags:
|
||||||
tags.lower().split(',')]:
|
tags = [x.strip() for x in tags.lower().split(',')]
|
||||||
yield r[self.FIELD_MAP['id']]
|
if tag in tags and (mht is None or mht in tags):
|
||||||
|
yield r[iindex]
|
||||||
|
|
||||||
def get_next_series_num_for(self, series):
|
def get_next_series_num_for(self, series):
|
||||||
series_id = self.conn.get('SELECT id from series WHERE name=?',
|
series_id = self.conn.get('SELECT id from series WHERE name=?',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user