Fix findEntities( ... name == x ... ), fixes #2769
This commit is contained in:
parent
fe7f961ff6
commit
3ad9d4821b
2 changed files with 17 additions and 9 deletions
|
@ -5,6 +5,17 @@ from django.db.models import Q, Manager
|
||||||
import ox
|
import ox
|
||||||
from ox.django.query import QuerySet
|
from ox.django.query import QuerySet
|
||||||
|
|
||||||
|
|
||||||
|
def namePredicate(op, value):
|
||||||
|
pat = {
|
||||||
|
'==': '|%s|',
|
||||||
|
'^': '|%s',
|
||||||
|
'$': '%s|',
|
||||||
|
}.get(op, '%s')
|
||||||
|
|
||||||
|
return ('name_find__icontains', pat % value)
|
||||||
|
|
||||||
|
|
||||||
def parseCondition(condition, user, item=None):
|
def parseCondition(condition, user, item=None):
|
||||||
'''
|
'''
|
||||||
'''
|
'''
|
||||||
|
@ -29,10 +40,12 @@ def parseCondition(condition, user, item=None):
|
||||||
return Q(**{k: v})
|
return Q(**{k: v})
|
||||||
if isinstance(v, bool): #featured and public flag
|
if isinstance(v, bool): #featured and public flag
|
||||||
key = k
|
key = k
|
||||||
|
elif k == 'name_find':
|
||||||
|
key, v = namePredicate(op, v)
|
||||||
else:
|
else:
|
||||||
if k == '*':
|
if k == '*':
|
||||||
k = 'find__value'
|
k = 'find__value'
|
||||||
elif k not in ('name_find', 'id', 'user__username', 'type'):
|
elif k not in ('id', 'user__username', 'type'):
|
||||||
find_key = k
|
find_key = k
|
||||||
k = 'find__value'
|
k = 'find__value'
|
||||||
key = "%s%s" % (k, {
|
key = "%s%s" % (k, {
|
||||||
|
|
|
@ -19,6 +19,7 @@ from itemlist.models import List
|
||||||
from changelog.models import add_changelog
|
from changelog.models import add_changelog
|
||||||
|
|
||||||
import models
|
import models
|
||||||
|
from managers import namePredicate
|
||||||
|
|
||||||
def get_entity_or_404_json(id):
|
def get_entity_or_404_json(id):
|
||||||
try:
|
try:
|
||||||
|
@ -119,14 +120,8 @@ def autocompleteEntities(request, data):
|
||||||
|
|
||||||
qs = models.Entity.objects.filter(type=data['key'])
|
qs = models.Entity.objects.filter(type=data['key'])
|
||||||
if data['value']:
|
if data['value']:
|
||||||
if op == '=':
|
k, v = namePredicate(op, data['value'])
|
||||||
qs = qs.filter(name_find__icontains=data['value'])
|
qs = qs.filter(**{k: v})
|
||||||
elif op == '==':
|
|
||||||
qs = qs.filter(name_find__icontains=u'|%s|'%data['value'])
|
|
||||||
elif op == '^':
|
|
||||||
qs = qs.filter(name_find__icontains=u'|%s'%data['value'])
|
|
||||||
elif op == '$':
|
|
||||||
qs = qs.filter(name_find__icontains=u'%s|'%data['value'])
|
|
||||||
qs = qs.order_by(order_by)
|
qs = qs.order_by(order_by)
|
||||||
if op != '$':
|
if op != '$':
|
||||||
value_lower = data['value'].lower()
|
value_lower = data['value'].lower()
|
||||||
|
|
Loading…
Reference in a new issue