Exemple #1
0
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)
Exemple #2
0
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'))
Exemple #3
0
def songs_view_one(song_id):
    song = Song.query.get_or_404(song_id)
    song.views += 1
    db.session().commit()

    song_and_artists_and_samples = Song.find_song_and_artists_and_samples(
        song_id)

    return render_template('songs/one.html', song=song_and_artists_and_samples)
Exemple #4
0
def songs_create():
    form = SongForm(request.form)
    form.song_artist.choices = [(artist.id, artist.name)
                                for artist in Artist.query.order_by('name')]
    form.album.choices = [(album.id, album.name)
                          for album in Album.query.order_by('name')]

    if not form.validate():
        return render_template('songs/new.html', form=form)

    song = Song(form.name.data, form.album.data)
    song.account_id = current_user.id

    artist = Artist.query.get(form.song_artist.data)
    artist.song_artist.append(song)

    db.session().add(song)
    db.session().add(artist)
    db.session().commit()

    return redirect(url_for('songs_index'))
Exemple #5
0
def songs_create():
    """Method gets user input from form and adds new song to db"""
    form = SongForm(request.form)

    if not form.validate():
        return render_template("songs/new.html", form=form)

    song_already_added = Song.query.filter_by(name=form.name.data,
                                              artist=form.artist.data).first()

    if song_already_added:
        form.name.errors.append("Song is already in database")
        return render_template("songs/new.html", form=form)

    new_song = Song(form.name.data, form.artist.data)
    new_song.account_id = current_user.id
    db.session().add(new_song)
    db.session().commit()

    flash('Song successfully added')
    return redirect(url_for("songs_index"))
Exemple #6
0
def songs_create():

    form = NewSongForm(request.form)

    if request.method == "GET":
        return render_template("songs/new.html", form=form)

    language = SelectField('language', [DataRequired()],
                           choices=[('', ''), ('finnish', 'finnish'),
                                    ('english', 'english'),
                                    ('french', 'french')])

    if not form.validate():
        return render_template("songs/new.html",
                               form=form,
                               error="Fields must not be empty.")

    song = Song(form.title.data, form.lyrics.data, form.language.data,
                g.user.id, g.user.role_id)

    authors = request.form["author"].split(',')
    for auth in authors:
        if Author.query.filter_by(name=auth.strip()).first() is None:
            author = Author(name=auth.strip(),
                            result_all=None,
                            result_no_stop_words=None)
            try:
                db.session().add(author)
                db.session().commit()
            except SQLAlchemyError:
                db.session.rollback()
                flash("Author(s) not added to database.", "danger")
                return render_template("songs/new.html", form=form)

    for auth in authors:
        song.authors.extend(Author.query.filter_by(name=auth.strip()))

    try:
        db.session().add(song)
        db.session().commit()
    except IntegrityError:
        db.session.rollback()
        flash("Song already exists. Consider changing name.", "warning")
        return render_template("songs/new.html", form=form)
    except SQLAlchemyError:
        db.session.rollback()
        flash("Something went wrong.", "danger")
        return render_template("songs/new.html", form=form)

    return render_template("songs/list.html", songs=Song.query.all())
Exemple #7
0
def songs_change_name(song_id):

    song = Song.query.get(song_id)
    artist_id = Song.find_artist_for_song(song)
    artist = Artist.query.get(artist_id)
    form = ChangeSongForm(obj=song)  #the form prefilled with the song

    if not form.validate():
        return render_template("songs/change.html",
                               song=song,
                               artist=artist,
                               form=form)

    return render_template("songs/change.html",
                           song=song,
                           artist=artist,
                           form=SongForm(obj=song))
Exemple #8
0
def change_form(song_id):
    song = Song.query.get(song_id)
    artist_id = Song.find_artist_for_song(song)
    artist = Artist.query.get(artist_id)
    form = ChangeSongForm(obj=song)  #the form prefilled with the song

    if not form.validate():
        return render_template("songs/change.html",
                               form=form,
                               song=song,
                               artist=artist,
                               song_error="")

    song.songname = form.songname.data
    song.description = form.description.data
    db.session().commit()

    return redirect(url_for("songs_index"))
Exemple #9
0
def song_choose(song_id):

    song = Song.query.get(song_id)
    form = SongForm(request.form)

    accountsong = Accountsongs.check_if_exists(song, current_user)

    if accountsong:
        return render_template(
            "songs/mylist.html",
            form=form,
            mysongs=Song.find_songs_for_current_user(),
            song_error="You have this song on your list already")

    if not accountsong:
        accountsong = Accountsongs(current_user, song, 0, 0)

        db.session().add(accountsong)
        db.session().commit()

    return redirect(url_for("show_mylist"))
