mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Fix boolean and date searching in non english calibre installs.
This commit is contained in:
parent
1941541cdf
commit
daff566a56
@ -352,6 +352,14 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
'<=':[2, relop_le]
|
'<=':[2, relop_le]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local_today = ('_today', icu_lower(_('today')))
|
||||||
|
local_yesterday = ('_yesterday', icu_lower(_('yesterday')))
|
||||||
|
local_thismonth = ('_thismonth', icu_lower(_('thismonth')))
|
||||||
|
local_daysago = icu_lower(_('daysago'))
|
||||||
|
local_daysago_len = len(local_daysago)
|
||||||
|
untrans_daysago = '_daysago'
|
||||||
|
untrans_daysago_len = len('_daysago')
|
||||||
|
|
||||||
def get_dates_matches(self, location, query, candidates):
|
def get_dates_matches(self, location, query, candidates):
|
||||||
matches = set([])
|
matches = set([])
|
||||||
if len(query) < 2:
|
if len(query) < 2:
|
||||||
@ -390,17 +398,24 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
if relop is None:
|
if relop is None:
|
||||||
(p, relop) = self.date_search_relops['=']
|
(p, relop) = self.date_search_relops['=']
|
||||||
|
|
||||||
if query == _('today'):
|
if query in self.local_today:
|
||||||
qd = now()
|
qd = now()
|
||||||
field_count = 3
|
field_count = 3
|
||||||
elif query == _('yesterday'):
|
elif query in self.local_yesterday:
|
||||||
qd = now() - timedelta(1)
|
qd = now() - timedelta(1)
|
||||||
field_count = 3
|
field_count = 3
|
||||||
elif query == _('thismonth'):
|
elif query in self.local_thismonth:
|
||||||
qd = now()
|
qd = now()
|
||||||
field_count = 2
|
field_count = 2
|
||||||
elif query.endswith(_('daysago')):
|
elif query.endswith(self.local_daysago):
|
||||||
num = query[0:-len(_('daysago'))]
|
num = query[0:-self.local_daysago_len]
|
||||||
|
try:
|
||||||
|
qd = now() - timedelta(int(num))
|
||||||
|
except:
|
||||||
|
raise ParseException(query, len(query), 'Number conversion error', self)
|
||||||
|
field_count = 3
|
||||||
|
elif query.endswith(self.untrans_daysago):
|
||||||
|
num = query[0:-self.untrans_daysago_len]
|
||||||
try:
|
try:
|
||||||
qd = now() - timedelta(int(num))
|
qd = now() - timedelta(int(num))
|
||||||
except:
|
except:
|
||||||
@ -591,14 +606,23 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
query = icu_lower(query)
|
query = icu_lower(query)
|
||||||
return matchkind, query
|
return matchkind, query
|
||||||
|
|
||||||
|
local_no = icu_lower(_('no'))
|
||||||
|
local_yes = icu_lower(_('yes'))
|
||||||
|
local_unchecked = icu_lower(_('unchecked'))
|
||||||
|
local_checked = icu_lower(_('checked'))
|
||||||
|
local_empty = icu_lower(_('empty'))
|
||||||
|
local_blank = icu_lower(_('blank'))
|
||||||
|
local_bool_values = (
|
||||||
|
local_no, local_unchecked, '_no', 'false',
|
||||||
|
local_yes, local_checked, '_yes', 'true',
|
||||||
|
local_empty, local_blank, '_empty')
|
||||||
|
|
||||||
def get_bool_matches(self, location, query, candidates):
|
def get_bool_matches(self, location, query, candidates):
|
||||||
bools_are_tristate = self.db_prefs.get('bools_are_tristate')
|
bools_are_tristate = self.db_prefs.get('bools_are_tristate')
|
||||||
loc = self.field_metadata[location]['rec_index']
|
loc = self.field_metadata[location]['rec_index']
|
||||||
matches = set()
|
matches = set()
|
||||||
query = icu_lower(query)
|
query = icu_lower(query)
|
||||||
if query not in (_('no'), _('unchecked'), '_no', 'false',
|
if query not in self.local_bool_values:
|
||||||
_('yes'), _('checked'), '_yes', 'true',
|
|
||||||
_('empty'), _('blank'), '_empty'):
|
|
||||||
raise ParseException(_('Invalid boolean query "{0}"').format(query))
|
raise ParseException(_('Invalid boolean query "{0}"').format(query))
|
||||||
for id_ in candidates:
|
for id_ in candidates:
|
||||||
item = self._data[id_]
|
item = self._data[id_]
|
||||||
@ -608,20 +632,20 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
val = force_to_bool(item[loc])
|
val = force_to_bool(item[loc])
|
||||||
if not bools_are_tristate:
|
if not bools_are_tristate:
|
||||||
if val is None or not val: # item is None or set to false
|
if val is None or not val: # item is None or set to false
|
||||||
if query in [_('no'), _('unchecked'), '_no', 'false']:
|
if query in (self.local_no, self.local_unchecked, '_no', 'false'):
|
||||||
matches.add(item[0])
|
matches.add(item[0])
|
||||||
else: # item is explicitly set to true
|
else: # item is explicitly set to true
|
||||||
if query in [_('yes'), _('checked'), '_yes', 'true']:
|
if query in (self.local_yes, self.local_checked, '_yes', 'true'):
|
||||||
matches.add(item[0])
|
matches.add(item[0])
|
||||||
else:
|
else:
|
||||||
if val is None:
|
if val is None:
|
||||||
if query in [_('empty'), _('blank'), '_empty', 'false']:
|
if query in (self.local_empty, self.local_blank, '_empty', 'false'):
|
||||||
matches.add(item[0])
|
matches.add(item[0])
|
||||||
elif not val: # is not None and false
|
elif not val: # is not None and false
|
||||||
if query in [_('no'), _('unchecked'), '_no', 'true']:
|
if query in (self.local_no, self.local_unchecked, '_no', 'true'):
|
||||||
matches.add(item[0])
|
matches.add(item[0])
|
||||||
else: # item is not None and true
|
else: # item is not None and true
|
||||||
if query in [_('yes'), _('checked'), '_yes', 'true']:
|
if query in (self.local_yes, self.local_checked, '_yes', 'true'):
|
||||||
matches.add(item[0])
|
matches.add(item[0])
|
||||||
return matches
|
return matches
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user