always clear siteposter cache if poster is removed

This commit is contained in:
j 2016-10-28 18:15:44 +02:00
parent c19598c4d7
commit addaa56d85
2 changed files with 3 additions and 2 deletions

View file

@ -1375,6 +1375,7 @@ class Item(models.Model):
f.write(data) f.write(data)
self.poster_height = self.poster.height self.poster_height = self.poster.height
self.poster_width = self.poster.width self.poster_width = self.poster.width
self.clear_poster_cache(self.poster.path)
if self.json.get('posterRatio') != self.poster_width / self.poster_height: if self.json.get('posterRatio') != self.poster_width / self.poster_height:
self.json = self.get_json() self.json = self.get_json()
Item.objects.filter(id=self.id).update(json=self.json, Item.objects.filter(id=self.id).update(json=self.json,
@ -1411,6 +1412,7 @@ class Item(models.Model):
if self.poster: if self.poster:
self.clear_poster_cache(self.poster.path) self.clear_poster_cache(self.poster.path)
self.poster.delete() self.poster.delete()
self.clear_poster_cache(os.path.join(settings.MEDIA_ROOT, self.path('siteposter.jpg')))
def clear_poster_cache(self, poster=None): def clear_poster_cache(self, poster=None):
if poster is None: if poster is None:
@ -1442,7 +1444,7 @@ class Item(models.Model):
data = f.read() data = f.read()
if data: if data:
self.save_poster(data) self.save_poster(data)
self.clear_poster_cache(poster) self.clear_poster_cache(poster)
def make_siteposter(self): def make_siteposter(self):
poster = self.path('siteposter.jpg') poster = self.path('siteposter.jpg')

View file

@ -674,7 +674,6 @@ def setPoster(request, data):
if data['source'] in valid_sources: if data['source'] in valid_sources:
item.poster_source = data['source'] item.poster_source = data['source']
item.remove_poster() item.remove_poster()
item.clear_poster_cache(item.path('siteposter.jpg'))
item.save() item.save()
tasks.update_poster(item.public_id) tasks.update_poster(item.public_id)
response = json_response() response = json_response()