forked from 0x2620/pandora
merge
This commit is contained in:
commit
459fe87f7c
4 changed files with 15 additions and 6 deletions
|
@ -171,5 +171,4 @@ class ClipManager(Manager):
|
||||||
filter_layers = filter(lambda k: k in public_layers, data['keys'])
|
filter_layers = filter(lambda k: k in public_layers, data['keys'])
|
||||||
if filter_layers:
|
if filter_layers:
|
||||||
qs = qs.filter(annotations__layer__name__in=filter_layers)
|
qs = qs.filter(annotations__layer__name__in=filter_layers)
|
||||||
qs = qs.distinct()
|
|
||||||
return qs
|
return qs
|
||||||
|
|
|
@ -9,6 +9,10 @@ from archive import extract
|
||||||
import managers
|
import managers
|
||||||
|
|
||||||
class Clip(models.Model):
|
class Clip(models.Model):
|
||||||
|
'''
|
||||||
|
CREATE INDEX clip_clip_title_idx ON clip_clip (title ASC NULLS LAST);
|
||||||
|
CREATE INDEX clip_clip_director_idx ON clip_clip (director ASC NULLS LAST);
|
||||||
|
'''
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ("item", "start", "end")
|
unique_together = ("item", "start", "end")
|
||||||
|
|
||||||
|
@ -32,6 +36,9 @@ class Clip(models.Model):
|
||||||
lightness = models.FloatField(default=0, db_index=True)
|
lightness = models.FloatField(default=0, db_index=True)
|
||||||
volume = models.FloatField(default=0, null=True, db_index=True)
|
volume = models.FloatField(default=0, null=True, db_index=True)
|
||||||
|
|
||||||
|
director = models.CharField(max_length=1000)
|
||||||
|
title = models.CharField(max_length=1000)
|
||||||
|
|
||||||
def update_calculated_values(self):
|
def update_calculated_values(self):
|
||||||
self.duration = self.end - self.start
|
self.duration = self.end - self.start
|
||||||
if self.duration > 0:
|
if self.duration > 0:
|
||||||
|
@ -41,6 +48,8 @@ class Clip(models.Model):
|
||||||
else:
|
else:
|
||||||
self.hue = self.saturation = self.lightness = 0
|
self.hue = self.saturation = self.lightness = 0
|
||||||
self.volume = 0
|
self.volume = 0
|
||||||
|
self.director = self.item.sort.director
|
||||||
|
self.title = self.item.sort.title
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.public_id = u"%s/%s-%s" %(self.item.itemId, self.start, self.end)
|
self.public_id = u"%s/%s-%s" %(self.item.itemId, self.start, self.end)
|
||||||
|
|
|
@ -20,7 +20,7 @@ def parse_query(data, user):
|
||||||
if key in data:
|
if key in data:
|
||||||
query[key] = data[key]
|
query[key] = data[key]
|
||||||
query['qs'] = models.Clip.objects.find(query, user)
|
query['qs'] = models.Clip.objects.find(query, user)
|
||||||
if 'itemQuery' in data:
|
if 'itemQuery' in data and data['itemQuery'].get('conditions'):
|
||||||
item_query = Item.objects.find({'query': data['itemQuery']}, user)
|
item_query = Item.objects.find({'query': data['itemQuery']}, user)
|
||||||
query['qs'] = query['qs'].filter(item__in=item_query)
|
query['qs'] = query['qs'].filter(item__in=item_query)
|
||||||
return query
|
return query
|
||||||
|
@ -32,7 +32,8 @@ def order_query(qs, sort):
|
||||||
if operator != '-':
|
if operator != '-':
|
||||||
operator = ''
|
operator = ''
|
||||||
clip_keys = ('public_id', 'start', 'end', 'hue', 'saturation', 'lightness', 'volume',
|
clip_keys = ('public_id', 'start', 'end', 'hue', 'saturation', 'lightness', 'volume',
|
||||||
'annotations__value')
|
'annotations__value',
|
||||||
|
'director', 'title')
|
||||||
key = {
|
key = {
|
||||||
'id': 'public_id',
|
'id': 'public_id',
|
||||||
'in': 'start',
|
'in': 'start',
|
||||||
|
@ -53,7 +54,6 @@ def order_query(qs, sort):
|
||||||
order_by.append(order)
|
order_by.append(order)
|
||||||
if order_by:
|
if order_by:
|
||||||
qs = qs.order_by(*order_by, nulls_last=True)
|
qs = qs.order_by(*order_by, nulls_last=True)
|
||||||
qs = qs.distinct()
|
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
def findClips(request):
|
def findClips(request):
|
||||||
|
@ -76,7 +76,8 @@ def findClips(request):
|
||||||
query = parse_query(data, request.user)
|
query = parse_query(data, request.user)
|
||||||
qs = order_query(query['qs'], query['sort'])
|
qs = order_query(query['qs'], query['sort'])
|
||||||
if 'keys' in data:
|
if 'keys' in data:
|
||||||
qs = qs.select_related()[query['range'][0]:query['range'][1]]
|
qs = qs.select_related()
|
||||||
|
qs = qs[query['range'][0]:query['range'][1]]
|
||||||
response['data']['items'] = [p.json(keys=data['keys']) for p in qs]
|
response['data']['items'] = [p.json(keys=data['keys']) for p in qs]
|
||||||
elif 'position' in query:
|
elif 'position' in query:
|
||||||
ids = [i.public_id for i in qs]
|
ids = [i.public_id for i in qs]
|
||||||
|
|
|
@ -242,7 +242,7 @@ class ItemManager(Manager):
|
||||||
#only include items that have hard metadata
|
#only include items that have hard metadata
|
||||||
conditions = parseConditions(data.get('query', {}).get('conditions', []),
|
conditions = parseConditions(data.get('query', {}).get('conditions', []),
|
||||||
data.get('query', {}).get('operator', '&'))
|
data.get('query', {}).get('operator', '&'))
|
||||||
qs = qs.filter(conditions).distinct()
|
qs = qs.filter(conditions)
|
||||||
|
|
||||||
#anonymous can only see public items
|
#anonymous can only see public items
|
||||||
if user.is_anonymous():
|
if user.is_anonymous():
|
||||||
|
|
Loading…
Reference in a new issue