make api query more accessible in shell

This commit is contained in:
j 2016-01-10 14:40:38 +05:30
parent 38779d2576
commit 8db9bdb9e2
4 changed files with 12 additions and 9 deletions

View file

@ -18,6 +18,7 @@ from db import MutableDict
import json_pickler
from .icons import icons
from .person import get_sort_name
from queryparser import Parser
from settings import config
from utils import remove_empty_folders
from websocket import trigger_event
@ -91,6 +92,10 @@ class Item(db.Model):
state.db.session.commit()
return item
@classmethod
def find(cls, data):
return Parser(cls, user_items, Find, Sort).find(data)
def add_user(self, user):
if not user in self.users:
self.users.append(user)
@ -514,7 +519,7 @@ class Find(db.Model):
id = sa.Column(sa.Integer(), primary_key=True)
item_id = sa.Column(sa.String(32), sa.ForeignKey('item.id'))
item = sa.orm.relationship('Item', backref=sa.orm.backref('find', lazy='dynamic'))
item = sa.orm.relationship('Item', backref=sa.orm.backref('find_', lazy='dynamic'))
key = sa.Column(sa.String(200), index=True)
value = sa.Column(sa.Text())
findvalue = sa.Column(sa.Text(), index=True)

View file

@ -5,7 +5,6 @@
#does not work in sqlite
#from sqlalchemy.sql.expression import nullslast
from queryparser import Parser
from . import models
import settings
import utils
@ -19,7 +18,7 @@ def parse(data):
if key in data:
query[key] = data[key]
#print data
query['qs'] = Parser(models.Item, models.user_items).find(data)
query['qs'] = models.Item.find(data)
if not 'group' in query:
query['qs'] = order(query['qs'], query['sort'])
return query

View file

@ -38,10 +38,10 @@ def get_operator(op, type='str'):
class Parser(object):
def __init__(self, model, user_items):
def __init__(self, model, user_items, find, sort):
self._model = model
self._find = model.find.mapper.class_
self._sort = model.sort.mapper.class_
self._find = find
self._sort = sort
self._user = model.users.mapper.class_
self._user_items = user_items
self._list = model.lists.mapper.class_

View file

@ -7,7 +7,6 @@ import sqlalchemy as sa
from changelog import Changelog
from db import MutableDict
from queryparser import Parser
import db
import json_pickler
import settings
@ -268,9 +267,9 @@ class List(db.Model):
self.user.clear_list_cache()
def get_items(self):
from item.models import Item, user_items
from item.models import Item
if self.type == 'smart':
return Parser(Item, user_items).find({'query': self._query})
return Item.find({'query': self._query})
else:
return self.user.items.join(Item.lists, aliased=True).filter(List.id == self.id)