set poster source
This commit is contained in:
parent
a52d33a387
commit
662d193c1d
2 changed files with 11 additions and 14 deletions
|
@ -127,7 +127,7 @@ class Item(models.Model):
|
|||
json = fields.DictField(default={}, editable=False)
|
||||
poster = models.ImageField(default=None, blank=True,
|
||||
upload_to=lambda i, x: i.path("poster.jpg"))
|
||||
poster_url = models.TextField(blank=True)
|
||||
poster_source = models.TextField(blank=True)
|
||||
poster_height = models.IntegerField(default=0)
|
||||
poster_width = models.IntegerField(default=0)
|
||||
poster_frame = models.FloatField(default=-1)
|
||||
|
@ -299,12 +299,6 @@ class Item(models.Model):
|
|||
poster['width'] = self.poster_width
|
||||
poster['height'] = self.poster_height
|
||||
poster['url'] = '/%s/poster.jpg' % self.itemId
|
||||
'''
|
||||
if self.poster:
|
||||
poster['url'] = self.poster.url
|
||||
else:
|
||||
poster['url'] = self.poster_url
|
||||
'''
|
||||
return poster
|
||||
|
||||
def get_posters(self):
|
||||
|
@ -789,9 +783,12 @@ class Item(models.Model):
|
|||
os.unlink(f)
|
||||
|
||||
def prefered_poster_url(self):
|
||||
if self.poster_url:
|
||||
return self.poster_url
|
||||
self.update_poster_urls()
|
||||
service = self.poster_source
|
||||
if service and service != settings.URL:
|
||||
for u in self.poster_urls.filter(service=service).order_by('-height'):
|
||||
return u.url
|
||||
if not service:
|
||||
for service in settings.POSTER_PRECEDENCE:
|
||||
for u in self.poster_urls.filter(service=service).order_by('-height'):
|
||||
return u.url
|
||||
|
|
|
@ -460,7 +460,7 @@ def setPoster(request): #parse path and return info
|
|||
'''
|
||||
param data {
|
||||
id: itemId,
|
||||
url: string
|
||||
source: string
|
||||
}
|
||||
return {
|
||||
status: {'code': int, 'text': string},
|
||||
|
@ -473,9 +473,9 @@ 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.get_posters()]
|
||||
if data['url'] in valid_urls:
|
||||
item.poster_url = data['url']
|
||||
valid_sources = [p['source'] for p in item.get_posters()]
|
||||
if data['source'] in valid_sources:
|
||||
item.poster_source = data['source']
|
||||
if item.poster:
|
||||
item.poster.delete()
|
||||
item.save()
|
||||
|
|
Loading…
Reference in a new issue