From dffb25e0e80f23a9debb298ef62c8d8bc6c8ac55 Mon Sep 17 00:00:00 2001 From: j Date: Sat, 30 Jul 2016 10:02:53 +0200 Subject: [PATCH] poster might still point to old id, after rename, delete and make new one. fixes #2944 --- pandora/item/models.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index 8ba5dfee..06fc891a 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -1390,8 +1390,23 @@ class Item(models.Model): for f in glob(os.path.join(settings.MEDIA_ROOT, self.path(), 'timeline*.jpg')): os.unlink(f) + def clear_poster_cache(self, poster): + for f in glob(poster.replace('.jpg', '*.jpg')): + if f != poster: + try: + os.unlink(f) + except OSError: + pass + def make_poster(self): ox.makedirs(os.path.join(settings.MEDIA_ROOT, self.path())) + poster = self.path('poster.jpg') + poster = os.path.abspath(os.path.join(settings.MEDIA_ROOT, poster)) + + if self.poster and self.poster.path != poster: + self.clear_poster_cache(self.poster.path) + self.poster.delete() + if not self.poster: poster = self.make_siteposter() url = self.prefered_poster_url() @@ -1403,14 +1418,7 @@ class Item(models.Model): data = f.read() if data: self.save_poster(data) - poster = self.path('poster.jpg') - poster = os.path.abspath(os.path.join(settings.MEDIA_ROOT, poster)) - for f in glob(poster.replace('.jpg', '*.jpg')): - if f != poster: - try: - os.unlink(f) - except OSError: - pass + self.clear_poster_cache(poster) def make_siteposter(self): poster = self.path('siteposter.jpg')