]> git.0d.be Git - django-panik-nonstop.git/commitdiff
misc: don't crash on duplicated tracks with missing files
authorFrédéric Péters <fpeters@0d.be>
Thu, 27 Jun 2019 08:57:13 +0000 (10:57 +0200)
committerFrédéric Péters <fpeters@0d.be>
Thu, 27 Jun 2019 08:57:13 +0000 (10:57 +0200)
nonstop/models.py

index 820883a45f2d9ace105685f273a97acb6ae54fdb..b3f459ebe69e0cf25fac50db0370fb5cb2cb2180 100644 (file)
@@ -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