This commit is contained in:
j 2011-10-19 16:54:33 +00:00
parent 906aec4301
commit 94d066d053

View file

@ -220,6 +220,19 @@ Positions
response['data']['items'] = [] response['data']['items'] = []
qs = _order_query(query['qs'], query['sort']) qs = _order_query(query['qs'], query['sort'])
_p = query['keys'] _p = query['keys']
def get_clips(qs):
n = qs.count()
if n > query['clip_items']:
clips = []
step = int(n/query['clip_items'])
offset = int((n - step * query['clip_items']) / 2)
for i in range(offset, n, step):
clips.append(qs[i])
else:
clips = qs
return [c.json(query['clip_keys']) for c in clips]
def only_p_sums(m): def only_p_sums(m):
r = {} r = {}
for p in _p: for p in _p:
@ -233,15 +246,7 @@ Positions
else: else:
r[p] = m.json.get(p, '') r[p] = m.json.get(p, '')
if 'clip_qs' in query: if 'clip_qs' in query:
qs = query['clip_qs'].filter(item=m) r['clips'] = get_clips(query['clip_qs'].filter(item=m))
n = qs.count()
if n > query['clip_items']:
clips = []
for i in range(0, n, int(n/query['clip_items'])):
clips.append(qs[i])
else:
clips = qs
r['clips'] = [c.json(query['clip_keys']) for c in clips]
return r return r
def only_p(m): def only_p(m):
r = {} r = {}
@ -250,15 +255,7 @@ Positions
for p in _p: for p in _p:
r[p] = m.get(p, '') r[p] = m.get(p, '')
if 'clip_qs' in query: if 'clip_qs' in query:
qs = query['clip_qs'].filter(item__itemId=m['id']) r['clips'] = get_clips(query['clip_qs'].filter(item__itemId=m['id']))
n = qs.count()
if n > query['clip_items']:
clips = []
for i in range(0, n, int(n/query['clip_items'])):
clips.append(qs[i])
else:
clips = qs
r['clips'] = [c.json(query['clip_keys']) for c in clips]
return r return r
qs = qs[query['range'][0]:query['range'][1]] qs = qs[query['range'][0]:query['range'][1]]
#response['data']['items'] = [m.get_json(_p) for m in qs] #response['data']['items'] = [m.get_json(_p) for m in qs]