add sharemetadata to itemKeys. fix queries for boolean keys
This commit is contained in:
parent
cd63cca194
commit
54b3982787
4 changed files with 26 additions and 5 deletions
|
@ -233,6 +233,13 @@
|
||||||
"format": {"type": "percent", "args": [1, 0]},
|
"format": {"type": "percent", "args": [1, 0]},
|
||||||
"sort": true
|
"sort": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "sharemetadata",
|
||||||
|
"title": "Share Metadata",
|
||||||
|
"type": "boolean",
|
||||||
|
"columnWidth": 144,
|
||||||
|
"sort": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "random",
|
"id": "random",
|
||||||
"title": "Random",
|
"title": "Random",
|
||||||
|
|
|
@ -176,6 +176,8 @@ class Item(db.Model):
|
||||||
value = ''.join(value)
|
value = ''.join(value)
|
||||||
value = ox.get_sort_title(value)
|
value = ox.get_sort_title(value)
|
||||||
value = utils.sort_title(value).lower()
|
value = utils.sort_title(value).lower()
|
||||||
|
elif sort_type == 'boolean':
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
value = '\n'.join(value)
|
value = '\n'.join(value)
|
||||||
|
@ -203,11 +205,16 @@ class Item(db.Model):
|
||||||
|
|
||||||
keys = []
|
keys = []
|
||||||
for key in config['itemKeys']:
|
for key in config['itemKeys']:
|
||||||
if key.get('find') or key.get('filter') or key.get('type') in [['string'], 'string']:
|
if key.get('find') or \
|
||||||
|
key.get('filter') or key.get('type') in [['string'], 'string'] or \
|
||||||
|
(key.get('type') == 'boolean' and key.get('sort')):
|
||||||
value = self.json().get(key['id'], None)
|
value = self.json().get(key['id'], None)
|
||||||
if key.get('filterMap') and value:
|
if key.get('filterMap') and value:
|
||||||
value = re.compile(key.get('filterMap')).findall(value)
|
value = re.compile(key.get('filterMap')).findall(value)
|
||||||
if value: value = value[0]
|
if value: value = value[0]
|
||||||
|
if key.get('type') == 'boolean':
|
||||||
|
value = True if value else False
|
||||||
|
value = str(value).lower()
|
||||||
if value:
|
if value:
|
||||||
keys.append(key['id'])
|
keys.append(key['id'])
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
|
@ -528,6 +535,8 @@ for key in config['itemKeys']:
|
||||||
col = sa.Column(sa.Float(), index=True)
|
col = sa.Column(sa.Float(), index=True)
|
||||||
elif sort_type == 'date':
|
elif sort_type == 'date':
|
||||||
col = sa.Column(sa.DateTime(), index=True)
|
col = sa.Column(sa.DateTime(), index=True)
|
||||||
|
elif sort_type == 'boolean':
|
||||||
|
col = sa.Column(sa.Boolean(), index=True)
|
||||||
else:
|
else:
|
||||||
col = sa.Column(sa.String(1000), index=True)
|
col = sa.Column(sa.String(1000), index=True)
|
||||||
setattr(Sort, '%s' % key['id'], col)
|
setattr(Sort, '%s' % key['id'], col)
|
||||||
|
|
|
@ -98,9 +98,13 @@ class Parser(object):
|
||||||
q = ~q
|
q = ~q
|
||||||
return q
|
return q
|
||||||
elif key_type == 'boolean':
|
elif key_type == 'boolean':
|
||||||
q = getattr(self._model, 'find_%s' % k) == v
|
v = str(v).lower()
|
||||||
if exclude:
|
v = v == 'true'
|
||||||
q = ~q
|
vk = getattr(self._sort, k)
|
||||||
|
q = operators.eq(vk, v)
|
||||||
|
ids = self._model.query.join(self._sort).filter(q).options(load_only('id'))
|
||||||
|
in_op = operators.notin_op if exclude else operators.in_op
|
||||||
|
q = in_op(self._model.id, ids)
|
||||||
return q
|
return q
|
||||||
elif key_type in ("string", "text"):
|
elif key_type in ("string", "text"):
|
||||||
if isinstance(v, str):
|
if isinstance(v, str):
|
||||||
|
|
|
@ -389,7 +389,8 @@ def migrate_4():
|
||||||
def migrate_5():
|
def migrate_5():
|
||||||
db.run_sql([
|
db.run_sql([
|
||||||
'DROP INDEX IF EXISTS user_metadata_index',
|
'DROP INDEX IF EXISTS user_metadata_index',
|
||||||
'CREATE UNIQUE INDEX user_metadata_index ON user_metadata(item_id, user_id)'
|
'CREATE UNIQUE INDEX user_metadata_index ON user_metadata(item_id, user_id)',
|
||||||
|
'UPDATE sort SET sharemetadata = 0',
|
||||||
]),
|
]),
|
||||||
with db.session() as session:
|
with db.session() as session:
|
||||||
import user.models
|
import user.models
|
||||||
|
|
Loading…
Reference in a new issue