From a52d33a3870260a8174e526f5d3631bab8a723bb Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 30 Jul 2011 14:23:06 +0200 Subject: [PATCH] only return requested keys --- pandora/item/models.py | 29 ++++++++++++++++++----------- pandora/item/views.py | 4 +--- static/js/pandora/ui/flipbook.js | 2 +- static/js/pandora/ui/list.js | 2 +- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index fb629f6..6e3f6e9 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -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 diff --git a/pandora/item/views.py b/pandora/item/views.py index f78e9b7..c8dcfc5 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -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) diff --git a/static/js/pandora/ui/flipbook.js b/static/js/pandora/ui/flipbook.js index 86cf091..509ea77 100644 --- a/static/js/pandora/ui/flipbook.js +++ b/static/js/pandora/ui/flipbook.js @@ -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, diff --git a/static/js/pandora/ui/list.js b/static/js/pandora/ui/list.js index 110b21b..abd0804 100644 --- a/static/js/pandora/ui/list.js +++ b/static/js/pandora/ui/list.js @@ -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();