mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add VALID_DATATYPES to FieldMetadata
This commit is contained in:
commit
77b20a7937
@ -12,6 +12,7 @@ from math import floor
|
|||||||
|
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
from calibre.constants import preferred_encoding
|
from calibre.constants import preferred_encoding
|
||||||
|
from calibre.library.field_metadata import FieldMetadata
|
||||||
from calibre.utils.date import parse_date
|
from calibre.utils.date import parse_date
|
||||||
|
|
||||||
class CustomColumns(object):
|
class CustomColumns(object):
|
||||||
@ -30,6 +31,10 @@ class CustomColumns(object):
|
|||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
# Verify that CUSTOM_DATA_TYPES is a (possibly improper) subset of
|
||||||
|
# VALID_DATA_TYPES
|
||||||
|
if len(self.CUSTOM_DATA_TYPES - FieldMetadata.VALID_DATA_TYPES) > 0:
|
||||||
|
raise ValueError('Unknown custom column type in set')
|
||||||
# Delete marked custom columns
|
# Delete marked custom columns
|
||||||
for record in self.conn.get(
|
for record in self.conn.get(
|
||||||
'SELECT id FROM custom_columns WHERE mark_for_delete=1'):
|
'SELECT id FROM custom_columns WHERE mark_for_delete=1'):
|
||||||
|
@ -30,8 +30,8 @@ class FieldMetadata(dict):
|
|||||||
|
|
||||||
label: the actual column label. No prefixing.
|
label: the actual column label. No prefixing.
|
||||||
|
|
||||||
datatype: the type of the information in the field. Valid values are float,
|
datatype: the type of information in the field. Valid values are listed in
|
||||||
int, rating, bool, comments, datetime, text.
|
VALID_DATA_TYPES below.
|
||||||
is_multiple: valid for the text datatype. If None, the field is to be
|
is_multiple: valid for the text datatype. If None, the field is to be
|
||||||
treated as a single term. If not None, it contains a string, and the field
|
treated as a single term. If not None, it contains a string, and the field
|
||||||
is assumed to contain a list of terms separated by that string
|
is assumed to contain a list of terms separated by that string
|
||||||
@ -65,6 +65,10 @@ class FieldMetadata(dict):
|
|||||||
rec_index: the index of the field in the db metadata record.
|
rec_index: the index of the field in the db metadata record.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
VALID_DATA_TYPES = frozenset([None, 'rating', 'text', 'comments', 'datetime',
|
||||||
|
'int', 'float', 'bool', 'series'])
|
||||||
|
|
||||||
_field_metadata = [
|
_field_metadata = [
|
||||||
('authors', {'table':'authors',
|
('authors', {'table':'authors',
|
||||||
'column':'name',
|
'column':'name',
|
||||||
@ -296,6 +300,8 @@ class FieldMetadata(dict):
|
|||||||
self._search_term_map = {}
|
self._search_term_map = {}
|
||||||
self.custom_label_to_key_map = {}
|
self.custom_label_to_key_map = {}
|
||||||
for k,v in self._field_metadata:
|
for k,v in self._field_metadata:
|
||||||
|
if v['kind'] == 'field' and v['datatype'] not in self.VALID_DATA_TYPES:
|
||||||
|
raise ValueError('Unknown datatype %s for field %s'%(v['datatype'], k))
|
||||||
self._tb_cats[k] = v
|
self._tb_cats[k] = v
|
||||||
self._tb_cats[k]['label'] = k
|
self._tb_cats[k]['label'] = k
|
||||||
self._tb_cats[k]['display'] = {}
|
self._tb_cats[k]['display'] = {}
|
||||||
@ -377,6 +383,8 @@ class FieldMetadata(dict):
|
|||||||
key = self.custom_field_prefix + label
|
key = self.custom_field_prefix + label
|
||||||
if key in self._tb_cats:
|
if key in self._tb_cats:
|
||||||
raise ValueError('Duplicate custom field [%s]'%(label))
|
raise ValueError('Duplicate custom field [%s]'%(label))
|
||||||
|
if datatype not in self.VALID_DATA_TYPES:
|
||||||
|
raise ValueError('Unknown datatype %s for field %s'%(datatype, key))
|
||||||
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