forked from 0x2620/pandora
store clip values in clip db, cleanup if all annotations are gone, add additionalSort
This commit is contained in:
parent
10a1239df7
commit
16cc495fb5
10 changed files with 109 additions and 99 deletions
|
|
@ -27,8 +27,8 @@ def parseCondition(condition, user):
|
|||
'in': 'start',
|
||||
'out': 'end',
|
||||
'place': 'annotations__places__id',
|
||||
'text': 'annotations__findvalue',
|
||||
'annotations': 'annotations__findvalue',
|
||||
'text': 'findvalue',
|
||||
'annotations': 'findvalue',
|
||||
'user': 'annotations__user__username',
|
||||
}.get(k, k)
|
||||
if not k:
|
||||
|
|
@ -37,10 +37,7 @@ def parseCondition(condition, user):
|
|||
op = condition.get('operator')
|
||||
if not op:
|
||||
op = ''
|
||||
public_layers = [l['id']
|
||||
for l in filter(lambda l: not l.get('private', False),
|
||||
settings.CONFIG['layers'])]
|
||||
if k in public_layers:
|
||||
if k in settings.CONFIG['clipLayers']:
|
||||
return parseCondition({'key': 'annotations__findvalue',
|
||||
'value': v,
|
||||
'operator': op}, user) \
|
||||
|
|
@ -141,10 +138,7 @@ class ClipManager(Manager):
|
|||
return QuerySet(self.model)
|
||||
|
||||
def filter_annotations(self, data, user):
|
||||
public_layers = [l['id']
|
||||
for l in filter(lambda l: not l.get('private', False),
|
||||
settings.CONFIG['layers'])]
|
||||
keys = public_layers + ['annotations', 'text', '*']
|
||||
keys = settings.CONFIG['clipLayers'] + ['annotations', 'text', '*']
|
||||
conditions = data.get('query', {}).get('conditions', [])
|
||||
conditions = filter(lambda c: c['key'] in keys, conditions)
|
||||
operator = data.get('query', {}).get('operator', '&')
|
||||
|
|
@ -160,7 +154,7 @@ class ClipManager(Manager):
|
|||
'$': '__iendswith',
|
||||
}.get(condition.get('opterator', ''), '__icontains'))
|
||||
q = Q(**{key: condition['value']})
|
||||
if condition['key'] in public_layers:
|
||||
if condition['key'] in settings.CONFIG['clipLayers']:
|
||||
q = q & Q(layer=condition['key'])
|
||||
return q
|
||||
conditions = map(parse, conditions)
|
||||
|
|
@ -205,6 +199,6 @@ class ClipManager(Manager):
|
|||
if conditions:
|
||||
qs = qs.filter(conditions)
|
||||
if 'keys' in data:
|
||||
for l in filter(lambda k: k in self.model.layers, data['keys']):
|
||||
for l in filter(lambda k: k in settings.CONFIG['clipLayers'], data['keys']):
|
||||
qs = qs.filter(**{l: True})
|
||||
return qs
|
||||
|
|
|
|||
|
|
@ -35,8 +35,19 @@ class MetaClip:
|
|||
streams = self.item.streams()
|
||||
if streams:
|
||||
self.aspect_ratio = streams[0].aspect_ratio
|
||||
sortvalue = ''
|
||||
findvalue = ''
|
||||
for l in settings.CONFIG['clipLayers']:
|
||||
sortvalue += ''.join(filter(lambda s: s,
|
||||
[a.sortvalue
|
||||
for a in self.annotations.filter(layer=l).order_by('sortvalue')]))
|
||||
if sortvalue:
|
||||
self.sortvalue = sortvalue[:1000]
|
||||
else:
|
||||
self.sortvalue = None
|
||||
self.findvalue = '\n'.join([a.findvalue for a in self.annotations.all()])
|
||||
if self.id:
|
||||
for l in self.layers:
|
||||
for l in settings.CONFIG['clipLayers']:
|
||||
setattr(self, l, self.annotations.filter(layer=l).count()>0)
|
||||
models.Model.save(self, *args, **kwargs)
|
||||
|
||||
|
|
@ -60,7 +71,7 @@ class MetaClip:
|
|||
del j[key]
|
||||
#needed here to make item find with clips work
|
||||
if 'annotations' in keys:
|
||||
annotations = self.annotations.filter(layer__in=self.layers)
|
||||
annotations = self.annotations.filter(layer__in=settings.CONFIG['clipLayers'])
|
||||
if qs:
|
||||
annotations = annotations.filter(qs)
|
||||
j['annotations'] = [a.json(keys=['value', 'id', 'layer'])
|
||||
|
|
@ -118,13 +129,11 @@ attrs = {
|
|||
|
||||
'director': models.CharField(max_length=1000, null=True, db_index=True),
|
||||
'title': models.CharField(max_length=1000, db_index=True),
|
||||
'sortvalue': models.CharField(max_length=1000, null=True, db_index=True),
|
||||
'findvalue': models.TextField(),
|
||||
}
|
||||
public_layers = [l['id']
|
||||
for l in filter(lambda l: not l.get('private', False),
|
||||
settings.CONFIG['layers'])]
|
||||
for name in public_layers:
|
||||
for name in settings.CONFIG['clipLayers']:
|
||||
attrs[name] = models.BooleanField(default=False, db_index=True)
|
||||
|
||||
Clip = type('Clip', (MetaClip,models.Model), attrs)
|
||||
Clip.layers = public_layers
|
||||
|
||||
|
|
|
|||
|
|
@ -36,20 +36,20 @@ def order_query(qs, sort):
|
|||
if operator != '-':
|
||||
operator = ''
|
||||
clip_keys = ('public_id', 'start', 'end', 'hue', 'saturation', 'lightness', 'volume',
|
||||
'duration', 'annotations__sortvalue', 'videoRatio',
|
||||
'duration', 'sortvalue', 'videoRatio',
|
||||
'director', 'title')
|
||||
key = {
|
||||
'id': 'public_id',
|
||||
'in': 'start',
|
||||
'out': 'end',
|
||||
'position': 'start',
|
||||
'text': 'annotations__sortvalue',
|
||||
'text': 'sortvalue',
|
||||
'videoRatio': 'aspect_ratio',
|
||||
}.get(e['key'], e['key'])
|
||||
if key.startswith('clip:'):
|
||||
key = e['key'][len('clip:'):]
|
||||
key = {
|
||||
'text': 'annotations__sortvalue',
|
||||
'text': 'sortvalue',
|
||||
'position': 'start',
|
||||
}.get(key, key)
|
||||
elif key not in clip_keys:
|
||||
|
|
@ -85,7 +85,8 @@ def findClips(request):
|
|||
qs = qs[query['range'][0]:query['range'][1]]
|
||||
|
||||
ids = []
|
||||
keys = filter(lambda k: k not in models.Clip.layers + ['annotations'], data['keys'])
|
||||
keys = filter(lambda k: k not in settings.CONFIG['clipLayers'] + ['annotations'],
|
||||
data['keys'])
|
||||
if filter(lambda k: k not in models.Clip.clip_keys, keys):
|
||||
qs = qs.select_related('item__sort')
|
||||
|
||||
|
|
@ -116,9 +117,9 @@ def findClips(request):
|
|||
if response['data']['items']:
|
||||
if 'annotations' in keys:
|
||||
add_annotations('annotations',
|
||||
Annotation.objects.filter(layer__in=models.Clip.layers, clip__in=ids),
|
||||
True)
|
||||
for layer in filter(lambda l: l in keys, models.Clip.layers):
|
||||
Annotation.objects.filter(layer__in=settings.CONFIG['clipLayers'],
|
||||
clip__in=ids), True)
|
||||
for layer in filter(lambda l: l in keys, settings.CONFIG['clipLayers']):
|
||||
add_annotations(layer,
|
||||
Annotation.objects.filter(layer=layer, clip__in=ids))
|
||||
elif 'position' in query:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue