diff --git a/src/calibre/gui2/preferences/create_custom_column.py b/src/calibre/gui2/preferences/create_custom_column.py index 3eed04f709..5cd32a4af3 100644 --- a/src/calibre/gui2/preferences/create_custom_column.py +++ b/src/calibre/gui2/preferences/create_custom_column.py @@ -112,7 +112,7 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): getattr(self, 'enum_'+x).setVisible(col_type == 'enumeration') def accept(self): - col = unicode(self.column_name_box.text()) + col = unicode(self.column_name_box.text()).strip() if not col: return self.simple_error('', _('No lookup name was provided')) if re.match('^\w*$', col) is None or not col[0].isalpha() or col.lower() != col: @@ -121,7 +121,7 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): if col.endswith('_index'): return self.simple_error('', _('Lookup names cannot end with _index, ' 'because these names are reserved for the index of a series column.')) - col_heading = unicode(self.column_heading_box.text()) + col_heading = unicode(self.column_heading_box.text()).strip() col_type = self.column_types[self.column_type_box.currentIndex()]['datatype'] if col_type == '*text': col_type='text' @@ -153,23 +153,22 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): display_dict = {} if col_type == 'datetime': - if self.date_format_box.text(): - display_dict = {'date_format':unicode(self.date_format_box.text())} + if self.date_format_box.text().strip(): + display_dict = {'date_format':unicode(self.date_format_box.text()).strip()} else: display_dict = {'date_format': None} elif col_type == 'composite': - if not self.composite_box.text(): + if not self.composite_box.text().strip(): return self.simple_error('', _('You must enter a template for' ' composite columns')) - display_dict = {'composite_template':unicode(self.composite_box.text())} + display_dict = {'composite_template':unicode(self.composite_box.text()).strip()} elif col_type == 'enumeration': if not self.enum_box.text(): return self.simple_error('', _('You must enter at least one' ' value for enumeration columns')) l = [v.strip() for v in unicode(self.enum_box.text()).split(',')] - for v in l: - if not v: - return self.simple_error('', _('You cannot provide the empty ' + if '' in l: + return self.simple_error('', _('You cannot provide the empty ' 'value, as it is included by default')) for i in range(0, len(l)-1): if l[i] in l[i+1:]: diff --git a/src/calibre/gui2/tag_view.py b/src/calibre/gui2/tag_view.py index 6b5de37bbe..c2b0e4638b 100644 --- a/src/calibre/gui2/tag_view.py +++ b/src/calibre/gui2/tag_view.py @@ -7,6 +7,8 @@ __docformat__ = 'restructuredtext en' Browsing book collection by tags. ''' +import traceback + from itertools import izip from functools import partial @@ -755,13 +757,15 @@ class TagsModel(QAbstractItemModel): # {{{ try: tb_cats.add_user_category(label=cat_name, name=user_cat) except ValueError: - import traceback traceback.print_exc() - for cat in sorted(self.db.prefs.get('grouped_search_terms', {}), + for cat in sorted(self.db.prefs.get('grouped_search_terms', {}).keys(), key=sort_key): if (u'@' + cat) in data: - tb_cats.add_user_category(label=u'@' + cat, name=cat) + try: + tb_cats.add_user_category(label=u'@' + cat, name=cat) + except ValueError: + traceback.print_exc() self.db.data.change_search_locations(self.db.field_metadata.get_search_terms()) if len(saved_searches().names()): diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 33826419e4..305d1581d7 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -353,12 +353,23 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): # Reconstruct the user categories, putting them into field_metadata # Assumption is that someone else will fix them if they change. self.field_metadata.remove_dynamic_categories() - tb_cats = self.field_metadata for user_cat in sorted(self.prefs.get('user_categories', {}).keys(), key=sort_key): cat_name = '@' + user_cat # add the '@' to avoid name collision - tb_cats.add_user_category(label=cat_name, name=user_cat) + self.field_metadata.add_user_category(label=cat_name, name=user_cat) + + # add grouped search term user categories + muc = self.prefs.get('grouped_search_make_user_categories', []) + for cat in sorted(self.prefs.get('grouped_search_terms', {}).keys(), key=sort_key): + if cat in muc: + # There is a chance that these can be duplicates of an existing + # user category. Print the exception and continue. + try: + self.field_metadata.add_user_category(label=u'@' + cat, name=cat) + except: + traceback.print_exc() + if len(saved_searches().names()): - tb_cats.add_search_category(label='search', name=_('Searches')) + self.field_metadata.add_search_category(label='search', name=_('Searches')) self.field_metadata.add_grouped_search_terms( self.prefs.get('grouped_search_terms', {})) diff --git a/src/calibre/library/server/browse.py b/src/calibre/library/server/browse.py index 2749f0651f..5415cfe8bb 100644 --- a/src/calibre/library/server/browse.py +++ b/src/calibre/library/server/browse.py @@ -603,7 +603,9 @@ class BrowseServer(object): val = '' if add_category_links: added_key = False - if val and key in ('authors', 'publisher', 'series', 'tags'): + fm = mi.metadata_for_field(key) + if val and fm and fm['is_category'] and \ + key != 'formats' and fm['datatype'] not in ['rating']: categories = mi.get(key) if isinstance(categories, basestring): categories = [categories]