]> git.0d.be Git - django-panik-nonstop.git/commitdiff
don't keep duplicated file and do not create duplicated nonstop file object
authorFrédéric Péters <fpeters@0d.be>
Sat, 4 Jan 2020 16:58:14 +0000 (17:58 +0100)
committerFrédéric Péters <fpeters@0d.be>
Sat, 4 Jan 2020 16:58:14 +0000 (17:58 +0100)
nonstop/views.py

index 6b8edddc0aff78f7ef312f7916cd9287f8d6fb38..5981eab08f9bf0c91533ddf076ee27625e7e314c 100644 (file)
@@ -210,18 +210,18 @@ class UploadTracksView(FormView):
                 track_title[:80].replace('/', ' ').strip(),
                 os.path.splitext(f.name)[-1])
 
-            default_storage.save(os.path.join('nonstop', 'tracks', filepath), content=f)
-
-            nonstop_file = NonstopFile()
-            nonstop_file.set_track_filepath(filepath)
             artist, created = Artist.objects.get_or_create(name=artist_name)
             track, created = Track.objects.get_or_create(title=track_title, artist=artist,
                     defaults={'uploader': self.request.user})
-            if created or nonstop_file.track is None or not nonstop_file.track.file_exists():
+            if created or not track.file_exists():
+                default_storage.save(os.path.join('nonstop', 'tracks', filepath), content=f)
+                nonstop_file = NonstopFile()
+                nonstop_file.set_track_filepath(filepath)
                 nonstop_file.track = track
                 nonstop_file.save()
             else:
-                pass  # do not create a duplicated nonstop file object
+                # don't keep duplicated file and do not create a duplicated nonstop file object
+                pass
             if request.POST.get('nonstop_zone'):
                 track.nonstop_zones.add(
                         Nonstop.objects.get(id=request.POST.get('nonstop_zone')))