Пример #1
0
def events_create():
    # POST: Create new event
    if request.method == 'POST':
        form = EventForm(request.form)
        performers = [(performer.id, performer.name)
                      for performer in Performer.query.all()]
        for sub_form in form.performers:
            sub_form.performer.choices = performers

        if not form.validate_on_submit():
            return render_template('events/new.html', form=form)

        for entry in form.performers.entries:
            print(entry.data['performer'])
        performer_ids = [(entry.data['performer'])
                         for entry in form.performers.entries]
        print(performer_ids)
        e = Event(name=form.name.data,
                  performers=[(Performer.query.get(id))
                              for id in performer_ids],
                  venue=form.venue.data,
                  date=form.date.data)
        e.account_id = current_user.id
        db.session().add(e)
        db.session().commit()
        # Then redirect to list of events
        return redirect(url_for("events_index"))

    # GET: Serve form for event creation
    performers = [(performer.id, performer.name)
                  for performer in Performer.query.all()]
    form = EventForm()
    for sub_form in form.performers:
        sub_form.performer.choices = performers
    return render_template("events/new.html", form=form, performers=performers)
Пример #2
0
def create_event():
    form = EventForm(request.form)

    if not form.validate():
        return render_template(
            "/events/new_event.html",
            form=form,
            sign_ups=Sign_up.query.filter_by(account_id=current_user.id).all())

    e = Event(form.date.data, form.league.data.id, form.distance.data,
              form.description.data, form.league.data)
    e.account_id = current_user.id

    db.session().add(e)
    db.session().commit()

    return redirect(url_for("list_events"))