new api get({id, keys}, one poster per service
This commit is contained in:
parent
1bab3255bd
commit
66e6fb812e
2 changed files with 51 additions and 18 deletions
|
@ -308,17 +308,27 @@ class Item(models.Model):
|
|||
return poster
|
||||
|
||||
def get_posters(self):
|
||||
posters = {
|
||||
'local': [{
|
||||
url = self.prefered_poster_url()
|
||||
posters = [
|
||||
{
|
||||
'url': '/%s/poster.pandora.jpg' % self.itemId,
|
||||
'width': 640,
|
||||
'height': 1024,
|
||||
}]
|
||||
'service': settings.URL,
|
||||
'selected': url == None
|
||||
}
|
||||
for p in self.poster_urls.all():
|
||||
if p.service not in posters:
|
||||
posters[p.service] = []
|
||||
posters[p.service].append({'url': p.url, 'width': p.width, 'height': p.height})
|
||||
]
|
||||
got = {}
|
||||
for p in self.poster_urls.all().order_by('-height'):
|
||||
if p.service not in got:
|
||||
got[p.service] = 1
|
||||
posters.append({
|
||||
'url': p.url,
|
||||
'width': p.width,
|
||||
'height': p.height,
|
||||
'service': p.service,
|
||||
'selected': p.url == url
|
||||
})
|
||||
return posters
|
||||
|
||||
def get_stream(self):
|
||||
|
@ -369,9 +379,12 @@ class Item(models.Model):
|
|||
if value:
|
||||
i[key] = value
|
||||
|
||||
if not fields or 'poster' in fields:
|
||||
i['poster'] = self.get_poster()
|
||||
if not fields or 'posters' in fields:
|
||||
i['posters'] = self.get_posters()
|
||||
i['posterFrames'] = ['/%s/frame/poster/%d.jpg' %(self.itemId, p)
|
||||
if not fields or 'frames' in fields:
|
||||
i['frames'] = ['/%s/frame/poster/%d.jpg' %(self.itemId, p)
|
||||
for p in range(0, len(self.poster_frames()))]
|
||||
return i
|
||||
|
||||
|
|
|
@ -326,6 +326,31 @@ def autocomplete(request):
|
|||
actions.register(autocomplete)
|
||||
|
||||
|
||||
def get(request):
|
||||
'''
|
||||
param data {
|
||||
id: string
|
||||
keys: array
|
||||
}
|
||||
return item array
|
||||
'''
|
||||
response = json_response({})
|
||||
data = json.loads(request.POST['data'])
|
||||
item = get_object_or_404_json(models.Item, itemId=data['id'])
|
||||
if item.access(request.user):
|
||||
info = item.get_json(data['keys'])
|
||||
if 'stream' in data['keys']:
|
||||
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]
|
||||
else:
|
||||
response = json_response(status=403, text='permission denied')
|
||||
return render_to_json_response(response)
|
||||
actions.register(get)
|
||||
|
||||
def getItem(request):
|
||||
'''
|
||||
param data
|
||||
|
@ -450,7 +475,7 @@ def setPoster(request): #parse path and return info
|
|||
item = get_object_or_404_json(models.Item, itemId=data['id'])
|
||||
response = json_response()
|
||||
if item.editable(request.user):
|
||||
valid_urls = [p.url for p in item.poster_urls.all()]
|
||||
valid_urls = [p['url'] for p in item.get_posters()]
|
||||
if data['url'] in valid_urls:
|
||||
item.poster_url = data['url']
|
||||
if item.poster:
|
||||
|
@ -459,11 +484,6 @@ def setPoster(request): #parse path and return info
|
|||
tasks.update_poster.delay(item.itemId)
|
||||
response = json_response()
|
||||
response['data']['poster'] = item.get_poster()
|
||||
elif data['url'].endswith('/poster.pandora.jpg'):
|
||||
item.poster_url = ''
|
||||
item.save()
|
||||
tasks.update_poster.delay(item.itemId)
|
||||
response['data']['poster'] = item.get_poster()
|
||||
else:
|
||||
response = json_response(status=403, text='invalid poster url')
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue