even more improvements to lists
This commit is contained in:
parent
1a8a478256
commit
3a8f437f96
7 changed files with 154 additions and 1748 deletions
|
|
@ -87,12 +87,13 @@ def parseCondition(condition):
|
|||
if len(l) == 2:
|
||||
lqs = List.objects.filter(name=l[1], user__username=l[0])
|
||||
if lqs.count() == 1:
|
||||
if lqs[0].query.get('static', False) == False:
|
||||
data = lqs[0].query
|
||||
q = parseConditions(data['conditions'],
|
||||
l = lqs[0]
|
||||
if l.query.get('static', False) == False:
|
||||
data = l.query
|
||||
q = parseConditions(data.get('conditions', []),
|
||||
data.get('operator', '&'))
|
||||
else:
|
||||
q = Q(id__in=lqs[0].items.all())
|
||||
q = Q(id__in=l.items.all())
|
||||
return q
|
||||
else: #number or date
|
||||
|
||||
|
|
@ -237,7 +238,7 @@ class ItemManager(Manager):
|
|||
qs = self.get_query_set()
|
||||
#only include items that have hard metadata
|
||||
qs = qs.filter(available=True)
|
||||
conditions = parseConditions(data['query']['conditions'],
|
||||
conditions = parseConditions(data['query'].get('conditions', []),
|
||||
data['query'].get('operator', '&'))
|
||||
if conditions:
|
||||
qs = qs.filter(conditions)
|
||||
|
|
|
|||
|
|
@ -206,3 +206,16 @@ def sort_title(title):
|
|||
#pad numbered titles
|
||||
title = re.sub('(\d+)', lambda x: '%010d' % int(x.group(0)), title)
|
||||
return title.strip()
|
||||
|
||||
def get_positions(ids, pos):
|
||||
'''
|
||||
>>> get_positions([1,2,3,4], [2,4])
|
||||
{2: 1, 4: 3}
|
||||
'''
|
||||
positions = {}
|
||||
for i in pos:
|
||||
try:
|
||||
positions[i] = ids.index(i)
|
||||
except:
|
||||
pass
|
||||
return positions
|
||||
|
|
|
|||
|
|
@ -70,16 +70,6 @@ def _parse_query(data, user):
|
|||
return query
|
||||
|
||||
|
||||
def _get_positions(ids, get_ids):
|
||||
positions = {}
|
||||
for i in get_ids:
|
||||
try:
|
||||
positions[i] = ids.index(i)
|
||||
except:
|
||||
pass
|
||||
return positions
|
||||
|
||||
|
||||
def find(request):
|
||||
'''
|
||||
param data {
|
||||
|
|
@ -184,7 +174,7 @@ Positions
|
|||
#FIXME: this does not scale for larger results
|
||||
response['data']['positions'] = {}
|
||||
ids = [j['value'] for j in qs]
|
||||
response['data']['positions'] = _get_positions(ids, query['ids'])
|
||||
response['data']['positions'] = utils.get_positions(ids, query['ids'])
|
||||
|
||||
elif 'range' in data:
|
||||
qs = qs[query['range'][0]:query['range'][1]]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue