only return requested keys

This commit is contained in:
j 2011-07-30 14:23:06 +02:00
parent ac0018baad
commit a52d33a387
4 changed files with 21 additions and 16 deletions

View file

@ -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,21 +371,28 @@ class Item(models.Model):
i.update(self.data)
for k in site_config()['itemKeys']:
key = k['id']
if key not in i:
value = self.get(key)
#also get values from sort table, i.e. numberof values
if not value and self.sort and hasattr(self.sort, key):
value = getattr(self.sort, key)
if value:
i[key] = value
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
if not value and self.sort and hasattr(self.sort, key):
value = getattr(self.sort, key)
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

View file

@ -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)

View file

@ -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,

View file

@ -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();