positions not ids and other cleanups
This commit is contained in:
parent
b32ac91211
commit
3b85387481
9 changed files with 72 additions and 49 deletions
|
@ -360,12 +360,12 @@ Groups
|
|||
Positions
|
||||
param data {
|
||||
'query': query,
|
||||
'ids': []
|
||||
'positions': []
|
||||
}
|
||||
|
||||
query: query object, more on query syntax at
|
||||
https://wiki.0x2620.org/wiki/pandora/QuerySyntax
|
||||
ids: ids of items for which positions are required
|
||||
positions: ids of items for which positions are required
|
||||
return {
|
||||
status: {...},
|
||||
data: {
|
||||
|
@ -403,24 +403,24 @@ Positions
|
|||
qs = models.Facet.objects.filter(key=query['group']).filter(item__id__in=item_qs)
|
||||
qs = qs.values('value').annotate(items=Count('id')).order_by(*order_by)
|
||||
|
||||
if 'ids' in query:
|
||||
if 'positions' in query:
|
||||
#FIXME: this does not scale for larger results
|
||||
response['data']['positions'] = {}
|
||||
ids = [j['value'] for j in qs]
|
||||
response['data']['positions'] = utils.get_positions(ids, query['ids'])
|
||||
response['data']['positions'] = utils.get_positions(ids, query['positions'])
|
||||
|
||||
elif 'range' in data:
|
||||
qs = qs[query['range'][0]:query['range'][1]]
|
||||
response['data']['items'] = [{'name': i['value'], 'items': i[items]} for i in qs]
|
||||
else:
|
||||
response['data']['items'] = qs.count()
|
||||
elif 'ids' in query:
|
||||
elif 'positions' in query:
|
||||
#FIXME: this does not scale for larger results
|
||||
qs = _order_query(query['qs'], query['sort'])
|
||||
|
||||
response['data']['positions'] = {}
|
||||
ids = [j['itemId'] for j in qs.values('itemId')]
|
||||
response['data']['positions'] = utils.get_positions(ids, query['ids'])
|
||||
response['data']['positions'] = utils.get_positions(ids, query['positions'])
|
||||
|
||||
elif 'keys' in query:
|
||||
response['data']['items'] = []
|
||||
|
|
|
@ -238,8 +238,8 @@ class ItemManager(Manager):
|
|||
qs = self.get_query_set()
|
||||
#only include items that have hard metadata
|
||||
qs = qs.filter(available=True)
|
||||
conditions = parseConditions(data['query'].get('conditions', []),
|
||||
data['query'].get('operator', '&'))
|
||||
conditions = parseConditions(data.get('query', {}).get('conditions', []),
|
||||
data.get('query', {}).get('operator', '&'))
|
||||
qs = qs.filter(conditions).distinct()
|
||||
|
||||
#anonymous can only see public items
|
||||
|
|
|
@ -320,11 +320,6 @@ class Item(models.Model):
|
|||
|
||||
def get_layers(self, user=None):
|
||||
layers = {}
|
||||
layers['subtitles'] = []
|
||||
#FIXME: should subtitles be stored in Annotation?
|
||||
qs = self.files.filter(is_subtitle=True, is_main=True, available=True)
|
||||
if qs.count()>0:
|
||||
layers['subtitles'] = qs[0].srt()
|
||||
for l in Layer.objects.all():
|
||||
ll = layers.setdefault(l.name, [])
|
||||
qs = Annotation.objects.filter(layer=l, item=self)
|
||||
|
|
|
@ -14,6 +14,7 @@ from ox.utils import json
|
|||
from ox.django.decorators import login_required_json
|
||||
from ox.django.shortcuts import render_to_json_response, get_object_or_404_json, json_response
|
||||
from ox.django.http import HttpFileResponse
|
||||
from django.db.models import Q
|
||||
import ox
|
||||
|
||||
import models
|
||||
|
@ -22,6 +23,7 @@ import tasks
|
|||
|
||||
from archive.models import File
|
||||
from archive import extract
|
||||
from annotation.models import Annotation
|
||||
|
||||
from api.actions import actions
|
||||
|
||||
|
@ -82,14 +84,18 @@ def parse_query(data, user):
|
|||
query = {}
|
||||
query['range'] = [0, 100]
|
||||
query['sort'] = [{'key':'title', 'operator':'+'}]
|
||||
for key in ('sort', 'keys', 'group', 'range', 'ids'):
|
||||
for key in ('sort', 'keys', 'group', 'range', 'position', 'positions'):
|
||||
if key in data:
|
||||
query[key] = data[key]
|
||||
query['qs'] = models.Item.objects.find(data, user)
|
||||
if 'annotations' in data:
|
||||
query['annotations'] = data['annotations']
|
||||
#FIXME: annotations need manager find(data, user)
|
||||
query['aqs'] = Annotation.objects.filter(Q(layer__private=False)|Q(user=user))
|
||||
|
||||
#group by only allows sorting by name or number of itmes
|
||||
return query
|
||||
|
||||
|
||||
def find(request):
|
||||
'''
|
||||
param data {
|
||||
|
@ -147,12 +153,13 @@ Groups
|
|||
Positions
|
||||
param data {
|
||||
'query': query,
|
||||
'ids': []
|
||||
'positions': [],
|
||||
'sort': array
|
||||
}
|
||||
|
||||
query: query object, more on query syntax at
|
||||
https://wiki.0x2620.org/wiki/pandora/QuerySyntax
|
||||
ids: ids of items for which positions are required
|
||||
positions: ids of items for which positions are required
|
||||
return {
|
||||
status: {...},
|
||||
data: {
|
||||
|
@ -176,20 +183,31 @@ Positions
|
|||
qs = models.Facet.objects.filter(key=query['group']).filter(item__id__in=item_qs)
|
||||
qs = qs.values('value').annotate(items=Count('id')).order_by(*order_by)
|
||||
|
||||
if 'ids' in query:
|
||||
if 'positions' in query:
|
||||
response['data']['positions'] = {}
|
||||
ids = [j['value'] for j in qs]
|
||||
response['data']['positions'] = utils.get_positions(ids, query['ids'])
|
||||
response['data']['positions'] = utils.get_positions(ids, query['positions'])
|
||||
elif 'range' in data:
|
||||
qs = qs[query['range'][0]:query['range'][1]]
|
||||
response['data']['items'] = [{'name': i['value'], 'items': i[items]} for i in qs]
|
||||
else:
|
||||
response['data']['items'] = qs.count()
|
||||
elif 'ids' in query:
|
||||
elif 'position' in query:
|
||||
qs = _order_query(query['qs'], query['sort'])
|
||||
response['data']['positions'] = {}
|
||||
ids = [j['itemId'] for j in qs.values('itemId')]
|
||||
response['data']['positions'] = utils.get_positions(ids, query['ids'])
|
||||
data['conditions'] = data['conditions'] + {
|
||||
'value': query['position'],
|
||||
'key': query['sort'][0]['key'],
|
||||
'operator': '^'
|
||||
}
|
||||
query = parse_query(data, request.user)
|
||||
qs = _order_query(query['qs'], query['sort'])
|
||||
if qs.count() > 0:
|
||||
response['data']['position'] = utils.get_positions(ids, [qs[0].itemId])[0]
|
||||
elif 'positions' in query:
|
||||
qs = _order_query(query['qs'], query['sort'])
|
||||
ids = [j['itemId'] for j in qs.values('itemId')]
|
||||
response['data']['positions'] = utils.get_positions(ids, query['positions'])
|
||||
elif 'keys' in query:
|
||||
response['data']['items'] = []
|
||||
qs = _order_query(query['qs'], query['sort'])
|
||||
|
@ -206,6 +224,10 @@ Positions
|
|||
r[p] = m.sort.popularity
|
||||
else:
|
||||
r[p] = m.json.get(p, '')
|
||||
if 'annotations' in query:
|
||||
n = query['annotations']
|
||||
r['annotations'] = [a.json(layer=True)
|
||||
for a in query['aqs'].filter(itemID=m.id)[:n]]
|
||||
return r
|
||||
def only_p(m):
|
||||
r = {}
|
||||
|
@ -213,6 +235,10 @@ Positions
|
|||
m = json.loads(m)
|
||||
for p in _p:
|
||||
r[p] = m.get(p, '')
|
||||
if 'annotations' in query:
|
||||
n = query['annotations']
|
||||
r['annotations'] = [a.json(layer=True)
|
||||
for a in query['aqs'].filter(item__itemId=m['id'])[:n]]
|
||||
return r
|
||||
qs = qs[query['range'][0]:query['range'][1]]
|
||||
#response['data']['items'] = [m.get_json(_p) for m in qs]
|
||||
|
@ -224,6 +250,7 @@ Positions
|
|||
response['data']['items'] = [only_p_sums(m) for m in qs]
|
||||
else:
|
||||
response['data']['items'] = [only_p(m['json']) for m in qs.values('json')]
|
||||
|
||||
else: # otherwise stats
|
||||
items = query['qs']
|
||||
files = File.objects.filter(item__in=items).filter(size__gt=0)
|
||||
|
|
|
@ -35,7 +35,7 @@ def parse_query(data, user):
|
|||
query = {}
|
||||
query['range'] = [0, 100]
|
||||
query['sort'] = [{'key':'user', 'operator':'+'}, {'key':'name', 'operator':'+'}]
|
||||
for key in ('keys', 'group', 'list', 'range', 'ids', 'sort'):
|
||||
for key in ('keys', 'group', 'list', 'range', 'position', 'positions', 'sort'):
|
||||
if key in data:
|
||||
query[key] = data[key]
|
||||
query['qs'] = models.List.objects.find(data, user)
|
||||
|
@ -100,9 +100,12 @@ def findLists(request):
|
|||
qs = qs[query['range'][0]:query['range'][1]]
|
||||
|
||||
response['data']['items'] = [l.json(data['keys'], request.user) for l in qs]
|
||||
elif 'ids' in data:
|
||||
elif 'position' in data:
|
||||
#FIXME: actually implement position requests
|
||||
response['data']['position'] = 0
|
||||
elif 'positions' in data:
|
||||
ids = [i.get_id() for i in qs]
|
||||
response['data']['positions'] = utils.get_positions(ids, query['ids'])
|
||||
response['data']['positions'] = utils.get_positions(ids, query['positions'])
|
||||
else:
|
||||
response['data']['items'] = qs.count()
|
||||
return render_to_json_response(response)
|
||||
|
|
|
@ -146,19 +146,8 @@ class PlaceManager(Manager):
|
|||
#join query with operator
|
||||
qs = self.get_query_set()
|
||||
|
||||
south=data['area']['south']
|
||||
west=data['area']['west']
|
||||
north=data['area']['north']
|
||||
east=data['area']['east']
|
||||
qs = qs.filter(Q(
|
||||
Q(Q(south__gt=south)|Q(south__lt=north)|Q(west__gt=west)|Q(west__lt=east)) &
|
||||
Q(Q(south__gt=south)|Q(south__lt=north)|Q(west__lt=east)|Q(east__gt=east)) &
|
||||
Q(Q(north__gt=south)|Q(north__lt=north)|Q(west__gt=west)|Q(west__lt=east)) &
|
||||
Q(Q(north__gt=south)|Q(north__lt=north)|Q(east__gt=west)|Q(east__lt=east))
|
||||
))
|
||||
|
||||
conditions = parseConditions(data['query'].get('conditions', []),
|
||||
data['query'].get('operator', '&'),
|
||||
conditions = parseConditions(data.get('query', {}).get('conditions', []),
|
||||
data.get('query', {}).get('operator', '&'),
|
||||
user)
|
||||
if conditions:
|
||||
qs = qs.filter(conditions)
|
||||
|
|
|
@ -124,8 +124,7 @@ def parse_query(data, user):
|
|||
query = {}
|
||||
query['range'] = [0, 100]
|
||||
query['sort'] = [{'key':'name', 'operator':'+'}]
|
||||
query['area'] = {'south': -180.0, 'west': -180.0, 'north': 180.0, 'east': 180.0}
|
||||
for key in ('area', 'keys', 'group', 'list', 'range', 'ids', 'sort', 'query'):
|
||||
for key in ('keys', 'group', 'list', 'range', 'position', 'positions', 'sort', 'query'):
|
||||
if key in data:
|
||||
query[key] = data[key]
|
||||
query['qs'] = models.Place.objects.find(query, user)
|
||||
|
@ -183,7 +182,7 @@ def findPlaces(request):
|
|||
}
|
||||
}
|
||||
param data
|
||||
{'query': query, 'sort': array, 'range': array, 'area': array}
|
||||
{'query': query, 'sort': array, 'range': array}
|
||||
|
||||
query: query object, more on query syntax at
|
||||
https://wiki.0x2620.org/wiki/pandora/QuerySyntax
|
||||
|
@ -199,7 +198,6 @@ def findPlaces(request):
|
|||
}
|
||||
]
|
||||
range: result range, array [from, to]
|
||||
area: {south:, west:, north:, east:} only return places in that square
|
||||
|
||||
with keys, items is list of dicts with requested properties:
|
||||
return {'status': {'code': int, 'text': string},
|
||||
|
@ -207,11 +205,11 @@ def findPlaces(request):
|
|||
|
||||
Positions
|
||||
param data
|
||||
{'query': query, 'ids': []}
|
||||
{'query': query, 'positions': []}
|
||||
|
||||
query: query object, more on query syntax at
|
||||
https://wiki.0x2620.org/wiki/pandora/QuerySyntax
|
||||
ids: ids of places for which positions are required
|
||||
positions: ids of places for which positions are required
|
||||
'''
|
||||
data = json.loads(request.POST['data'])
|
||||
print data
|
||||
|
@ -222,9 +220,20 @@ Positions
|
|||
if 'keys' in data:
|
||||
qs = qs[query['range'][0]:query['range'][1]]
|
||||
response['data']['items'] = [p.json(request.user) for p in qs]
|
||||
elif 'ids' in data:
|
||||
elif 'position' in query:
|
||||
ids = [i.get_id() for i in qs]
|
||||
response['data']['positions'] = utils.get_positions(ids, query['ids'])
|
||||
data['conditions'] = data['conditions'] + {
|
||||
'value': query['position'],
|
||||
'key': query['sort'][0]['key'],
|
||||
'operator': '^'
|
||||
}
|
||||
query = parse_query(data, request.user)
|
||||
qs = order_query(query['qs'], query['sort'])
|
||||
if qs.count() > 0:
|
||||
response['data']['position'] = utils.get_positions(ids, [qs[0].itemId])[0]
|
||||
elif 'positions' in data:
|
||||
ids = [i.get_id() for i in qs]
|
||||
response['data']['positions'] = utils.get_positions(ids, query['positions'])
|
||||
else:
|
||||
response['data']['items'] = qs.count()
|
||||
response['data']['area'] = qs.aggregate(
|
||||
|
|
|
@ -6,8 +6,8 @@ pandora.ui.flipbook = function(item) {
|
|||
pandora.URL.set(item + '/timeline');
|
||||
});
|
||||
pandora.api.getItem(item, function(result) {
|
||||
var duration = result.data.item.duration,
|
||||
posterFrame = result.data.item.posterFrame || parseInt(duration/2),
|
||||
var duration = result.data.duration,
|
||||
posterFrame = result.data.posterFrame || parseInt(duration/2),
|
||||
steps = 24,
|
||||
framePrefix = '/' + item + '/frame/' + that.width() + '/',
|
||||
frames = {};
|
||||
|
|
|
@ -369,7 +369,7 @@ pandora.ui.list = function(view) { // fixme: remove view argument
|
|||
}
|
||||
if (data.ids.length == 1) {
|
||||
pandora.api.getItem(data.ids[0], function(result) {
|
||||
app.ui.infoRatio = result.data.item.stream.aspectRatio;
|
||||
app.ui.infoRatio = result.data.stream.aspectRatio;
|
||||
var height = app.$ui.info.width() / app.ui.infoRatio + 16;
|
||||
if(app.$ui.infoStill) app.$ui.infoStill.removeElement();
|
||||
app.$ui.infoStill = pandora.ui.flipbook(data.ids[0])
|
||||
|
|
Loading…
Reference in a new issue