def download_album(request, pk): album = Album.objects.get(pk=pk) if album.song_set.count() == 0: messages.add_message( request, messages.INFO, _('The album does not have any song')) return redirect(album.get_absolute_url()) else: sync_song_files(Song.objects.filter(album=album)) sync_cover_images([album]) remove_empty_directories(album.filepath) return _download(album)
def download_artist(request, pk): artist = Artist.objects.get(pk=pk) num_songs = Song.objects.filter(album__artist=artist).count() if num_songs == 0: messages.add_message( request, messages.INFO, _('The artist does not have any song')) return redirect(artist.get_absolute_url()) else: sync_song_files(Song.objects.filter(album__artist=artist)) sync_cover_images(Album.objects.filter(artist=artist)) remove_empty_directories(artist.filepath) return _download(artist)
def test_remove_empty_directories(self): artist = Artist.objects.get(pk=1) original_path = artist.filepath artist.name = "Brian" artist.save() sync_song_files() sync_cover_images() self.assertTrue(os.path.exists(full_path(original_path))) self.assertTrue(os.path.exists(full_path(artist.filepath))) remove_empty_directories() self.assertFalse(os.path.exists(full_path(original_path))) self.assertTrue(os.path.exists(full_path(artist.filepath)))
def handle_noargs(self, **options): delete_empty_instances() sync_song_files() sync_cover_images() remove_empty_directories()