def save_genre_and_song_relation(self, name, local_song): local_genres = Genre.objects.all() if not self.exists_locally(local_genres, name): genre = Genre() genre.name = name genre.save() local_song.genres.add(genre) else: local_song.genres.add(Genre.objects.filter(name=name)[0]) local_song.save()
def setUp(self): song = Song() song.title = "Basket Case" song.file_path = "burgle/data/pandora/Basket Case.mp3" artist = Artist() artist.name = 'Green Day' artist.save() song.artist = artist album = Album() album.title = 'Dookie' album.save() song.album = album song.station_id = int('21312') song.save() genre = Genre() genre.name = 'Rock' genre.save() song.genres.add(genre)
def addGenre(request): if request.method == "POST": genreName = request.POST.get('name') if genreName != "": try: genre = Genre(name=genreName, description=request.POST.get('description')) genre.save() except (): return render(request, 'music/genre.add.html', {'error_message': "Something aweful happened"}) else: return HttpResponseRedirect(reverse('music:showAllGenres')) else: return render(request, 'music/genre.add.html', {'error_message': "Can't save empty Genre"}) else: return render(request, 'music/genre.add.html')
def addGenre (request): if request.method == "POST": genreName = request.POST.get('name') if genreName!="": try: genre = Genre(name=genreName, description=request.POST.get('description')) genre.save() except (): return render(request, 'music/genre.add.html', { 'error_message': "Something aweful happened" }) else: return HttpResponseRedirect(reverse('music:showAllGenres')) else: return render(request, 'music/genre.add.html', { 'error_message': "Can't save empty Genre" }) else: return render(request, 'music/genre.add.html')
def setUp(self): seed = str(random.randint(1, 100000)) song = Song() song.title = 'Basket Case' pandora_url = 'http://audio-dc6-t1-1.pandora.com/access/6394738923373318898?version=4&lid=55475035&token=ltvKtTCJqaVK0%2FRsqx6FVl92LrWl3riBZtqhXMaoAQGBaZ5CflwAEnJO%2B7CSl%2FFyxIkYLmsL31krBpS3lnPj0PBX0UkSU0BFmh6BBO2wsUwUWvwFu2hyUHpWaJLcL7eJtEl08SKzQswNULEPr3V0R5JD64rB0ANyYc4YeDVSMs9m%2Fo5PITxWQlermntRbN1B2cGg4mi%2BOxQEHWnbwwoRKeQG6c0mv1qHasdMQXJrXc%2FxoUJM7az1yklTPW8LUnmaRho%2BxYBWhmJ5XBjMQtBt89moJVNfi9Cx08fUBf2GU369d63N1HACf86Nt1rcKRgS6NhaBngwjBPeJY0XBR76JesF%2BBQJHUKR' song.audio_url = pandora_url artist = Artist() artist.name = 'Green Day' artist.save() song.artist = artist album = Album() album.title = 'TestAlbum-' + str(seed) album.save() song.album = album song.station_id = int(seed) song.save() genre = Genre() genre.name = 'Rock' genre.save() song.genres.add(genre)
def setUp(self): for i in range(10): seed = str(random.randint(1, 100000)) song = Song() song.title = 'Demo' song.audio_url = 'test/music/demo.mp3' artist = Artist() artist.name = 'TestArtist-' + seed artist.save() song.artist = artist album = Album() album.title = 'TestAlbum-' + seed album.save() song.album = album song.station_id = int(seed) song.save() genre = Genre() genre.name = 'TestGenre-' + seed genre.save() song.genres.add(genre) self.test_songs.append(song)
album = Album.objects.get(name=tags['album']) except Album.DoesNotExist: album = Album(name = tags['album']) try: album.save() except: album = None except Exception, e: print("Error checking for existing album:", tags['album'], e) genre = None if tags['genre']: try: genre = Genre.objects.get(name=tags['genre']) except Genre.DoesNotExist: genre = Genre(name = tags['genre']) try: genre.save() except: genre = None artist = None if tags['artist']: try: artist = Artist.objects.get(name=tags['artist']) except Artist.DoesNotExist: artist = Artist(name = tags['artist']) try: artist.save() except: artist = None
def setUp(self): password = '******' hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8') user = User( email = '*****@*****.**', password = hashed_password, date_of_birth = '1991-09-04', phone_number = '010-1234-1234', ) user.save() self.access_token = jwt.encode({'id' : User.objects.get(id=user.id).id}, SECRET_KEY, algorithm=ALGORITHM) self.user = user self.user_id = user.id character = Character( name = '순대', user_id = self.user_id, ) character.save() self.character = character self.character_id = character.id artist_type = ArtistType(name='그룹') artist_type.save() self.artist_type = artist_type gender = Gender(name='여성') gender.save() self.gender = gender genre = Genre( name = '발라드' ) genre.save() self.genre = genre artist = Artist( name = '다비치', profile_image_url = 'http://www.google.co.kr', artist_type_id = self.artist_type.id, gender_id = self.gender.id, genre_id = self.genre.id ) artist.save() self.artist = artist chart = Chart( name = '빌보드 차트' ) chart.save() self.chart = chart character_taste_artist = CharacterTasteArtist( artist_id = self.artist.id, character_id = self.character_id ) character_taste_artist.save() self.character_taste_artist = character_taste_artist character_taste_genre = CharacterTasteGenre( genre_id = self.genre.id, character_id = self.character_id ) character_taste_genre.save() self.character_taste_genre = character_taste_genre character_taste_chart = CharacterTasteChart( chart_id = self.chart.id, character_id = self.character_id ) character_taste_chart.save() self.character_taste_chart = character_taste_chart