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())
|
||||
return layers
|
||||
|
||||
def get_json(self, fields=None):
|
||||
def get_json(self, keys=None):
|
||||
i = {
|
||||
'id': self.itemId,
|
||||
'rendered': self.rendered
|
||||
|
@ -371,6 +371,7 @@ class Item(models.Model):
|
|||
i.update(self.data)
|
||||
for k in site_config()['itemKeys']:
|
||||
key = k['id']
|
||||
if not keys or key in keys:
|
||||
if key not in i:
|
||||
value = self.get(key)
|
||||
#also get values from sort table, i.e. numberof values
|
||||
|
@ -379,13 +380,19 @@ class Item(models.Model):
|
|||
if value:
|
||||
i[key] = value
|
||||
|
||||
if not fields or 'poster' in fields:
|
||||
if not keys or 'poster' in keys:
|
||||
i['poster'] = self.get_poster()
|
||||
if not fields or 'posters' in fields:
|
||||
if not keys or 'posters' in keys:
|
||||
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)
|
||||
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
|
||||
|
||||
|
||||
|
|
|
@ -343,9 +343,7 @@ def get(request):
|
|||
info['stream'] = item.get_stream()
|
||||
if 'layers' in data['keys']:
|
||||
info['layers'] = item.get_layers(request.user)
|
||||
response['data'] = {}
|
||||
for key in data['keys']:
|
||||
response['data'][key] = info[key]
|
||||
response['data'] = info
|
||||
else:
|
||||
response = json_response(status=403, text='permission denied')
|
||||
return render_to_json_response(response)
|
||||
|
|
|
@ -5,7 +5,7 @@ pandora.ui.flipbook = function(item) {
|
|||
pandora.UI.set('videoPosition|' + item, data.position);
|
||||
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,
|
||||
posterFrame = result.data.posterFrame || parseInt(duration/2),
|
||||
steps = 24,
|
||||
|
|
|
@ -439,7 +439,7 @@ pandora.ui.list = function(view) { // fixme: remove view argument
|
|||
pandora.$ui.mainMenu.disableItem('openmovie');
|
||||
}
|
||||
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;
|
||||
var height = pandora.$ui.info.width() / pandora.user.infoRatio + 16;
|
||||
if(pandora.$ui.infoStill) pandora.$ui.infoStill.removeElement();
|
||||
|
|
Loading…
Reference in a new issue