query fixes, avoid empty authors
This commit is contained in:
parent
198a01f05b
commit
1e082c3d1b
3 changed files with 14 additions and 5 deletions
|
@ -18,3 +18,8 @@ class Cache(dict):
|
||||||
ttl = ttl or self._ttl
|
ttl = ttl or self._ttl
|
||||||
self._added[key] = time.time() + ttl
|
self._added[key] = time.time() + ttl
|
||||||
dict.__setitem__(self, key, value)
|
dict.__setitem__(self, key, value)
|
||||||
|
|
||||||
|
def delete(self, key):
|
||||||
|
if key in self._addedd:
|
||||||
|
del self._added[key]
|
||||||
|
del self[key]
|
||||||
|
|
|
@ -60,7 +60,10 @@ def metadata(f, from_=None):
|
||||||
data['primaryid'] = ['asin', data['asin'][0]]
|
data['primaryid'] = ['asin', data['asin'][0]]
|
||||||
if 'author' in data:
|
if 'author' in data:
|
||||||
if isinstance(data['author'], basestring):
|
if isinstance(data['author'], basestring):
|
||||||
data['author'] = data['author'].split('; ')
|
if data['author'].strip():
|
||||||
|
data['author'] = data['author'].strip().split('; ')
|
||||||
|
else:
|
||||||
|
del data['author']
|
||||||
if data['author'] in (['Administrator'], ['Default'], ['user']):
|
if data['author'] in (['Administrator'], ['Default'], ['user']):
|
||||||
del data['author']
|
del data['author']
|
||||||
if not 'title' in data:
|
if not 'title' in data:
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from sqlalchemy.sql import operators
|
from sqlalchemy.sql import operators
|
||||||
from sqlalchemy.orm import load_only
|
|
||||||
|
|
||||||
import utils
|
import utils
|
||||||
import settings
|
import settings
|
||||||
|
@ -41,6 +40,7 @@ class Parser(object):
|
||||||
def __init__(self, model):
|
def __init__(self, model):
|
||||||
self._model = model
|
self._model = model
|
||||||
self._find = model.find.mapper.class_
|
self._find = model.find.mapper.class_
|
||||||
|
self._sort = model.sort.mapper.class_
|
||||||
self._user = model.users.mapper.class_
|
self._user = model.users.mapper.class_
|
||||||
self._list = model.lists.mapper.class_
|
self._list = model.lists.mapper.class_
|
||||||
self.item_keys = model.item_keys
|
self.item_keys = model.item_keys
|
||||||
|
@ -145,13 +145,15 @@ class Parser(object):
|
||||||
return datetime(*[int(i) for i in d])
|
return datetime(*[int(i) for i in d])
|
||||||
#using sort here since find only contains strings
|
#using sort here since find only contains strings
|
||||||
v = parse_date(v.split('-'))
|
v = parse_date(v.split('-'))
|
||||||
vk = getattr(self._model, 'sort_%s' % k)
|
vk = getattr(self._sort, k)
|
||||||
q = get_operator(op, 'int')(vk, v)
|
q = get_operator(op, 'int')(vk, v)
|
||||||
|
self._joins.append(self._sort)
|
||||||
if exclude:
|
if exclude:
|
||||||
q = ~q
|
q = ~q
|
||||||
return q
|
return q
|
||||||
else: #integer, float, time
|
else: #integer, float, time
|
||||||
q = get_operator(op, 'int')(getattr(self._model, 'sort_%s'%k), v)
|
q = get_operator(op, 'int')(getattr(self._sort, k), v)
|
||||||
|
self._joins.append(self._sort)
|
||||||
if exclude:
|
if exclude:
|
||||||
q = ~q
|
q = ~q
|
||||||
return q
|
return q
|
||||||
|
@ -232,4 +234,3 @@ class Parser(object):
|
||||||
qs = qs.filter(c)
|
qs = qs.filter(c)
|
||||||
qs = qs.group_by(self._model.id)
|
qs = qs.group_by(self._model.id)
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue