示例#1
0
文件: routes.py 项目: BenMini/Fyyur
def create_venue():
    '''create new venue'''
    form = VenueForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            venue = Venue(
                name=form.name.data,
                genres=",".join(form.genres.data),
                address=form.address.data,
                city=form.city.data,
                state=form.state.data,
                phone=form.phone.data,
                website=form.website.data,
                facebook_link=form.facebook_link.data,
                seeking_talent=form.seeking_talent.data,
                seeking_description=form.seeking_description.data,
                image_link=form.image_link.data
            )
            db.session.add(venue)
            db.session.commit()
            flash('venue ' + venue.name +
                  ' was successfully listed!')
            return redirect(url_for('venues'))
        else:
            flash("Found errors: {}".format(form.errors))
    return render_template('forms/new_venue.html', form=form)
示例#2
0
def create_venue():
    form = VenueForm()

    if form.validate_on_submit():
        venue1 = Venues(location=form.venue.data, date=" ")
        db.session.add(venue1)
        db.session.commit()
        flash('Artist {} has been created'.format(venue1))

    return render_template('create_venue.html', form=form)
示例#3
0
def venue():
    form = VenueForm()
    if form.validate_on_submit():
        venue = Venue(village=form.village.data, kingdom=form.kingdom.data)
        db.session.add(venue)
        db.session.commit()

        flash('Created new Venue: {}'.format(form.village.data,
                                             form.kingdom.data))
        final_form = VenueForm()
        render_template('venue.html', title='New Venue', form=final_form)

    return render_template('venue.html', title='New Venue', form=form)
示例#4
0
文件: routes.py 项目: BenMini/Fyyur
def edit_venue(venue_id):
    '''pulls venue form and populates with current artist data'''
    form = VenueForm()
    # query artist
    venue = Venue.query.filter_by(id=venue_id).first_or_404()
    # populate form with artist data
    if request.method == 'POST':
        venue.name = form.name.data
        venue.genres = ",".join(form.genres.data)
        venue.address = form.address.data
        venue.city = form.city.data
        venue.state = form.state.data
        venue.phone = form.phone.data
        venue.website = form.website.data
        venue.facebook_link = form.facebook_link.data
        venue.seeking_talent = form.seeking_talent.data
        venue.seeking_description = form.seeking_description.data
        venue.image_link = form.image_link.data
        db.session.add(venue)
        db.session.commit()
        flash('Your changes have been saved')
        return redirect(url_for('edit_venue', venue_id=venue_id))
    if request.method == 'GET':
        form.name.data = venue.name
        form.genres.data = venue.genres
        form.address.data = venue.address
        form.city.data = venue.city
        form.state.data = venue.state
        form.phone.data = venue.phone
        form.website.data = venue.website
        form.facebook_link.data = venue.facebook_link
        form.seeking_talent.data = venue.seeking_talent
        form.seeking_description.data = venue.seeking_description
        form.image_link.data = venue.image_link
    return render_template('forms/edit_venue.html', form=form, venue=venue)
示例#5
0
    def edit_action(id, kwargs={}):
        """Edit a Venue"""

        try:
            if not kwargs:

                form = VenueForm(request.form)

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

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

            db.session.commit()

            flash('Venue' + form.name.data + ' was successfully updated!')

        except:

            flash('An error occurred. Venue ' + form.name.data + ' could not be updated.')

        return redirect(url_for('venue.edit_form_page', venue_id=id))
示例#6
0
    def create_form_page():
        """Returns the rendered page for creating a Venue"""

        form = VenueForm()

        return render_template(
            'venue/forms/new.html',
            form=form
        )
示例#7
0
def edit_venue(venue_id):
    form = VenueForm()
    venue = Venue.query.filter_by(id=venue_id).first()

    form.name.data = venue.name
    form.genres.data = venue.genres
    form.city.data = venue.city
    form.state.data = venue.state
    form.address.data = venue.address
    form.phone.data = venue.phone
    form.website_link.data = venue.website_link
    form.facebook_link.data = venue.facebook_link

    # DONE: populate form with values from venue with ID <venue_id>
    return render_template('forms/edit_venue.html', form=form, venue=venue)
示例#8
0
def edit_venue_submission(venue_id):
    # TODO: take values from the form submitted, and update existing
    # venue record with ID <venue_id> using the new attributes
    form = VenueForm()
    venue = Venue.query.filter_by(id=venue_id).first()

    venue.name = form.name.data
    venue.genres = form.genres.data
    venue.city = form.city.data
    venue.state = form.state.data
    venue.phone = form.phone.data
    venue.address = form.address.data
    venue.website_link = form.website_link.data
    venue.facebook_link = form.facebook_link.data

    db.session.add(venue)
    db.session.commit()
    return redirect(url_for('bp.show_venue', venue_id=venue_id))
示例#9
0
def create_venue_submission():
    venue_form = VenueForm()
    # venue_form.validate()
    name = venue_form.name.data
    phone = venue_form.phone.data
    address = venue_form.address.data
    city = venue_form.city.data
    image_url = venue_form.image_link.data
    facebook_url = venue_form.facebook_link.data
    state = venue_form.state.data
    genres = venue_form.genres.data
    seeking_talent = venue_form.seeking_talent.data
    seeking_description = venue_form.seeking_description.data
    website = venue_form.website_link.data

    # DONE: insert form data as a new Venue record in the db, instead
    venue = Venue(name=name,
                  city=city,
                  state=state,
                  address=address,
                  phone=phone,
                  image_link=image_url,
                  facebook_link=facebook_url,
                  genres=genres,
                  website_link=website,
                  seeking_talent=seeking_talent,
                  seeking_description=seeking_description)
    try:
        db.session.add(venue)
        db.session.commit()
        # on successful db insert, flash success
        flash("Venue " + name + " was successfully listed!")
        # Done: modify data to be the data object returned from db insertion
    except Exception as e:
        # Done: on unsuccessful db insert, flash an error instead.
        # e.g., flash("An error occurred. Venue " + data.name + " could not be listed.")
        # see: http://flask.pocoo.org/docs/1.0/patterns/flashing/
        db.session.rollback()
        flash("An error occurred. Venue " + name + " could not be listed.")
        db.session.flush()
        print(e)
    return render_template("pages/home.html")
示例#10
0
    def edit_form_page(id):
        """Returns the rendered page for editing a Venue"""

        try:

            venue = Venue.query.filter_by(id=id).first()

        except:

            return redirect(url_for('core.index_page'))

        form = VenueForm(request.form)
        form.state.process_data(venue.state)
        form.genres.process_data(venue.genres)

        return render_template(
            'venue/forms/edit.html',
            form=form,
            venue=venue
        )
示例#11
0
    def create_action(kwargs={}):
        """Creates a Venue"""

        try:

            form = VenueForm(request.form)

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

            model = Venue(
                **kwargs
            )

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

            flash('Venue ' + model.name + ' was successfully listed!')

            return redirect(url_for('venue.detail_page', venue_id=model.id))

        except:

            flash('Whoops. Venue ' + kwargs.get('name','') + ' could not be listed.')

            return redirect(url_for('venue.list_page'))
示例#12
0
def create_venue_form():
    form = VenueForm()
    return render_template('forms/new_venue.html', form=form)
示例#13
0
def edit_venue(venue_id):
    venue = Venue.query.filter(Venue.id == venue_id).first()
    form = VenueForm(obj=venue)
    form.genres.data = [GenreEnum(str(genre)).name for genre in venue.genres]

    return render_template('forms/edit_venue.html', form=form, venue=venue)