mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Cleanup previous PR
I dont think we need to enforce unique column titles. If a user wants to have columns with the same titles, that's up to them. Also avoids the performance penalty.
This commit is contained in:
parent
c04b7dd482
commit
f4878d0509
@ -575,16 +575,10 @@ allow_template_database_functions_in_composites = False
|
|||||||
# takes a glob pattern allowing a single entry to match multiple URL types.
|
# takes a glob pattern allowing a single entry to match multiple URL types.
|
||||||
openers_by_scheme = {}
|
openers_by_scheme = {}
|
||||||
|
|
||||||
#: Change standard column heading text to some value
|
#: Change standard column names
|
||||||
# Use the dictionary below to change a column heading. The format of the
|
# Use the dictionary below to change a column name.
|
||||||
# dictionary is
|
# This tweak works only with standard columns, it cannot be used to change
|
||||||
# {lookup_name: new_heading, ...}
|
# the heading for a custom column.
|
||||||
# The new_heading must be unique: no two columns can have the same heading.
|
|
||||||
# This tweak works only with standard columns: it cannot be used to change
|
|
||||||
# the heading for a custom column. If a custom column has the same heading as
|
|
||||||
# one provided here then a number will appended to the custom column's heading
|
|
||||||
# to make it unique.
|
|
||||||
#
|
|
||||||
# Example:
|
# Example:
|
||||||
# alternate_column_headings = {'authors':'Writers', 'size':'MBytes'}
|
# alternate_column_names = {'authors':'Writers', 'size':'MBytes'}
|
||||||
alternate_column_headings = {}
|
alternate_column_names = {}
|
||||||
|
@ -342,7 +342,7 @@ class Quickview(QDialog, Ui_Quickview):
|
|||||||
a = m.addAction(self.select_book_icon, _('Select this book in the library'),
|
a = m.addAction(self.select_book_icon, _('Select this book in the library'),
|
||||||
partial(self.select_book, book_id))
|
partial(self.select_book, book_id))
|
||||||
a.setEnabled(book_displayed)
|
a.setEnabled(book_displayed)
|
||||||
m.addAction(_('Open a locked book details window for this book'),
|
m.addAction(_('Open a locked Book details window for this book'),
|
||||||
partial(self.show_book_details, book_id))
|
partial(self.show_book_details, book_id))
|
||||||
m.addAction(self.search_icon, _('Find item in the library'),
|
m.addAction(self.search_icon, _('Find item in the library'),
|
||||||
partial(self.do_search, follow_library_view=False))
|
partial(self.do_search, follow_library_view=False))
|
||||||
|
@ -967,7 +967,6 @@ class BooksView(QTableView): # {{{
|
|||||||
injected = False
|
injected = False
|
||||||
for f in ('last_modified', 'languages', 'formats', 'id', 'path'):
|
for f in ('last_modified', 'languages', 'formats', 'id', 'path'):
|
||||||
if not ans.get(f+'_injected', False):
|
if not ans.get(f+'_injected', False):
|
||||||
print('injecting', f)
|
|
||||||
injected = True
|
injected = True
|
||||||
ans[f+'_injected'] = True
|
ans[f+'_injected'] = True
|
||||||
hc = ans.get('hidden_columns', [])
|
hc = ans.get('hidden_columns', [])
|
||||||
|
@ -5,7 +5,6 @@ Created on 25 May 2010
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
import sys
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from calibre.utils.config_base import tweaks
|
from calibre.utils.config_base import tweaks
|
||||||
@ -396,6 +395,7 @@ class FieldMetadata:
|
|||||||
|
|
||||||
# search labels that are not db columns
|
# search labels that are not db columns
|
||||||
search_items = ['all', 'search', 'vl', 'template']
|
search_items = ['all', 'search', 'vl', 'template']
|
||||||
|
custom_field_prefix = '#'
|
||||||
__calibre_serializable__ = True
|
__calibre_serializable__ = True
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -412,22 +412,18 @@ class FieldMetadata:
|
|||||||
self._tb_cats[k]['display'] = {}
|
self._tb_cats[k]['display'] = {}
|
||||||
self._tb_cats[k]['is_editable'] = True
|
self._tb_cats[k]['is_editable'] = True
|
||||||
self._add_search_terms_to_map(k, v['search_terms'])
|
self._add_search_terms_to_map(k, v['search_terms'])
|
||||||
alternate_headings = tweaks.get('alternate_column_headings', {})
|
try:
|
||||||
if alternate_headings:
|
for k, v in tweaks['alternate_column_names'].items():
|
||||||
existing_headings = {k['name'] for k in self._tb_cats.values() if k['name']}
|
if k in self._tb_cats and not self.is_custom_field(k):
|
||||||
for k,v in alternate_headings.items():
|
|
||||||
if k in self._tb_cats.keys():
|
|
||||||
v = self.get_unique_field_heading(v)
|
|
||||||
existing_headings.discard(self._tb_cats[k]['name'])
|
|
||||||
existing_headings.add(v)
|
|
||||||
self._tb_cats[k]['name'] = v
|
self._tb_cats[k]['name'] = v
|
||||||
|
except Exception:
|
||||||
|
traceback.print_exc()
|
||||||
self._tb_cats['timestamp']['display'] = {
|
self._tb_cats['timestamp']['display'] = {
|
||||||
'date_format': tweaks['gui_timestamp_display_format']}
|
'date_format': tweaks['gui_timestamp_display_format']}
|
||||||
self._tb_cats['pubdate']['display'] = {
|
self._tb_cats['pubdate']['display'] = {
|
||||||
'date_format': tweaks['gui_pubdate_display_format']}
|
'date_format': tweaks['gui_pubdate_display_format']}
|
||||||
self._tb_cats['last_modified']['display'] = {
|
self._tb_cats['last_modified']['display'] = {
|
||||||
'date_format': tweaks['gui_last_modified_display_format']}
|
'date_format': tweaks['gui_last_modified_display_format']}
|
||||||
self.custom_field_prefix = '#'
|
|
||||||
self.get = self._tb_cats.get
|
self.get = self._tb_cats.get
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
@ -464,10 +460,6 @@ class FieldMetadata:
|
|||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
return not self.__eq__(other)
|
return not self.__eq__(other)
|
||||||
|
|
||||||
def set_field_heading(self, key, heading):
|
|
||||||
if key in self._tb_cats.keys():
|
|
||||||
self._tb_cats[key]['name'] = heading
|
|
||||||
|
|
||||||
def sortable_field_keys(self):
|
def sortable_field_keys(self):
|
||||||
return [k for k in self._tb_cats.keys()
|
return [k for k in self._tb_cats.keys()
|
||||||
if self._tb_cats[k]['kind']=='field' and
|
if self._tb_cats[k]['kind']=='field' and
|
||||||
@ -574,18 +566,6 @@ class FieldMetadata:
|
|||||||
l[k] = self._tb_cats[k]
|
l[k] = self._tb_cats[k]
|
||||||
return l
|
return l
|
||||||
|
|
||||||
def get_unique_field_heading(self, name):
|
|
||||||
# Verify column heading is unique. Can only happen if the tweak is set
|
|
||||||
if tweaks.get('alternate_column_headings', {}):
|
|
||||||
existing_names = {icu_lower(c['name']) for c in self._tb_cats.values() if c['name'] is not None}
|
|
||||||
t = icu_lower(name)
|
|
||||||
if t in existing_names:
|
|
||||||
for i in range(1, sys.maxsize):
|
|
||||||
if (t + '_' + str(i)) not in existing_names:
|
|
||||||
name = name + '_' + str(i)
|
|
||||||
break
|
|
||||||
return name
|
|
||||||
|
|
||||||
def add_custom_field(self, label, table, column, datatype, colnum, name,
|
def add_custom_field(self, label, table, column, datatype, colnum, name,
|
||||||
display, is_editable, is_multiple, is_category,
|
display, is_editable, is_multiple, is_category,
|
||||||
is_csp=False):
|
is_csp=False):
|
||||||
@ -594,7 +574,6 @@ class FieldMetadata:
|
|||||||
raise ValueError('Duplicate custom field [%s]'%(label))
|
raise ValueError('Duplicate custom field [%s]'%(label))
|
||||||
if datatype not in self.VALID_DATA_TYPES:
|
if datatype not in self.VALID_DATA_TYPES:
|
||||||
raise ValueError('Unknown datatype %s for field %s'%(datatype, key))
|
raise ValueError('Unknown datatype %s for field %s'%(datatype, key))
|
||||||
name = self.get_unique_field_heading(name)
|
|
||||||
self._tb_cats[key] = {'table':table, 'column':column,
|
self._tb_cats[key] = {'table':table, 'column':column,
|
||||||
'datatype':datatype, 'is_multiple':is_multiple,
|
'datatype':datatype, 'is_multiple':is_multiple,
|
||||||
'kind':'field', 'name':name,
|
'kind':'field', 'name':name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user