def itervals(self, record): for name, fm in self.entries: dt = fm['datatype'] val = record[fm['rec_index']] if dt == 'composite': sb = fm['display'].get('composite_sort', 'text') if sb == 'date': try: val = parse_date(val) except: val = UNDEFINED_DATE dt = 'datetime' elif sb == 'number': try: p = 1 for i, candidate in enumerate( ('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB')): if val.endswith(candidate): p = 1024**(i) val = val[:-len(candidate)].strip() break val = locale.atof(val) * p except: val = 0.0 dt = 'float' elif sb == 'bool': val = force_to_bool(val) dt = 'bool' if dt == 'datetime': if val is None: val = UNDEFINED_DATE if tweaks['sort_dates_using_visible_fields']: format = None if name == 'timestamp': format = tweaks['gui_timestamp_display_format'] elif name == 'pubdate': format = tweaks['gui_pubdate_display_format'] elif name == 'last_modified': format = tweaks['gui_last_modified_display_format'] elif fm['is_custom']: format = fm['display'].get('date_format', None) val = clean_date_for_sort(val, format) elif dt == 'series': if val is None: val = ('', 1) else: if self.library_order: try: lang = record[self.lang_idx].partition(u',')[0] except (AttributeError, ValueError, KeyError, IndexError, TypeError): lang = None val = title_sort(val, order='library_order', lang=lang) sidx_fm = self.field_metadata[name + '_index'] sidx = record[sidx_fm['rec_index']] val = (self.string_sort_key(val), sidx) elif dt in ('text', 'comments', 'composite', 'enumeration'): if val: if fm['is_multiple']: jv = fm['is_multiple']['list_to_ui'] sv = fm['is_multiple']['cache_to_list'] if '&' in jv: val = jv.join([ author_to_author_sort(v) for v in val.split(sv) ]) else: val = jv.join( sorted(val.split(sv), key=self.string_sort_key)) val = self.string_sort_key(val) elif dt == 'bool': if not self.db_prefs.get('bools_are_tristate'): val = {True: 1, False: 2, None: 2}.get(val, 2) else: val = {True: 1, False: 2, None: 3}.get(val, 3) yield val
def itervals(self, record): for name, fm in self.entries: dt = fm['datatype'] val = record[fm['rec_index']] if dt == 'composite': sb = fm['display'].get('composite_sort', 'text') if sb == 'date': try: val = parse_date(val) except: val = UNDEFINED_DATE dt = 'datetime' elif sb == 'number': try: p = 1 for i, candidate in enumerate( ('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB')): if val.endswith(candidate): p = 1024**(i) val = val[:-len(candidate)].strip() break val = locale.atof(val) * p except: val = 0.0 dt = 'float' elif sb == 'bool': val = force_to_bool(val) dt = 'bool' if dt == 'datetime': if val is None: val = UNDEFINED_DATE if tweaks['sort_dates_using_visible_fields']: format = None if name == 'timestamp': format = tweaks['gui_timestamp_display_format'] elif name == 'pubdate': format = tweaks['gui_pubdate_display_format'] elif name == 'last_modified': format = tweaks['gui_last_modified_display_format'] elif fm['is_custom']: format = fm['display'].get('date_format', None) val = clean_date_for_sort(val, format) elif dt == 'series': if val is None: val = ('', 1) else: if self.library_order: try: lang = record[self.lang_idx].partition(u',')[0] except (AttributeError, ValueError, KeyError, IndexError, TypeError): lang = None val = title_sort(val, order='library_order', lang=lang) sidx_fm = self.field_metadata[name + '_index'] sidx = record[sidx_fm['rec_index']] val = (self.string_sort_key(val), sidx) elif dt in ('text', 'comments', 'composite', 'enumeration'): if val: if fm['is_multiple']: jv = fm['is_multiple']['list_to_ui'] sv = fm['is_multiple']['cache_to_list'] if '&' in jv: val = jv.join( [author_to_author_sort(v) for v in val.split(sv)]) else: val = jv.join(sorted(val.split(sv), key=self.string_sort_key)) val = self.string_sort_key(val) elif dt == 'bool': if not self.db_prefs.get('bools_are_tristate'): val = {True: 1, False: 2, None: 2}.get(val, 2) else: val = {True: 1, False: 2, None: 3}.get(val, 3) yield val
def itervals(self, record): for name, fm in self.entries: dt = fm["datatype"] val = record[fm["rec_index"]] if dt == "composite": sb = fm["display"].get("composite_sort", "text") if sb == "date": try: val = parse_date(val) except: val = UNDEFINED_DATE dt = "datetime" elif sb == "number": try: p = 1 for i, candidate in enumerate(("B", "KB", "MB", "GB", "TB", "PB", "EB")): if val.endswith(candidate): p = 1024 ** (i) val = val[: -len(candidate)].strip() break val = locale.atof(val) * p except: val = 0.0 dt = "float" elif sb == "bool": val = force_to_bool(val) dt = "bool" if dt == "datetime": if val is None: val = UNDEFINED_DATE if tweaks["sort_dates_using_visible_fields"]: format = None if name == "timestamp": format = tweaks["gui_timestamp_display_format"] elif name == "pubdate": format = tweaks["gui_pubdate_display_format"] elif name == "last_modified": format = tweaks["gui_last_modified_display_format"] elif fm["is_custom"]: format = fm["display"].get("date_format", None) val = clean_date_for_sort(val, format) elif dt == "series": if val is None: val = ("", 1) else: if self.library_order: try: lang = record[self.lang_idx].partition(u",")[0] except (AttributeError, ValueError, KeyError, IndexError, TypeError): lang = None val = title_sort(val, order="library_order", lang=lang) sidx_fm = self.field_metadata[name + "_index"] sidx = record[sidx_fm["rec_index"]] val = (self.string_sort_key(val), sidx) elif dt in ("text", "comments", "composite", "enumeration"): if val: if fm["is_multiple"]: jv = fm["is_multiple"]["list_to_ui"] sv = fm["is_multiple"]["cache_to_list"] if "&" in jv: val = jv.join([author_to_author_sort(v) for v in val.split(sv)]) else: val = jv.join(sorted(val.split(sv), key=self.string_sort_key)) val = self.string_sort_key(val) elif dt == "bool": if not self.db_prefs.get("bools_are_tristate"): val = {True: 1, False: 2, None: 2}.get(val, 2) else: val = {True: 1, False: 2, None: 3}.get(val, 3) yield val