fix findClips for layers no in clipLayers

This commit is contained in:
j 2014-11-17 14:12:29 +00:00
parent 5a971909d0
commit 16f1dbca93
3 changed files with 16 additions and 13 deletions

View file

@ -7,7 +7,7 @@ from django.conf import settings
from ox.django.query import QuerySet
from item.utils import decode_id
from item.utils import decode_id, get_by_id
def parseCondition(condition, user):
@ -38,7 +38,7 @@ def parseCondition(condition, user):
op = condition.get('operator')
if not op:
op = ''
if k in settings.CONFIG.get('clipLayers', []):
if get_by_id(settings.CONFIG['layers'], k):
return parseCondition({'key': 'annotations__findvalue',
'value': v,
'operator': op}, user) \
@ -144,7 +144,8 @@ class ClipManager(Manager):
return QuerySet(self.model)
def filter_annotations(self, data, user):
keys = settings.CONFIG['clipLayers'] + ['annotations', 'text', '*']
layer_ids = [k['id'] for k in settings.CONFIG['layers']]
keys = layer_ids + ['annotations', 'text', '*']
conditions = data.get('query', {}).get('conditions', [])
conditions = filter(lambda c: c['key'] in keys, conditions)
operator = data.get('query', {}).get('operator', '&')
@ -163,7 +164,7 @@ class ClipManager(Manager):
if isinstance(v, unicode):
v = unicodedata.normalize('NFKD', v).lower()
q = Q(**{key: v})
if condition['key'] in settings.CONFIG['clipLayers']:
if condition['key'] in layer_ids:
q = q & Q(layer=condition['key'])
return q
conditions = map(parse, conditions)
@ -208,7 +209,8 @@ class ClipManager(Manager):
if conditions:
qs = qs.filter(conditions)
if 'keys' in data:
for l in filter(lambda k: k in settings.CONFIG['clipLayers'], data['keys']):
layer_ids = [k['id'] for k in settings.CONFIG['layers']]
for l in filter(lambda k: k in layer_ids, data['keys']):
qs = qs.filter(**{l: True})
#anonymous can only see public clips
if not user or user.is_anonymous():

View file

@ -49,7 +49,7 @@ class MetaClip:
else:
self.sortvalue = None
self.findvalue = '\n'.join(filter(None, [a.findvalue for a in self.annotations.all()]))
for l in settings.CONFIG['clipLayers']:
for l in [k['id'] for k in settings.CONFIG['layers']]:
setattr(self, l, self.annotations.filter(layer=l).count()>0)
models.Model.save(self, *args, **kwargs)
@ -73,11 +73,11 @@ class MetaClip:
del j[key]
#needed here to make item find with clips work
if 'annotations' in keys:
annotations = self.annotations.filter(layer__in=settings.CONFIG['clipLayers'])
#annotations = self.annotations.filter(layer__in=settings.CONFIG['clipLayers'])
annotations = self.annotations.all()
if qs:
annotations = annotations.filter(qs)
j['annotations'] = [a.json(keys=['value', 'id', 'layer'])
for a in annotations]
j['annotations'] = [a.json(keys=['value', 'id', 'layer']) for a in annotations]
if 'layers' in keys:
j['layers'] = self.get_layers()
if 'cuts' in keys:
@ -184,7 +184,7 @@ attrs = {
'sortvalue': models.CharField(max_length=1000, null=True, db_index=True),
'findvalue': models.TextField(null=True, db_index=settings.DB_GIN_TRGM),
}
for name in settings.CONFIG['clipLayers']:
for name in [k['id'] for k in settings.CONFIG['layers']]:
attrs[name] = models.BooleanField(default=False, db_index=True)
Clip = type('Clip', (MetaClip,models.Model), attrs)

View file

@ -102,8 +102,8 @@ def findClips(request, data):
qs = qs[query['range'][0]:query['range'][1]]
ids = []
keys = filter(lambda k: k not in settings.CONFIG['clipLayers'] + ['annotations'],
data['keys'])
layer_ids = [k['id'] for k in settings.CONFIG['layers']]
keys = filter(lambda k: k not in layer_ids + ['annotations'], data['keys'])
if filter(lambda k: k not in models.Clip.clip_keys, keys):
qs = qs.select_related('sort')
@ -144,7 +144,8 @@ def findClips(request, data):
aqs = Annotation.objects.filter(layer__in=settings.CONFIG['clipLayers'],
clip__in=ids)
add_annotations('annotations',aqs , True)
for layer in filter(lambda l: l in keys, settings.CONFIG['clipLayers']):
layer_ids = [k['id'] for k in settings.CONFIG['layers']]
for layer in filter(lambda l: l in keys, layer_ids):
aqs = Annotation.objects.filter(layer=layer, clip__in=ids)
add_annotations(layer, aqs)
elif 'position' in query: