Esempio n. 1
0
def create_artist():
    '''create new artist'''
    form = ArtistForm()
    if request.method == "POST":
        # import ipdb
        # ipdb.set_trace()
        if form.validate_on_submit():
            artist = Artist(
                name=form.name.data,
                genres=",".join(form.genres.data),
                city=form.city.data,
                state=form.state.data,
                phone=form.phone.data,
                website=form.website.data,
                facebook_link=form.facebook_link.data,
                seeking_venue=form.seeking_venue.data,
                seeking_description=form.seeking_description.data,
                image_link=form.image_link.data
            )
            db.session.add(artist)
            db.session.commit()
            flash('Artist ' + artist.name +
                  ' was successfully listed!')
            return redirect(url_for('artists'))
        else:
            flash("Found errors: {}".format(form.errors))
    return render_template('forms/new_artist.html', form=form)
Esempio n. 2
0
def edit_artist(artist_id):
    '''pulls artist form and populates with current artist data'''
    form = ArtistForm()
    # query artist
    artist = Artist.query.filter_by(id=artist_id).first_or_404()
    # populate form with artist data
    if form.validate_on_submit():
        artist.name = form.name.data
        artist.genres = ",".join(form.genres.data)
        artist.city = form.city.data
        artist.state = form.state.data
        artist.phone = form.phone.data
        artist.website = form.website.data
        artist.facebook_link = form.facebook_link.data
        artist.seeking_venue = form.seeking_venue.data
        artist.seeking_description = form.seeking_description.data
        artist.image_link = form.image_link.data
        db.session.add(artist)
        db.session.commit()
        flash('Your changes have been saved')
        return redirect(url_for('edit_artist', artist_id=artist_id))
    elif request.method == 'GET':
        form.name.data = artist.name
        form.genres.data = artist.genres
        form.city.data = artist.city
        form.state.data = artist.state
        form.phone.data = artist.phone
        form.website.data = artist.website
        form.facebook_link.data = artist.facebook_link
        form.seeking_venue.data = artist.seeking_venue
        form.seeking_description.data = artist.seeking_description
        form.image_link.data = artist.image_link
    return render_template('forms/edit_artist.html', form=form, artist=artist)
Esempio n. 3
0
def enterartist():
    form = ArtistForm()
    if form.validate_on_submit():
        artist = Artist(artistname=form.artistname.data,
                        artistlogo=form.artistlogo.data)
        db.session.add(artist)
        db.session.commit()
        flash('You Submitted {}'.format(form.artistname.data))
        return redirect('/music')

    return render_template('enter_artist.html', title='Music', form=form)
Esempio n. 4
0
def create_artist():

    form = ArtistForm()

    if form.validate_on_submit():
        artist1 = Artist(name=form.artist.data, description=form.bio.data)
        db.session.add(artist1)
        db.session.commit()
        flash('Artist {} has been created'.format(artist1))

    return render_template('create_artist.html', form=form)
Esempio n. 5
0
    def edit_action(id, kwargs=None):
        """Edit an Artist"""

        try:
            if not kwargs:

                form = ArtistForm(request.form)

                kwargs = {
                    "name": form.name.data,
                    "genres": form.genres.data,
                    "city": form.city.data,
                    "phone": form.phone.data,
                    "state": form.state.data,
                    "facebook_link": form.facebook_link.data,
                    "image_link": form.image_link.data,
                    "website": form.website.data,
                    "seeking_venue": form.seeking_venue.data,
                    "seeking_description": form.seeking_description.data
                }

            Artist.query.filter(Artist.id == id).update(kwargs)

            db.session.commit()

            flash('Artist ' + form.name.data + ' was successfully edited!')

        except:

            flash('An error occurred. Artist ' + form.name +
                  ' could not be listed.')

        return redirect(url_for('artist.detail_page', artist_id=id))
Esempio n. 6
0
def edit_artist(artist_id):
    form = ArtistForm()
    artist = Artist.query.filter_by(id=artist_id).first()

    form.name.data = artist.name
    form.genres.data = artist.genres
    form.city.data = artist.city
    form.state.data = artist.state
    form.phone.data = artist.phone
    form.website_link.data = artist.website_link
    form.facebook_link.data = artist.facebook_link
    # TODO: populate form with fields from artist with ID <artist_id>
    return render_template("forms/edit_artist.html", form=form, artist=artist)
