예제 #1
0
파일: fields.py 프로젝트: smalldek/calibre
    def __init__(self, name, table):
        self.name, self.table = name, table
        dt = self.metadata['datatype']
        self.has_text_data = dt in {'text', 'comments', 'series', 'enumeration'}
        self.table_type = self.table.table_type
        self._sort_key = (sort_key if dt in ('text', 'series', 'enumeration') else lambda x: x)

        # This will be compared to the output of sort_key() which is a
        # bytestring, therefore it is safer to have it be a bytestring.
        # Coercing an empty bytestring to unicode will never fail, but the
        # output of sort_key cannot be coerced to unicode
        self._default_sort_key = b''

        if dt in {'int', 'float', 'rating'}:
            self._default_sort_key = 0
        elif dt == 'bool':
            self._default_sort_key = None
        elif dt == 'datetime':
            self._default_sort_key = UNDEFINED_DATE
        if self.name == 'languages':
            self._sort_key = lambda x:sort_key(calibre_langcode_to_name(x))
        self.is_multiple = (bool(self.metadata['is_multiple']) or self.name ==
                'formats')
        self.sort_sort_key = True
        if self.is_multiple and '&' in self.metadata['is_multiple']['list_to_ui']:
            self._sort_key = lambda x: sort_key(author_to_author_sort(x))
            self.sort_sort_key = False
        self.default_value = {} if name == 'identifiers' else () if self.is_multiple else None
        self.category_formatter = type(u'')
        if dt == 'rating':
            self.category_formatter = lambda x:'\u2605'*int(x/2)
        elif name == 'languages':
            self.category_formatter = calibre_langcode_to_name
        self.writer = Writer(self)
        self.series_field = None
예제 #2
0
파일: fields.py 프로젝트: kobolabs/calibre
 def __init__(self, name, table):
     self.name, self.table = name, table
     dt = self.metadata['datatype']
     self.has_text_data = dt in {
         'text', 'comments', 'series', 'enumeration'
     }
     self.table_type = self.table.table_type
     self._sort_key = (sort_key if dt in ('text', 'series',
                                          'enumeration') else lambda x: x)
     self._default_sort_key = ''
     if dt in {'int', 'float', 'rating'}:
         self._default_sort_key = 0
     elif dt == 'bool':
         self._default_sort_key = None
     elif dt == 'datetime':
         self._default_sort_key = UNDEFINED_DATE
     if self.name == 'languages':
         self._sort_key = lambda x: sort_key(calibre_langcode_to_name(x))
     self.is_multiple = (bool(self.metadata['is_multiple'])
                         or self.name == 'formats')
     self.category_formatter = type(u'')
     if dt == 'rating':
         self.category_formatter = lambda x: '\u2605' * int(x / 2)
     elif name == 'languages':
         self.category_formatter = calibre_langcode_to_name
     self.writer = Writer(self)
     self.series_field = None
예제 #3
0
    def __init__(self, name, table, bools_are_tristate,
                 get_template_functions):
        self.name, self.table = name, table
        dt = self.metadata['datatype']
        self.has_text_data = dt in {
            'text', 'comments', 'series', 'enumeration'
        }
        self.table_type = self.table.table_type
        self._sort_key = (sort_key if dt in ('text', 'series',
                                             'enumeration') else IDENTITY)

        # This will be compared to the output of sort_key() which is a
        # bytestring, therefore it is safer to have it be a bytestring.
        # Coercing an empty bytestring to unicode will never fail, but the
        # output of sort_key cannot be coerced to unicode
        self._default_sort_key = b''

        if dt in {'int', 'float', 'rating'}:
            self._default_sort_key = 0
            self._sort_key = numeric_sort_key
        elif dt == 'bool':
            self._default_sort_key = None
            self._sort_key = bool_sort_key(bools_are_tristate)
        elif dt == 'datetime':
            self._default_sort_key = UNDEFINED_DATE
            if tweaks['sort_dates_using_visible_fields']:
                fmt = None
                if name in {'timestamp', 'pubdate', 'last_modified'}:
                    fmt = tweaks['gui_%s_display_format' % name]
                elif self.metadata['is_custom']:
                    fmt = self.metadata.get('display',
                                            {}).get('date_format', None)
                self._sort_key = partial(clean_date_for_sort, fmt=fmt)
        elif dt == 'comments' or name == 'identifiers':
            self._default_sort_key = ''

        if self.name == 'languages':
            self._sort_key = lambda x: sort_key(calibre_langcode_to_name(x))
        self.is_multiple = (bool(self.metadata['is_multiple'])
                            or self.name == 'formats')
        self.sort_sort_key = True
        if self.is_multiple and '&' in self.metadata['is_multiple'][
                'list_to_ui']:
            self._sort_key = lambda x: sort_key(author_to_author_sort(x))
            self.sort_sort_key = False
        self.default_value = {} if name == 'identifiers' else (
        ) if self.is_multiple else None
        self.category_formatter = unicode_type
        if dt == 'rating':
            if self.metadata['display'].get('allow_half_stars', False):
                self.category_formatter = lambda x: rating_to_stars(x, True)
            else:
                self.category_formatter = rating_to_stars
        elif name == 'languages':
            self.category_formatter = calibre_langcode_to_name
        self.writer = Writer(self)
        self.series_field = None
        self.get_template_functions = get_template_functions