forked from 0x2620/pandora
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
|
||||
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):
|
||||
'''
|
||||
'''
|
||||
|
@ -29,10 +40,12 @@ def parseCondition(condition, user, item=None):
|
|||
return Q(**{k: v})
|
||||
if isinstance(v, bool): #featured and public flag
|
||||
key = k
|
||||
elif k == 'name_find':
|
||||
key, v = namePredicate(op, v)
|
||||
else:
|
||||
if k == '*':
|
||||
k = 'find__value'
|
||||
elif k not in ('name_find', 'id', 'user__username', 'type'):
|
||||
elif k not in ('id', 'user__username', 'type'):
|
||||
find_key = k
|
||||
k = 'find__value'
|
||||
key = "%s%s" % (k, {
|
||||
|
|
|
@ -19,6 +19,7 @@ from itemlist.models import List
|
|||
from changelog.models import add_changelog
|
||||
|
||||
import models
|
||||
from managers import namePredicate
|
||||
|
||||
def get_entity_or_404_json(id):
|
||||
try:
|
||||
|
@ -119,14 +120,8 @@ def autocompleteEntities(request, data):
|
|||
|
||||
qs = models.Entity.objects.filter(type=data['key'])
|
||||
if data['value']:
|
||||
if op == '=':
|
||||
qs = qs.filter(name_find__icontains=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'])
|
||||
elif op == '$':
|
||||
qs = qs.filter(name_find__icontains=u'%s|'%data['value'])
|
||||
k, v = namePredicate(op, data['value'])
|
||||
qs = qs.filter(**{k: v})
|
||||
qs = qs.order_by(order_by)
|
||||
if op != '$':
|
||||
value_lower = data['value'].lower()
|
||||
|
|
Loading…
Reference in a new issue