fix findMedia by list
This commit is contained in:
parent
74c4d718ab
commit
557c078319
1 changed files with 29 additions and 0 deletions
|
@ -7,6 +7,7 @@ from oxdjango.managers import get_operator
|
|||
from oxdjango.query import QuerySet
|
||||
from oxdjango.fields import DictField
|
||||
|
||||
|
||||
keymap = {
|
||||
'id': 'item__public_id',
|
||||
'filename': 'path',
|
||||
|
@ -16,6 +17,9 @@ default_key = 'oshash'
|
|||
def parseCondition(condition, user):
|
||||
'''
|
||||
'''
|
||||
from item.managers import parseConditions as itemParseConditions
|
||||
from itemlist.models import List
|
||||
from item.models import Item
|
||||
k = condition.get('key', default_key)
|
||||
k = keymap.get(k, k)
|
||||
if not k:
|
||||
|
@ -34,6 +38,31 @@ def parseCondition(condition, user):
|
|||
elif k == 'url':
|
||||
key = 'info' + get_operator('=', 'istr')
|
||||
v = DictField.dumps({'url': v})[1:-1]
|
||||
elif k == 'list':
|
||||
q = Q(id=0)
|
||||
l = v.split(":")
|
||||
if len(l) == 1:
|
||||
vqs = Volume.objects.filter(name=v, user=user)
|
||||
if vqs.count() == 1:
|
||||
v = vqs[0]
|
||||
q = Q(files__instances__volume__id=v.id)
|
||||
elif len(l) >= 2:
|
||||
l = (l[0], ":".join(l[1:]))
|
||||
lqs = list(List.objects.filter(name=l[1], user__username=l[0]))
|
||||
if len(lqs) == 1 and lqs[0].accessible(user):
|
||||
l = lqs[0]
|
||||
if l.query.get('static', False) is False:
|
||||
data = l.query
|
||||
q = itemParseConditions(data.get('conditions', []),
|
||||
data.get('operator', '&'),
|
||||
user, l.user)
|
||||
else:
|
||||
q = Q(id__in=l.items.all())
|
||||
if exclude:
|
||||
q = ~q
|
||||
else:
|
||||
q = Q(id=0)
|
||||
return Q(item__in=Item.objects.filter(q))
|
||||
else:
|
||||
key = k + get_operator(op, 'istr')
|
||||
key = str(key)
|
||||
|
|
Loading…
Reference in a new issue