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')))