def auth_stats(load): errors = [] # TOP 5 search words words = Word.find_words() stats = Word.find_stats() result_list = [] if len(words) > 0: for i in range(len(words)): new_list = [] new_list.append(words[i]['word']) new_list.append(words[i]['count']) new_list.append(stats[i]['matches']) new_list.append(stats[i]['average']) result_list.append(new_list) else: result_list = None song_count = db.session.query(Song).count() poem_count = db.session.query(Poem).count() if song_count > 0 and poem_count > 0: return render_template( "auth/stats.html", db_songs_status=Song.find_database_songs_status(), db_poems_status=Poem.find_database_poems_status(), top_words=result_list, load=load, errors=errors) elif song_count > 0 and poem_count == 0: errors.append("Cannot load database status for poems:") errors.append("Tables Poem and Poet are empty.") return render_template( "auth/stats.html", db_songs_status=Song.find_database_songs_status(), db_poems_status=None, top_words=result_list, load=load, errors=errors) elif song_count == 0 and poem_count > 0: errors.append("Cannot load database status for songs:") errors.append("Tables Song and Author are empty.") return render_template( "auth/stats.html", db_songs_status=None, db_poems_status=Poem.find_database_poems_status(), top_words=result_list, load=load, errors=errors) else: errors.append("Cannot load database status:") return render_template("auth/stats.html", db_songs_status=None, db_poems_status=None, top_words=result_list, load=load, errors=errors)
def add_poems(): if db.session.query(Poet).count() > 0 and db.session.query(Poem).filter( Poem.account_role == 1).count() > 0: flash("Default poems already exist.", "warning") return redirect(url_for("auth_stats", load='na')) else: progress_poems() db_songs_status = Song.find_database_songs_status() song_count = db.session.query(Song).count() if song_count > 0: return redirect( url_for("auth_stats", db_songs_status=db_songs_status, db_poems_status=None, top_words=None, load='poem')) else: return redirect( url_for("auth_stats", db_songs_status=None, db_poems_status=None, top_words=None, load='poem'))