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