mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make series column editable and html2oeb a little more robust
This commit is contained in:
parent
d373ae7d13
commit
9b365f0a9c
@ -253,7 +253,7 @@ class OPF(MetaInformation):
|
||||
role = elem.get('opf:role')
|
||||
if not role:
|
||||
role = 'aut'
|
||||
if role == 'aut':
|
||||
if role == 'aut' and elem.string:
|
||||
raw = self.ENTITY_PATTERN.sub(entity_to_unicode, elem.string)
|
||||
au = raw.split(',')
|
||||
ans = []
|
||||
@ -293,13 +293,13 @@ class OPF(MetaInformation):
|
||||
|
||||
def get_category(self):
|
||||
category = self.soup.find('dc:type')
|
||||
if category:
|
||||
if category and category.string:
|
||||
return self.ENTITY_PATTERN.sub(entity_to_unicode, category.string).strip()
|
||||
return None
|
||||
|
||||
def get_publisher(self):
|
||||
publisher = self.soup.find('dc:publisher')
|
||||
if publisher:
|
||||
if publisher and publisher.string:
|
||||
return self.ENTITY_PATTERN.sub(entity_to_unicode, publisher.string).strip()
|
||||
return None
|
||||
|
||||
@ -308,7 +308,7 @@ class OPF(MetaInformation):
|
||||
scheme = item.get('scheme')
|
||||
if not scheme:
|
||||
scheme = item.get('opf:scheme')
|
||||
if scheme is not None and scheme.lower() == 'isbn':
|
||||
if scheme is not None and scheme.lower() == 'isbn' and item.string:
|
||||
return str(item.string).strip()
|
||||
return None
|
||||
|
||||
@ -353,7 +353,7 @@ class OPF(MetaInformation):
|
||||
|
||||
def get_series_index(self):
|
||||
s = self.soup.package.metadata.find('series-index')
|
||||
if s:
|
||||
if s and s.string:
|
||||
try:
|
||||
return int(str(s.string).strip())
|
||||
except:
|
||||
@ -365,7 +365,7 @@ class OPF(MetaInformation):
|
||||
if not xm:
|
||||
return None
|
||||
s = xm.find('rating')
|
||||
if s:
|
||||
if s and s.string:
|
||||
try:
|
||||
return int(str(s.string).strip())
|
||||
except:
|
||||
|
@ -1,6 +1,6 @@
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
import os, textwrap, traceback, time
|
||||
import os, textwrap, traceback, time, re
|
||||
from datetime import timedelta, datetime
|
||||
from operator import attrgetter
|
||||
|
||||
@ -100,7 +100,7 @@ class BooksModel(QAbstractTableModel):
|
||||
QAbstractTableModel.__init__(self, parent)
|
||||
self.db = None
|
||||
self.cols = ['title', 'authors', 'size', 'date', 'rating', 'publisher', 'tags', 'series']
|
||||
self.editable_cols = [0, 1, 4, 5, 6]
|
||||
self.editable_cols = [0, 1, 4, 5, 6, 7]
|
||||
self.default_image = QImage(':/images/book.svg')
|
||||
self.sorted_on = (3, Qt.AscendingOrder)
|
||||
self.last_search = '' # The last search performed on this model
|
||||
@ -433,8 +433,19 @@ class BooksModel(QAbstractTableModel):
|
||||
if col == 4:
|
||||
val = 0 if val < 0 else 5 if val > 5 else val
|
||||
val *= 2
|
||||
column = self.cols[col]
|
||||
self.db.set(row, column, val)
|
||||
if col == 7:
|
||||
pat = re.compile(r'\[(\d+)\]')
|
||||
match = pat.search(val)
|
||||
id = self.db.id(row)
|
||||
if match is not None:
|
||||
self.db.set_series_index(id, int(match.group(1)))
|
||||
val = pat.sub('', val)
|
||||
val = val.strip()
|
||||
if val:
|
||||
self.db.set_series(id, val)
|
||||
else:
|
||||
column = self.cols[col]
|
||||
self.db.set(row, column, val)
|
||||
self.emit(SIGNAL("dataChanged(QModelIndex, QModelIndex)"), \
|
||||
index, index)
|
||||
if col == self.sorted_on[0]:
|
||||
|
@ -822,17 +822,18 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
'''
|
||||
Rebuild self.data and self.cache. Filter results are lost.
|
||||
'''
|
||||
FIELDS = {'title' : 'sort',
|
||||
'authors': 'author_sort',
|
||||
'publisher': 'publisher',
|
||||
'size': 'size',
|
||||
'date': 'timestamp',
|
||||
'timestamp':'timestamp',
|
||||
'formats':'formats',
|
||||
'rating': 'rating',
|
||||
'tags':'tags',
|
||||
'series': 'series',
|
||||
}
|
||||
FIELDS = {
|
||||
'title' : 'sort',
|
||||
'authors' : 'author_sort',
|
||||
'publisher' : 'publisher',
|
||||
'size' : 'size',
|
||||
'date' : 'timestamp',
|
||||
'timestamp' : 'timestamp',
|
||||
'formats' : 'formats',
|
||||
'rating' : 'rating',
|
||||
'tags' : 'tags',
|
||||
'series' : 'series',
|
||||
}
|
||||
field = FIELDS[sort_field]
|
||||
order = 'ASC'
|
||||
if not ascending:
|
||||
@ -894,6 +895,11 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
|
||||
def id(self, index):
|
||||
return self.data[index][0]
|
||||
|
||||
def row(self, id):
|
||||
for r, record in enumerate(self.data):
|
||||
if record[0] == id:
|
||||
return r
|
||||
|
||||
def title(self, index, index_is_id=False):
|
||||
if not index_is_id:
|
||||
@ -1212,6 +1218,9 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
aid = self.conn.execute('INSERT INTO series(name) VALUES (?)', (series,)).lastrowid
|
||||
self.conn.execute('INSERT INTO books_series_link(book, series) VALUES (?,?)', (id, aid))
|
||||
self.conn.commit()
|
||||
row = self.row(id)
|
||||
if row is not None:
|
||||
self.data[row][9] = series
|
||||
|
||||
def remove_unused_series(self):
|
||||
for id, in self.conn.execute('SELECT id FROM series').fetchall():
|
||||
@ -1222,6 +1231,9 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
def set_series_index(self, id, idx):
|
||||
self.conn.execute('UPDATE books SET series_index=? WHERE id=?', (int(idx), id))
|
||||
self.conn.commit()
|
||||
row = self.row(id)
|
||||
if row is not None:
|
||||
self.data[row][10] = idx
|
||||
|
||||
def set_rating(self, id, rating):
|
||||
rating = int(rating)
|
||||
|
Loading…
x
Reference in New Issue
Block a user