Exemple #10
0
def songs_create():
    form = SongForm(request.form)

    if not form.validate():
        return render_template("songs/new.html", form=form)

    s = Song(form.name.data)
    s.artist = form.artist.data
    s.length = form.length.data
    s.songkey = form.songkey.data
    s.account_id = current_user.id

    db.session().add(s)

    db.session().commit()

    flash("Song successfully created!")
    return redirect(url_for("songs_index"))
Exemple #11
0
def songs_index():
    return render_template('songs/list.html',
                           songs=Song.get_songs_and_sample_counts())
Exemple #12
0
    def generate(x, id):  #------------------------------------------------
        # add default authors
        #------------------------------------------------
        for auth in authors.authors:
            db.session.add(
                Author(name=auth, result_all=None, result_no_stop_words=None))
            db.session.commit()
            x = x + 100.0 / num_all
            yield "data:" + str('%.4f' % (x)) + "\n\n"

        #------------------------------------------------
        # add default songs
        #------------------------------------------------
        # finnish songs
        for i in range(1, 7):
            document_path = os.getcwd(
            ) + '/application/static/default_songs/fi/' + str(i) + '.txt'
            file = open(document_path, 'r', encoding='utf-8')
            name = file.readline().rstrip()
            file.close()
            lyrics = ""
            with open(document_path, encoding='utf-8') as f:
                for line in itertools.islice(f, 2, None):
                    lyrics += line
            language = 'finnish'

            song = Song(name, lyrics, language, account_id=id, account_role=1)

            if i == 1:
                song.authors.extend([
                    db.session.query(Author).filter(
                        Author.name ==
                        'Jens Nicolai Ludvig Schjörring').first(),
                    db.session.query(Author).filter(
                        Author.name == 'H. S. Thompson').first()
                ])
            elif i == 2:
                song.authors.extend([
                    db.session.query(Author).filter(
                        Author.name == 'Abraham Achrenius').first(),
                    db.session.query(Author).filter(
                        Author.name == 'Toisinto Ylistarosta').first()
                ])
            elif i == 3:
                song.authors.extend([
                    db.session.query(Author).filter(
                        Author.name == 'Lina Sandell-Berg').first(),
                    db.session.query(Author).filter(
                        Author.name == 'Gunr Wennerberg').first()
                ])
            elif i == 4:
                song.authors.extend([
                    db.session.query(Author).filter(
                        Author.name == 'Georgiana M. Taylor').first(),
                    db.session.query(Author).filter(
                        Author.name == 'Tuntematon').first()
                ])
            elif i == 5:
                song.authors.extend([
                    db.session.query(Author).filter(
                        Author.name == 'Johnson Jr. Oatman').first(),
                    db.session.query(Author).filter(
                        Author.name == 'Edwin O. Excell').first()
                ])
            elif i == 6:
                song.authors.extend([
                    db.session.query(Author).filter(
                        Author.name == 'Tuntematon').first(),
                    db.session.query(Author).filter(
                        Author.name == 'Lewis Hartsoug').first()
                ])

            try:
                db.session.add(song)
                db.session.commit()
            except:
                db.session.rollback()

            x = x + 100.0 / num_all
            yield "data:" + str('%.4f' % (x)) + "\n\n"

        # english songs
        for i in range(7, 13):
            document_path = os.getcwd(
            ) + '/application/static/default_songs/en/' + str(i) + '.txt'
            file = open(document_path, 'r', encoding='utf-8')
            name = file.readline().rstrip()
            file.close()
            lyrics = ""
            with open(document_path, encoding='utf-8') as f:
                for line in itertools.islice(f, 2, None):
                    lyrics += line
            language = 'english'

            song = Song(name, lyrics, language, account_id=id, account_role=1)

            if i == 7:
                song.authors.extend([
                    db.session.query(Author).filter(
                        Author.name == 'Chris Tomlin').first()
                ])
            elif i == 8:
                song.authors.extend([
                    db.session.query(Author).filter(
                        Author.name == 'George Crawford Hugg').first(),
                    db.session.query(Author).filter(
                        Author.name == 'Johnson Jr. Oatman').first()
                ])
            elif i == 9:
                song.authors.extend([
                    db.session.query(Author).filter(
                        Author.name == 'Philip Paul Bliss').first()
                ])
            elif i == 10:
                song.authors.extend([
                    db.session.query(Author).filter(
                        Author.name == 'Chris Tomlin').first(),
                    db.session.query(Author).filter(
                        Author.name == 'Ed Cash').first(),
                    db.session.query(Author).filter(
                        Author.name == 'Stephan Conley Sharp').first()
                ])
            elif i == 11:
                song.authors.extend([
                    db.session.query(Author).filter(
                        Author.name == 'Matt Maher').first()
                ])
            elif i == 12:
                song.authors.extend([
                    db.session.query(Author).filter(
                        Author.name == 'Hillsong United').first()
                ])

            try:
                db.session.add(song)
                db.session.commit()
            except:
                db.session.rollback()

            x = x + 100.0 / num_all
            yield "data:" + str('%.4f' % (x)) + "\n\n"

        # french songs
        for i in range(13, 19):
            document_path = os.getcwd(
            ) + '/application/static/default_songs/fr/' + str(i) + '.txt'
            file = open(document_path, 'r', encoding='utf-8')
            name = file.readline().rstrip()
            file.close()
            lyrics = ""
            with open(document_path, encoding='utf-8') as f:
                for line in itertools.islice(f, 2, None):
                    lyrics += line
            language = 'french'

            song = Song(name, lyrics, language, account_id=id, account_role=1)

            if i == 13:
                song.authors.extend([
                    db.session.query(Author).filter(
                        Author.name == 'John van den Hogen').first()
                ])
            elif i == 14:
                song.authors.extend([
                    db.session.query(Author).filter(
                        Author.name == 'Mlle Amélie Humbert').first(),
                    db.session.query(Author).filter(
                        Author.name == 'George Coles Stebbins').first()
                ])
            elif i == 15:
                song.authors.extend([
                    db.session.query(Author).filter(
                        Author.name == 'Charles Rochedieu').first(),
                    db.session.query(Author).filter(
                        Author.name == 'William Herbert Jude').first()
                ])
            elif i == 16:
                song.authors.extend([
                    db.session.query(Author).filter(
                        Author.name == 'Mlle Amélie Humbert').first(),
                    db.session.query(Author).filter(
                        Author.name == 'C.-C. Williams').first()
                ])
            elif i == 17:
                song.authors.extend([
                    db.session.query(Author).filter(
                        Author.name == 'Horatio Richmond Palmer').first()
                ])
            elif i == 18:
                song.authors.extend([
                    db.session.query(Author).filter(
                        Author.name == 'Jean-François Bussy').first()
                ])

            try:
                db.session.add(song)
                db.session.commit()
            except:
                db.session.rollback()

            x = x + 100.0 / num_all
            yield "data:" + str('%.4f' % (x)) + "\n\n"
