From: Frédéric Péters Date: Sat, 4 Jan 2020 16:58:14 +0000 (+0100) Subject: don't keep duplicated file and do not create duplicated nonstop file object X-Git-Tag: v2021~269 X-Git-Url: https://git.0d.be/?p=django-panik-nonstop.git;a=commitdiff_plain;h=122c67aa2cf7e6488f564eee29f754c013f937ac don't keep duplicated file and do not create duplicated nonstop file object --- diff --git a/nonstop/views.py b/nonstop/views.py index 6b8eddd..5981eab 100644 --- a/nonstop/views.py +++ b/nonstop/views.py @@ -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')))