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')
|
role = elem.get('opf:role')
|
||||||
if not role:
|
if not role:
|
||||||
role = 'aut'
|
role = 'aut'
|
||||||
if role == 'aut':
|
if role == 'aut' and elem.string:
|
||||||
raw = self.ENTITY_PATTERN.sub(entity_to_unicode, elem.string)
|
raw = self.ENTITY_PATTERN.sub(entity_to_unicode, elem.string)
|
||||||
au = raw.split(',')
|
au = raw.split(',')
|
||||||
ans = []
|
ans = []
|
||||||
@ -293,13 +293,13 @@ class OPF(MetaInformation):
|
|||||||
|
|
||||||
def get_category(self):
|
def get_category(self):
|
||||||
category = self.soup.find('dc:type')
|
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 self.ENTITY_PATTERN.sub(entity_to_unicode, category.string).strip()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_publisher(self):
|
def get_publisher(self):
|
||||||
publisher = self.soup.find('dc:publisher')
|
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 self.ENTITY_PATTERN.sub(entity_to_unicode, publisher.string).strip()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -308,7 +308,7 @@ class OPF(MetaInformation):
|
|||||||
scheme = item.get('scheme')
|
scheme = item.get('scheme')
|
||||||
if not scheme:
|
if not scheme:
|
||||||
scheme = item.get('opf: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 str(item.string).strip()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -353,7 +353,7 @@ class OPF(MetaInformation):
|
|||||||
|
|
||||||
def get_series_index(self):
|
def get_series_index(self):
|
||||||
s = self.soup.package.metadata.find('series-index')
|
s = self.soup.package.metadata.find('series-index')
|
||||||
if s:
|
if s and s.string:
|
||||||
try:
|
try:
|
||||||
return int(str(s.string).strip())
|
return int(str(s.string).strip())
|
||||||
except:
|
except:
|
||||||
@ -365,7 +365,7 @@ class OPF(MetaInformation):
|
|||||||
if not xm:
|
if not xm:
|
||||||
return None
|
return None
|
||||||
s = xm.find('rating')
|
s = xm.find('rating')
|
||||||
if s:
|
if s and s.string:
|
||||||
try:
|
try:
|
||||||
return int(str(s.string).strip())
|
return int(str(s.string).strip())
|
||||||
except:
|
except:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__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 datetime import timedelta, datetime
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ class BooksModel(QAbstractTableModel):
|
|||||||
QAbstractTableModel.__init__(self, parent)
|
QAbstractTableModel.__init__(self, parent)
|
||||||
self.db = None
|
self.db = None
|
||||||
self.cols = ['title', 'authors', 'size', 'date', 'rating', 'publisher', 'tags', 'series']
|
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.default_image = QImage(':/images/book.svg')
|
||||||
self.sorted_on = (3, Qt.AscendingOrder)
|
self.sorted_on = (3, Qt.AscendingOrder)
|
||||||
self.last_search = '' # The last search performed on this model
|
self.last_search = '' # The last search performed on this model
|
||||||
@ -433,6 +433,17 @@ class BooksModel(QAbstractTableModel):
|
|||||||
if col == 4:
|
if col == 4:
|
||||||
val = 0 if val < 0 else 5 if val > 5 else val
|
val = 0 if val < 0 else 5 if val > 5 else val
|
||||||
val *= 2
|
val *= 2
|
||||||
|
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]
|
column = self.cols[col]
|
||||||
self.db.set(row, column, val)
|
self.db.set(row, column, val)
|
||||||
self.emit(SIGNAL("dataChanged(QModelIndex, QModelIndex)"), \
|
self.emit(SIGNAL("dataChanged(QModelIndex, QModelIndex)"), \
|
||||||
|
@ -822,7 +822,8 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
|||||||
'''
|
'''
|
||||||
Rebuild self.data and self.cache. Filter results are lost.
|
Rebuild self.data and self.cache. Filter results are lost.
|
||||||
'''
|
'''
|
||||||
FIELDS = {'title' : 'sort',
|
FIELDS = {
|
||||||
|
'title' : 'sort',
|
||||||
'authors' : 'author_sort',
|
'authors' : 'author_sort',
|
||||||
'publisher' : 'publisher',
|
'publisher' : 'publisher',
|
||||||
'size' : 'size',
|
'size' : 'size',
|
||||||
@ -895,6 +896,11 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
|||||||
def id(self, index):
|
def id(self, index):
|
||||||
return self.data[index][0]
|
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):
|
def title(self, index, index_is_id=False):
|
||||||
if not index_is_id:
|
if not index_is_id:
|
||||||
return self.data[index][1]
|
return self.data[index][1]
|
||||||
@ -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
|
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.execute('INSERT INTO books_series_link(book, series) VALUES (?,?)', (id, aid))
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
row = self.row(id)
|
||||||
|
if row is not None:
|
||||||
|
self.data[row][9] = series
|
||||||
|
|
||||||
def remove_unused_series(self):
|
def remove_unused_series(self):
|
||||||
for id, in self.conn.execute('SELECT id FROM series').fetchall():
|
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):
|
def set_series_index(self, id, idx):
|
||||||
self.conn.execute('UPDATE books SET series_index=? WHERE id=?', (int(idx), id))
|
self.conn.execute('UPDATE books SET series_index=? WHERE id=?', (int(idx), id))
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
row = self.row(id)
|
||||||
|
if row is not None:
|
||||||
|
self.data[row][10] = idx
|
||||||
|
|
||||||
def set_rating(self, id, rating):
|
def set_rating(self, id, rating):
|
||||||
rating = int(rating)
|
rating = int(rating)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user