ClipManager: match annotation layer case-sensitively (fixes #2832)

The case must be correct anyway for the layer to be found in
settings.CONFIG['layers']. Running this:

    Q(annotation__layer__iexact='foo') &
    Q(annotation__findvalue__icontains='bar')

compiles to

    upper(layer) = upper('foo') and
    ...

which can't use the case-sensitive annotation_annotation_layer index.
This:

    Q(annotation__layer__exact='foo') &
    Q(annotation__findvalue__icontains='bar')

can. (It still can't use the findvalue_like index, though! The other
option is to add indices on upper(layer) and upper(findvalue)
[varchar_pattern_ops].)
This commit is contained in:
Will Thompson 2015-09-14 14:13:06 +02:00 committed by j
parent da1ad5b9c1
commit eaa07b1ccb

View file

@ -44,7 +44,7 @@ def parseCondition(condition, user):
'operator': op}, user) \
& parseCondition({'key': 'annotations__layer',
'value': k,
'operator': '=='}, user)
'operator': '==='}, user)
if op.startswith('!'):
op = op[1:]
@ -82,6 +82,7 @@ def parseCondition(condition, user):
'>=': '__gte',
'<': '__lt',
'<=': '__lte',
'===': '__exact',
'==': '__iexact',
'=': '__icontains',
'^': '__istartswith',
@ -89,7 +90,7 @@ def parseCondition(condition, user):
}.get(op, '__icontains'))
key = str(key)
if isinstance(v, unicode):
if isinstance(v, unicode) and op != '===':
v = unicodedata.normalize('NFKD', v).lower()
if exclude:
q = ~Q(**{key: v})