support groups itemKey with special value , 1879
This commit is contained in:
parent
183c550078
commit
1556699723
2 changed files with 46 additions and 43 deletions
|
@ -431,6 +431,11 @@
|
||||||
"capability": "canSeeMedia",
|
"capability": "canSeeMedia",
|
||||||
"find": true
|
"find": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "groups",
|
||||||
|
"title": "Group",
|
||||||
|
"type": ["string"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "filename",
|
"id": "filename",
|
||||||
"title": "Filename",
|
"title": "Filename",
|
||||||
|
|
|
@ -8,11 +8,34 @@ from django.conf import settings
|
||||||
|
|
||||||
from archive.models import Volume
|
from archive.models import Volume
|
||||||
from itemlist.models import List
|
from itemlist.models import List
|
||||||
|
from django.contrib.auth.models import Group
|
||||||
import models
|
import models
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
from ox.django.query import QuerySet
|
from ox.django.query import QuerySet
|
||||||
|
|
||||||
|
def get_operator(op, type='str'):
|
||||||
|
return {
|
||||||
|
'str': {
|
||||||
|
'==': '__iexact',
|
||||||
|
'>': '__gt',
|
||||||
|
'>=': '__gte',
|
||||||
|
'<': '__lt',
|
||||||
|
'<=': '__lte',
|
||||||
|
'^': '__istartswith',
|
||||||
|
'$': '__iendswith',
|
||||||
|
},
|
||||||
|
'int': {
|
||||||
|
'==': '__exact',
|
||||||
|
'>': '__gt',
|
||||||
|
'>=': '__gte',
|
||||||
|
'<': '__lt',
|
||||||
|
'<=': '__lte',
|
||||||
|
}
|
||||||
|
}[type].get(op, {
|
||||||
|
'str': '__icontains',
|
||||||
|
'int': ''
|
||||||
|
}[type])
|
||||||
|
|
||||||
def parseCondition(condition, user, owner=None):
|
def parseCondition(condition, user, owner=None):
|
||||||
'''
|
'''
|
||||||
|
@ -57,13 +80,17 @@ def parseCondition(condition, user, owner=None):
|
||||||
if k == 'list':
|
if k == 'list':
|
||||||
key_type = ''
|
key_type = ''
|
||||||
|
|
||||||
if v == '{me}' and op == '==':
|
if k == 'groups':
|
||||||
|
if op == '==' and v == '$my':
|
||||||
if not owner:
|
if not owner:
|
||||||
owner = user
|
owner = user
|
||||||
if k == 'user':
|
groups = owner.groups.all()
|
||||||
v = owner.username
|
else:
|
||||||
elif k == 'groups':
|
key = 'name' + get_operator(op)
|
||||||
q = Q(groups__in=owner.groups.all())
|
groups = Group.objects.filter(**{key: v})
|
||||||
|
if not groups.count():
|
||||||
|
return Q(id=0)
|
||||||
|
q = Q(groups__in=groups)
|
||||||
if exclude:
|
if exclude:
|
||||||
q = ~q
|
q = ~q
|
||||||
return q
|
return q
|
||||||
|
@ -115,28 +142,11 @@ def parseCondition(condition, user, owner=None):
|
||||||
value_key = k
|
value_key = k
|
||||||
if k in facet_keys:
|
if k in facet_keys:
|
||||||
in_find = False
|
in_find = False
|
||||||
facet_value = 'facets__value%s' % {
|
facet_value = 'facets__value' + get_operator(op)
|
||||||
'==': '__iexact',
|
|
||||||
'>': '__gt',
|
|
||||||
'>=': '__gte',
|
|
||||||
'<': '__lt',
|
|
||||||
'<=': '__lte',
|
|
||||||
'^': '__istartswith',
|
|
||||||
'$': '__iendswith',
|
|
||||||
}.get(op, '__icontains')
|
|
||||||
v = models.Item.objects.filter(**{'facets__key':k, facet_value:v})
|
v = models.Item.objects.filter(**{'facets__key':k, facet_value:v})
|
||||||
value_key = 'id__in'
|
value_key = 'id__in'
|
||||||
else:
|
else:
|
||||||
value_key = '%s%s' % (value_key, {
|
value_key = value_key + get_operator(op)
|
||||||
'==': '__iexact',
|
|
||||||
'>': '__gt',
|
|
||||||
'>=': '__gte',
|
|
||||||
'<': '__lt',
|
|
||||||
'<=': '__lte',
|
|
||||||
'^': '__istartswith',
|
|
||||||
'$': '__iendswith',
|
|
||||||
}.get(op, '__icontains'))
|
|
||||||
|
|
||||||
k = str(k)
|
k = str(k)
|
||||||
value_key = str(value_key)
|
value_key = str(value_key)
|
||||||
if isinstance(v, unicode):
|
if isinstance(v, unicode):
|
||||||
|
@ -183,13 +193,7 @@ def parseCondition(condition, user, owner=None):
|
||||||
|
|
||||||
#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 = 'sort__%s%s' % (k, {
|
vk = 'sort__%s%s' % (k, get_operator(op, 'int'))
|
||||||
'==': '__exact',
|
|
||||||
'>': '__gt',
|
|
||||||
'>=': '__gte',
|
|
||||||
'<': '__lt',
|
|
||||||
'<=': '__lte',
|
|
||||||
}.get(op,''))
|
|
||||||
vk = str(vk)
|
vk = str(vk)
|
||||||
q = Q(**{vk: v})
|
q = Q(**{vk: v})
|
||||||
if exclude:
|
if exclude:
|
||||||
|
@ -200,13 +204,7 @@ def parseCondition(condition, user, owner=None):
|
||||||
if key_type == 'time':
|
if key_type == 'time':
|
||||||
v = int(utils.parse_time(v))
|
v = int(utils.parse_time(v))
|
||||||
|
|
||||||
vk = 'sort__%s%s' % (k, {
|
vk = 'sort__%s%s' % (k, get_operator(op, 'int'))
|
||||||
'==': '__exact',
|
|
||||||
'>': '__gt',
|
|
||||||
'>=': '__gte',
|
|
||||||
'<': '__lt',
|
|
||||||
'<=': '__lte',
|
|
||||||
}.get(op,''))
|
|
||||||
vk = str(vk)
|
vk = str(vk)
|
||||||
q = Q(**{vk: v})
|
q = Q(**{vk: v})
|
||||||
if exclude:
|
if exclude:
|
||||||
|
|
Loading…
Reference in a new issue