add sharemetadata to itemKeys. fix queries for boolean keys

This commit is contained in:
j 2016-01-19 16:44:00 +05:30
parent cd63cca194
commit 54b3982787
4 changed files with 26 additions and 5 deletions

View File

@ -233,6 +233,13 @@
"format": {"type": "percent", "args": [1, 0]},
"sort": true
},
{
"id": "sharemetadata",
"title": "Share Metadata",
"type": "boolean",
"columnWidth": 144,
"sort": true
},
{
"id": "random",
"title": "Random",

View File

@ -176,6 +176,8 @@ class Item(db.Model):
value = ''.join(value)
value = ox.get_sort_title(value)
value = utils.sort_title(value).lower()
elif sort_type == 'boolean':
pass
else:
if isinstance(value, list):
value = '\n'.join(value)
@ -203,11 +205,16 @@ class Item(db.Model):
keys = []
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)
if key.get('filterMap') and value:
value = re.compile(key.get('filterMap')).findall(value)
if value: value = value[0]
if key.get('type') == 'boolean':
value = True if value else False
value = str(value).lower()
if value:
keys.append(key['id'])
if isinstance(value, dict):
@ -528,6 +535,8 @@ for key in config['itemKeys']:
col = sa.Column(sa.Float(), index=True)
elif sort_type == 'date':
col = sa.Column(sa.DateTime(), index=True)
elif sort_type == 'boolean':
col = sa.Column(sa.Boolean(), index=True)
else:
col = sa.Column(sa.String(1000), index=True)
setattr(Sort, '%s' % key['id'], col)

View File

@ -98,9 +98,13 @@ class Parser(object):
q = ~q
return q
elif key_type == 'boolean':
q = getattr(self._model, 'find_%s' % k) == v
if exclude:
q = ~q
v = str(v).lower()
v = v == 'true'
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
elif key_type in ("string", "text"):
if isinstance(v, str):

View File

@ -389,7 +389,8 @@ def migrate_4():
def migrate_5():
db.run_sql([
'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:
import user.models