forked from 0x2620/pandora
only return requested keys
This commit is contained in:
parent
8ebc5ebc05
commit
9e2412888b
4 changed files with 21 additions and 16 deletions
|
@ -362,7 +362,7 @@ class Item(models.Model):
|
||||||
ll.append(a.json())
|
ll.append(a.json())
|
||||||
return layers
|
return layers
|
||||||
|
|
||||||
def get_json(self, fields=None):
|
def get_json(self, keys=None):
|
||||||
i = {
|
i = {
|
||||||
'id': self.itemId,
|
'id': self.itemId,
|
||||||
'rendered': self.rendered
|
'rendered': self.rendered
|
||||||
|
@ -371,21 +371,28 @@ class Item(models.Model):
|
||||||
i.update(self.data)
|
i.update(self.data)
|
||||||
for k in site_config()['itemKeys']:
|
for k in site_config()['itemKeys']:
|
||||||
key = k['id']
|
key = k['id']
|
||||||
if key not in i:
|
if not keys or key in keys:
|
||||||
value = self.get(key)
|
if key not in i:
|
||||||
#also get values from sort table, i.e. numberof values
|
value = self.get(key)
|
||||||
if not value and self.sort and hasattr(self.sort, key):
|
#also get values from sort table, i.e. numberof values
|
||||||
value = getattr(self.sort, key)
|
if not value and self.sort and hasattr(self.sort, key):
|
||||||
if value:
|
value = getattr(self.sort, key)
|
||||||
i[key] = value
|
if value:
|
||||||
|
i[key] = value
|
||||||
|
|
||||||
if not fields or 'poster' in fields:
|
if not keys or 'poster' in keys:
|
||||||
i['poster'] = self.get_poster()
|
i['poster'] = self.get_poster()
|
||||||
if not fields or 'posters' in fields:
|
if not keys or 'posters' in keys:
|
||||||
i['posters'] = self.get_posters()
|
i['posters'] = self.get_posters()
|
||||||
if not fields or 'frames' in fields:
|
if not keys or 'frames' in keys:
|
||||||
i['frames'] = ['/%s/frame/poster/%d.jpg' %(self.itemId, p)
|
i['frames'] = ['/%s/frame/poster/%d.jpg' %(self.itemId, p)
|
||||||
for p in range(0, len(self.poster_frames()))]
|
for p in range(0, len(self.poster_frames()))]
|
||||||
|
if keys:
|
||||||
|
info = {}
|
||||||
|
for key in keys:
|
||||||
|
if key in i:
|
||||||
|
info[key] = i[key]
|
||||||
|
return info
|
||||||
return i
|
return i
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -343,9 +343,7 @@ def get(request):
|
||||||
info['stream'] = item.get_stream()
|
info['stream'] = item.get_stream()
|
||||||
if 'layers' in data['keys']:
|
if 'layers' in data['keys']:
|
||||||
info['layers'] = item.get_layers(request.user)
|
info['layers'] = item.get_layers(request.user)
|
||||||
response['data'] = {}
|
response['data'] = info
|
||||||
for key in data['keys']:
|
|
||||||
response['data'][key] = info[key]
|
|
||||||
else:
|
else:
|
||||||
response = json_response(status=403, text='permission denied')
|
response = json_response(status=403, text='permission denied')
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
|
|
|
@ -5,7 +5,7 @@ pandora.ui.flipbook = function(item) {
|
||||||
pandora.UI.set('videoPosition|' + item, data.position);
|
pandora.UI.set('videoPosition|' + item, data.position);
|
||||||
pandora.URL.set(item + '/timeline');
|
pandora.URL.set(item + '/timeline');
|
||||||
});
|
});
|
||||||
pandora.api.getItem(item, function(result) {
|
pandora.api.get({id: item, keys: ['duration', 'posterFrame']}, function(result) {
|
||||||
var duration = result.data.duration,
|
var duration = result.data.duration,
|
||||||
posterFrame = result.data.posterFrame || parseInt(duration/2),
|
posterFrame = result.data.posterFrame || parseInt(duration/2),
|
||||||
steps = 24,
|
steps = 24,
|
||||||
|
|
|
@ -439,7 +439,7 @@ pandora.ui.list = function(view) { // fixme: remove view argument
|
||||||
pandora.$ui.mainMenu.disableItem('openmovie');
|
pandora.$ui.mainMenu.disableItem('openmovie');
|
||||||
}
|
}
|
||||||
if (data.ids.length == 1) {
|
if (data.ids.length == 1) {
|
||||||
pandora.api.getItem(data.ids[0], function(result) {
|
pandora.api.get({id: data.ids[0], keys:['stream']}, function(result) {
|
||||||
pandora.user.infoRatio = result.data.stream.aspectRatio;
|
pandora.user.infoRatio = result.data.stream.aspectRatio;
|
||||||
var height = pandora.$ui.info.width() / pandora.user.infoRatio + 16;
|
var height = pandora.$ui.info.width() / pandora.user.infoRatio + 16;
|
||||||
if(pandora.$ui.infoStill) pandora.$ui.infoStill.removeElement();
|
if(pandora.$ui.infoStill) pandora.$ui.infoStill.removeElement();
|
||||||
|
|
Loading…
Reference in a new issue