def list_artists(): """ Lists all the artists in your media server Can do this without a login """ # # Check if the user is logged in, if not: back to login. # if('logged_in' not in session or not session['logged_in']): # return redirect(url_for('login')) page['title'] = 'List Artists' # Get a list of all artists from the database allartists = None allartists = database.get_allartists() # Data integrity checks if allartists == None: allartists = [] return render_template('listitems/listartists.html', session=session, page=page, user=user_details, allartists=allartists)
def search_all(): """ Extension: power search autocomplete """ data = [] movies = database.get_allmovies() songs = database.get_allsongs() artists = database.get_allartists() genre = database.get_all_genre() podcasts = database.get_allpodcasts() tvshows = database.get_alltvshows() for instance in movies: data.append(instance['movie_title']) for instance in songs: data.append(instance['song_title']) for instance in artists: data.append(instance['artist_name']) for instance in genre: data.append(instance['md_value']) for instance in podcasts: data.append(instance['podcast_title']) for instance in tvshows: data.append(instance['tvshow_title']) return json.dumps(data, encoding='utf-8')
def add_song(): """ Add a new Song """ # # Check if the user is logged in, if not: back to login. if ('logged_in' not in session or not session['logged_in']): return redirect(url_for('login')) ######### # TODO # ######### ############################################################################# # Fill in the Function below with to do all data handling for adding a song # ############################################################################# page['title'] = '' # Add the title newdict = {} if request.method == 'POST': # Set up some variables to manage the post returns newdict['song_title'] = request.form['song_title'] newdict['song_length'] = request.form['song_length'] newdict['storage'] = request.form['storage'] newdict['song_genre'] = request.form['song_genre'] newdict['artist'] = request.form['artist'] newdict['song_artwork'] = request.form['song_artwork'] newdict['song_description'] = request.form['song_description'] print(newdict) song = database.add_song_to_db( newdict['song_title'], newdict['song_length'], newdict['storage'], newdict['song_genre'], newdict['artist'], newdict['song_artwork'], newdict['song_description']) song_id = 0 if song is not None: song_id = song[0] return single_song(song_id) # Once retrieved, do some data integrity checks on the data # Once verified, send the appropriate data to the database for insertion # NOTE :: YOU WILL NEED TO MODIFY THIS TO PASS THE APPROPRIATE VARIABLES else: artists = database.get_allartists() genres = database.get_all_genre() return render_template('createitems/createsong.html', session=session, page=page, user=user_details, artists=artists, genres=genres)
def add_song(): """ Add a new Song """ # # Check if the user is logged in, if not: back to login. if ('logged_in' not in session or not session['logged_in']): return redirect(url_for('login')) ######### # TODO # ######### ############################################################################# # Fill in the Function below with to do all data handling for adding a song # ############################################################################# page['title'] = 'Song Creation' # Add the title if bool(database.is_superuser([user_details['username']])) == False: flash("You do not have access to this feature.") allsongs = database.get_allsongs() return render_template('listitems/listsongs.html', session=session, page=page, user=user_details, allsongs=allsongs) else: songs = None print("request form is:") newdict = {} print(request.form) if (request.method == 'POST'): # Set up some variables to manage the post returns # Once retrieved, do some data integrity checks on the data # Once verified, send the appropriate data to the database for insertion # NOTE :: YOU WILL NEED TO MODIFY THIS TO PASS THE APPROPRIATE VARIABLES # verify that the values are available: if ('song_title' not in request.form): newdict['song_title'] = 'Empty Song Title' else: newdict['song_title'] = request.form['song_title'] print("We have a value: ", newdict['song_title']) if ('genre' not in request.form): newdict['genre'] = 'Empty Genre' else: newdict['genre'] = request.form['genre'] print("We have a value: ", newdict['genre']) if ('description' not in request.form): newdict['description'] = 'Empty description field' else: newdict['description'] = request.form['description'] print("We have a value: ", newdict['description']) if ('storage_location' not in request.form): newdict['storage_location'] = 'Empty storage location' else: newdict['storage_location'] = request.form['storage_location'] print("We have a value: ", newdict['storage_location']) if ('song_length' not in request.form): newdict['song_length'] = '0' else: newdict['song_length'] = request.form['song_length'] print("We have a value: ", newdict['song_length']) if ('artistId' not in request.form): newdict['artistId'] = '0' else: newdict['artistId'] = request.form['artistId'] print("We have a value: ", newdict['artistId']) print('newdict is:') print(newdict) # sending data for insertion songs = database.add_song_to_db(newdict['storage_location'], newdict['description'], newdict['song_title'], newdict['song_length'], newdict['genre'], newdict['artistId']) max_song_id = 1 print("Songs: ") print(songs) if songs is not None: max_song_id = songs[0] return single_song(max_song_id) else: print("TRIGGER") allartists = database.get_allartists() return render_template('createitems/createsong.html', session=session, page=page, user=user_details, allartists=allartists)
def add_artist(): """ Add a new artist """ # # Check if the user is logged in, if not: back to login. if ('logged_in' not in session or not session['logged_in']): return redirect(url_for('login')) page['title'] = 'Artist Creation' if bool(database.is_superuser([user_details['username']])) == False: flash("You do not have access to this feature.") allartists = database.get_allartists() return render_template('listitems/listartists.html', session=session, page=page, user=user_details, allartists=allartists) else: artists = None print("request form is:") newdict = {} print(request.form) # Check your incoming parameters if (request.method == 'POST'): # verify that the values are available: if ('artist_name' not in request.form): newdict['artist_name'] = 'Empty Artist Value' else: newdict['artist_name'] = request.form['artist_name'] print("We have a value: ", newdict['artist_name']) if ('description' not in request.form): newdict['description'] = 'Empty description field' else: newdict['description'] = request.form['description'] print("We have a value: ", newdict['description']) if ('artwork' not in request.form): newdict[ 'artwork'] = 'https://user-images.githubusercontent.com/24848110/33519396-7e56363c-d79d-11e7-969b-09782f5ccbab.png' else: newdict['artwork'] = request.form['artwork'] print("We have a value: ", newdict['artwork']) print('newdict is:') print(newdict) #forward to the database to manage insert artists = database.add_artist_to_db(newdict['artist_name'], newdict['description']) max_artist_id = database.get_last_artist()[0]['artist_id'] print(artists) if artists is not None: max_artist_id = artists[0] # ideally this would redirect to your newly added artist return single_artist(max_artist_id) else: return render_template('createitems/createartist.html', session=session, page=page, user=user_details)
def add_song(): """ Add a new Song """ # # Check if the user is logged in, if not: back to login. if('logged_in' not in session or not session['logged_in']): return redirect(url_for('login')) ######### # TODO # ######### ############################################################################# # Fill in the Function below with to do all data handling for adding a song # ############################################################################# page['title'] = 'Song Creation' # Add the title songs = None print("request form is:") newdict = {} print(request.form) # Retrieve all existing artists to pass into createsong.html artists = None artists = database.get_allartists() # Data integrity checks if artists == None: artists = [] else: # Order artist_id by ascending order for readability artists = sorted(artists, key = lambda k: k['artist_id']) if request.method == 'POST': # Set up some variables to manage the post returns # Once retrieved, do some data integrity checks on the data if ('song_title' not in request.form): newdict['song_title'] = 'Empty song' else: newdict['song_title'] = request.form['song_title'] print("We have a value: ",newdict['song_title']) if ('song_length' not in request.form): newdict['song_length'] = '0' else: newdict['song_length'] = request.form['song_length'] print("We have a value: ",newdict['song_length']) if ('storage_location' not in request.form): newdict['storage_location'] = 'No location' else: newdict['storage_location'] = request.form['storage_location'] print("We have a value: ",newdict['storage_location']) if ('artist_id' not in request.form): newdict['artist_id'] = '1' else: newdict['artist_id'] = request.form['artist_id'] print("We have a value: ",newdict['artist_id']) if ('description' not in request.form): newdict['description'] = 'No description' else: newdict['description'] = request.form['description'] print("We have a value: ",newdict['description']) if ('song_genre' not in request.form): newdict['song_genre'] = 'pop' else: newdict['song_genre'] = request.form['song_genre'] print("We have a value: ",newdict['song_genre']) if ('artwork' not in request.form): newdict['artwork'] = 'https://user-images.githubusercontent.com/24848110/33519396-7e56363c-d79d-11e7-969b-09782f5ccbab.png' else: newdict['artwork'] = request.form['artwork'] print("We have a value: ",newdict['artwork']) print('newdict is:') print(newdict) # Once verified, send the appropriate data to the database for insertion matching_artists = database.get_artist(newdict['artist_id']) if len(matching_artists) > 0: songs = database.add_song_to_db(newdict['storage_location'],newdict['description'],newdict['song_title'],newdict['song_length'],newdict['song_genre'],newdict['artist_id']) # Latest song is most recently added song to database # only if the new song cannot be inserted latest_song_id = database.get_last_song()[0]['song_id'] print("printing songs: {}".format(songs)) if songs is not None: latest_song_id = songs[0] return single_song(latest_song_id) else: return render_template('createitems/createsong.html', session=session, page=page, user=user_details, artists=artists)