def file_upload_handler(uploaded): """Writes an uploaded file to disk and adds it to the database""" name, path = parse(uploaded) with open(path, 'wb+') as dest: for chunk in uploaded.chunks(): dest.write(chunk) song = Song.create(name=name, path=path) song.save()
def setUp(self): self.client = Client() # Adds some example songs and playlists to the test db self.song1 = Song.create(name="song1", path="path1") self.song2 = Song.create(name="song2", path="path2") self.song3 = Song.create(name="song3", path="path3") self.playlist1 = Playlist.create(name="playlist1") self.playlist2 = Playlist.create(name="playlist2") self.playlist3 = Playlist.create(name="playlist3") self.playlist1.songs.add(self.song1) self.playlist1.songs.add(self.song2) self.playlist1.songs.add(self.song3) self.playlist2.songs.add(self.song1) self.playlist2.songs.add(self.song2) self.playlist3.songs.add(self.song1)
def testManyToManyOperation(self): team = Team.create(name="Houkago Tea Time") for name in self.names: team.members.append(first_name=name[0], last_name=name[1], part=name[2], age=name[3]) song1 = Song.create(name="Utauyo!! MIRACLE") song2 = Song.create(name="Tenshi ni Fureta yo!") for m in Member.all(): song1.members.append(m) for m in Member.select(age=17): song2.members.append(m) members = song1.members self.assertEqual(members.count(), 5) members = song2.members self.assertEqual(members.count(), 4) azusa = Member.get(first_name="Azusa") songs = azusa.songs self.assertEqual(songs.count(), 1) self.assertEqual(songs[0].name, "Utauyo!! MIRACLE")
def compose(): song = Song.create() compose_async.delay(song.key) return song