Exemple #13
0
def songs_create():
    form = SongForm(request.form)

    if not form.validate():
        return render_template("songs/new.html", form=form, song_error="")

    song = Song.query.filter_by(songname=form.songname.data).first()
    artist = Artist.query.filter_by(artistname=form.artistname.data).first()

    if song and artist:
        artistsong = Song.check_artistsong(song, artist)

        if artistsong:
            return render_template(
                "songs/new.html",
                form=form,
                song_error="This song has been added already")

        else:
            song = Song(form.songname.data)
            Song.new_song_dbs(song, artist)
            return redirect(url_for("songs_index"))

    elif song:
        song = Song(form.songname.data)
        song.description = form.description.data
        artist = Artist(form.artistname.data)
        Song.new_song_dbs(song, artist)
        return redirect(url_for("songs_index"))

    elif not song:
        song = Song(form.songname.data)
        song.description = form.description.data

        if artist:
            Song.new_song_dbs(song, artist)
            return redirect(url_for("songs_index"))

        if not artist:
            artist = Artist(form.artistname.data)
            Song.new_song_dbs(song, artist)
            return redirect(url_for("songs_index"))

    return redirect(url_for("songs_index"))
Exemple #14
0
def show_stats():

    return render_template("songs/stats.html",
                           stat_songs=Song.how_many_have_this(),
                           form=SongForm())
Exemple #15
0
def show_mylist():

    return render_template("songs/mylist.html",
                           mysongs=Song.find_songs_for_current_user(),
                           form=SongForm())
Exemple #16
0
def songs_index():
    return render_template("songs/list.html",
                           songs=Song.list_songs_with_artistname())