From f46d09bc17d5da9196c207dadb88a8062db70815 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 27 Jun 2019 10:57:13 +0200 Subject: [PATCH] misc: don't crash on duplicated tracks with missing files --- nonstop/models.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/nonstop/models.py b/nonstop/models.py index 820883a..b3f459e 100644 --- a/nonstop/models.py +++ b/nonstop/models.py @@ -74,11 +74,17 @@ class Track(models.Model): ).exclude(on_air=False).order_by('-play_timestamp') def file_path(self): - return self.nonstopfile_set.all().order_by('creation_timestamp').last().get_local_filepath() + nfile = None + for nfile in self.nonstopfile_set.all().order_by('creation_timestamp'): + if os.path.exists(nfile.get_local_filepath()): + return nfile.get_local_filepath() + if nfile: + return nfile.get_local_filepath() + return None def file_exists(self): try: - return os.path.exists(self.nonstopfile_set.order_by('creation_timestamp').last().get_local_filepath()) + return os.path.exists(self.file_path()) except AttributeError: return False -- 2.39.2