Esempio n. 7
0
    def edit_form_page(id):
        """Returns the rendered page for editing an Artist"""

        form = ArtistForm(request.form)

        artist = Artist.query.filter(Artist.id == id).first_or_404()

        form.state.process_data(artist.state)
        form.genres.process_data(artist.genres)

        return render_template('artist/forms/edit.html',
                               form=form,
                               artist=artist)
Esempio n. 8
0
def createartist(request):
    if request.method == "GET":
        form = ArtistForm()
        return render(request, 'createArtists.html', {'form': form})
    if request.method == "POST":
        form = ArtistForm(request.POST)
        form.save()
        return HttpResponseRedirect('/artists')
Esempio n. 9
0
def edit_artist_submission(artist_id):
    # artist record with ID <artist_id> using the new attributes
    # TODO: take values from the form submitted, and update existing
    form = ArtistForm()

    artist = Artist.query.filter_by(id=artist_id).first()

    artist.name = form.name.data
    artist.genres = form.genres.data
    artist.city = form.city.data
    artist.state = form.state.data
    artist.phone = form.phone.data
    artist.website_link = form.website_link.data
    artist.facebook_link = form.facebook_link.data

    db.session.add(artist)
    db.session.commit()
    return redirect(url_for('bp.show_artist', artist_id=artist_id))
Esempio n. 10
0
def create_artist_submission():
    # called upon submitting the new artist listing form
    # TODO: insert form data as a new Venue record in the db, instead
    artist_form = ArtistForm()

    name = artist_form.name.data
    phone = artist_form.phone.data
    city = artist_form.city.data
    image_url = artist_form.image_link.data
    facebook_url = artist_form.facebook_link.data
    state = artist_form.state.data
    genres = artist_form.genres.data
    website = artist_form.website_link.data
    seeking_venue = artist_form.seeking_venue.data
    seeking_description = artist_form.seeking_description.data
    artist = Artist(name=name,
                    city=city,
                    state=state,
                    phone=phone,
                    website_link=website,
                    genres=genres,
                    image_link=image_url,
                    facebook_link=facebook_url,
                    seeking_venue=seeking_venue,
                    seeking_description=seeking_description)
    # TODO: modify data to be the data object returned from db insertion(DONE)
    try:
        db.session.add(artist)
        db.session.commit()
        flash("Artist " + artist.name + " was successfully listed!")
    except Exception as e:
        db.session.rollback()
        db.session.flush()
        flash("An error occurred. Artist " + artist.name +
              " could not be listed.")
        # TODO: on unsuccessful db insert, flash an error instead.
        # e.g., flash("An error occurred. Artist " + data.name + " could not be listed.")
        # on successful db insert, flash success
        print(e)
    return render_template("pages/home.html")
Esempio n. 11
0
    def create_action(kwargs=None):
        """Creates an Artist"""

        try:

            if not kwargs:

                form = ArtistForm(request.form)

                kwargs = {
                    "name": form.name.data,
                    "genres": form.genres.data,
                    "city": form.city.data,
                    "phone": form.phone.data,
                    "state": form.state.data,
                    "facebook_link": form.facebook_link.data,
                    "image_link": form.image_link.data,
                    "website": form.website.data,
                    "seeking_venue": form.seeking_venue.data,
                    "seeking_description": form.seeking_description.data
                }

            model = Artist(**kwargs)

            db.session.add(model)
            db.session.commit()

            flash('Artist ' + request.form.get('name', '') +
                  ' was successfully listed!')

            return redirect(url_for('artist.detail_page', artist_id=model.id))

        except:

            flash('An error occurred. Artist ' + request.form.get('name', '') +
                  ' could not be listed.')

        return render_template('artist/pages/list.html')
Esempio n. 12
0
def create_artist_form():
    form = ArtistForm()
    return render_template('forms/new_artist.html', form=form)
Esempio n. 13
0
    def create_form_page():
        """Returns the rendered page for creating an Artist"""

        form = ArtistForm()

        return render_template('artist/forms/new.html', form=form)
Esempio n. 14
0
def edit_artist(artist_id):
    artist = Artist.query.filter(Artist.id == artist_id).first()
    form = ArtistForm(obj=artist)
    form.genres.data = [GenreEnum(str(genre)).name for genre in artist.genres]

    return render_template('forms/edit_artist.html', form=form, artist=artist)