diff --git a/src/calibre/gui2/dialogs/metadata_single.py b/src/calibre/gui2/dialogs/metadata_single.py index dfe4c106d9..a9e9ef825c 100644 --- a/src/calibre/gui2/dialogs/metadata_single.py +++ b/src/calibre/gui2/dialogs/metadata_single.py @@ -551,6 +551,25 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog): self.sync_formats() title = unicode(self.title.text()) self.db.set_title(self.id, title, notify=False) + au = unicode(self.authors.text()) + if au: + self.db.set_authors(self.id, string_to_authors(au), notify=False) + aus = unicode(self.author_sort.text()) + if aus: + self.db.set_author_sort(self.id, aus, notify=False) + self.db.set_isbn(self.id, + re.sub(r'[^0-9a-zA-Z]', '', unicode(self.isbn.text())), notify=False) + self.db.set_rating(self.id, 2*self.rating.value(), notify=False) + self.db.set_publisher(self.id, qstring_to_unicode(self.publisher.currentText()), notify=False) + self.db.set_tags(self.id, qstring_to_unicode(self.tags.text()).split(','), notify=False) + self.db.set_series(self.id, qstring_to_unicode(self.series.currentText()), notify=False) + self.db.set_series_index(self.id, self.series_index.value(), notify=False) + self.db.set_comment(self.id, qstring_to_unicode(self.comments.toPlainText()), notify=False) + d = self.pubdate.date() + self.db.set_pubdate(self.id, datetime(d.year(), d.month(), d.day())) + + if self.cover_changed and self.cover_data is not None: + self.db.set_cover(self.id, self.cover_data) except IOError, err: if err.errno == 13: # Permission denied fname = err.filename if err.filename else 'file' @@ -558,25 +577,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog): _('Could not open %s. Is it being used by another' ' program?')%fname, show=True) raise - au = unicode(self.authors.text()) - if au: - self.db.set_authors(self.id, string_to_authors(au), notify=False) - aus = qstring_to_unicode(self.author_sort.text()) - if aus: - self.db.set_author_sort(self.id, aus, notify=False) - self.db.set_isbn(self.id, - re.sub(r'[^0-9a-zA-Z]', '', unicode(self.isbn.text())), notify=False) - self.db.set_rating(self.id, 2*self.rating.value(), notify=False) - self.db.set_publisher(self.id, qstring_to_unicode(self.publisher.currentText()), notify=False) - self.db.set_tags(self.id, qstring_to_unicode(self.tags.text()).split(','), notify=False) - self.db.set_series(self.id, qstring_to_unicode(self.series.currentText()), notify=False) - self.db.set_series_index(self.id, self.series_index.value(), notify=False) - self.db.set_comment(self.id, qstring_to_unicode(self.comments.toPlainText()), notify=False) - d = self.pubdate.date() - self.db.set_pubdate(self.id, datetime(d.year(), d.month(), d.day())) - if self.cover_changed and self.cover_data is not None: - self.db.set_cover(self.id, self.cover_data) QDialog.accept(self) if callable(self.accepted_callback): self.accepted_callback(self.id) diff --git a/src/calibre/library/server.py b/src/calibre/library/server.py index 8e31ff8b37..f615827cde 100644 --- a/src/calibre/library/server.py +++ b/src/calibre/library/server.py @@ -366,6 +366,21 @@ class LibraryServer(object): return base.intersection(epub.union(pdb)) def stanza_sortby_subcategory(self, updated, sortby, offset): + pat = re.compile(r'\(.*\)') + + def clean_author(x): + return pat.sub('', x).strip() + + def author_cmp(x, y): + x = x if ',' in x else clean_author(x).rpartition(' ')[-1] + y = y if ',' in y else clean_author(y).rpartition(' ')[-1] + return cmp(x.lower(), y.lower()) + + def get_author(x): + pref, ___, suff = clean_author(x).rpartition(' ') + return suff + (', '+pref) if pref else suff + + what, subtitle = sortby[2:], '' if sortby == 'byseries': data = self.db.all_series() @@ -379,13 +394,15 @@ class LibraryServer(object): data = self.db.all_tags2() data = [(x[0], x[1], len(self.get_matches('tags', x[1]))) for x in data] subtitle = 'Books by tag' + fcmp = author_cmp if sortby == 'byauthor' else cmp data = [x for x in data if x[2] > 0] - data.sort(cmp=lambda x, y: cmp(x[1], y[1])) + data.sort(cmp=lambda x, y: fcmp(x[1], y[1])) next_offset = offset + self.max_stanza_items rdata = data[offset:next_offset] if next_offset >= len(data): next_offset = -1 - entries = [self.STANZA_SUBCATALOG_ENTRY.generate(title=title, id=id, + gt = get_author if sortby == 'byauthor' else lambda x: x + entries = [self.STANZA_SUBCATALOG_ENTRY.generate(title=gt(title), id=id, what=what, updated=updated, count=c).render('xml').decode('utf-8') for id, title, c in rdata] next_link = ''