def list_songs(): """ Lists all the songs 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')) global allmovies global alltvshows page['title'] = 'List Songs' # Get a list of all songs from the database allsongs = None allsongs = database.get_allsongs() # Data integrity checks if allsongs == None: allsongs = [] return render_template('listitems/listsongs.html', session=session, page=page, user=user_details, allsongs=allsongs, allmovies = allmovies, alltvshows=alltvshows)
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'] = '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)