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)
def events_create(): form = EventForm(request.form) venueChoices = [ (v.id, (v.name + " (" + v.location + ")")) for v in Venue.query.all() ] venueChoices.append((-1, "I will create a new venue")) form.venue.choices = venueChoices if not form.validate(): return render_template( "events/data.html", form=form, action="Organize", data_type="a new event", ) venue_id = form.venue.data if form.venue.data == -1: v = Venue(form.new_venue_name.data, form.new_venue_location.data) db.session().add(v) db.session().commit() venue_id = v.id e = Event( admin_id=current_user.id, name=form.name.data, info=form.info.data, venue_id=venue_id, start_time=form.start_time.data, end_time=form.end_time.data, ) db.session().add(e) db.session().commit() return redirect(url_for("events_index"))
def events_create(): form = EventForm(request.form) if not form.validate(): return render_template("events/new.html", form=form) c = Event(request.form['category_id'], request.form['duration'], request.form['description']) db.session().add(c) db.session().commit() return redirect(url_for("events_index"))
def events_create(): print(request.form.get("name")) print(request.form.get("description")) form = EventForm(request.form) if not form.validate(): return render_template("events/new.html", form=form) e = Event(request.form.get("name"), request.form.get("description"), request.form.get("minimum"), current_user.id) db.session().add(e) db.session().commit() return redirect(url_for("events_index"))
def events_index(): return render_template( "events/list.html", events=list(Event.find_events_user_has_permissions_to(current_user.id)), category=Category.query.filter(Category.id == Event.category_id).first(), form=EventForm() )
def events_create(): form = EventForm(request.form) if not form.validate(): return render_template("events/new.html", form=form) e = Event(form.name.data, form.location.data) e.date_time = datetime.combine(form.date.data, form.time.data) e.attendee_max = form.attendee_max.data e.attendee_min = form.attendee_min.data db.session().add(e) db.session().commit() return redirect(url_for("events_all"))
def save_event(event_id): form = EventForm(request.form) if not form.validate(): return render_template("/events/edit_event.html", form=form, event_id=event_id) e = Event.query.get(event_id) e.date = form.date.data e.league_id = form.league.data.id e.distance = form.distance.data e.description = form.description.data e.league = form.league.data db.session().commit() return redirect(url_for("list_events"))
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"))
def edit_event(event_id): e = Event.query.get(event_id) form = EventForm() form.date.data = e.date form.league.data = e.league form.distance.data = e.distance form.description.data = e.description return render_template("/events/edit_event.html", form=form, event_id=event_id)
def events_form(): venueChoices = [ (v.id, (v.name + " (" + v.location + ")")) for v in Venue.query.all() ] venueChoices.append((-1, "I will create a new venue")) eventForm = EventForm() eventForm.venue.choices = venueChoices return render_template( "events/data.html", form=eventForm, action="Organize", data_type="a new event", )
def events_edit(event_id): e = Event.query.get(event_id) if e.admin_id != current_user.id: return redirect(url_for("events_index")) venueChoices = [ (v.id, (v.name + " (" + v.location + ")")) for v in Venue.query.all() ] eventForm = EventForm(obj=e) eventForm.venue.choices = venueChoices return render_template( "events/data.html", form=eventForm, action="Edit", data_type=e.name, id=e.id, )
def events_modify(event_id): e = Event.query.get(event_id) if e.account.id is not current_user.id and not current_user.admin: return redirect(url_for('events_index')) # POST: Update 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 form.validate(): performer_ids = [(entry.data['performer']) for entry in form.performers.entries] e.name = form.name.data e.performers = [(Performer.query.get(id)) for id in performer_ids] e.venue = form.venue.data e.date = form.date.data db.session().commit() # Then redirect to list of events return redirect(url_for("events_index")) # If not valid, return to modification form return render_template("events/modify.html", form=form, event=e) # GET: Serve form for event modification form = EventForm(obj=e) performers = [(performer.id, performer.name) for performer in Performer.query.all()] iterator = 0 for sub_form in form.performers: sub_form.performer.choices = performers sub_form.performer.data = e.performers[iterator].id iterator += 1 return render_template("events/modify.html", form=form, event=e, performers=performers)
def events_update(event_id): form = EventForm(request.form) venueChoices = [ (v.id, (v.name + " (" + v.location + ")")) for v in Venue.query.all() ] form.venue.choices = venueChoices e = Event.query.get(event_id) if e.admin_id != current_user.id: return redirect(url_for("events_index")) if not form.validate(): return render_template( "events/data.html", form=form, action="Edit", data_type=e.name, id=e.id, ) e.name = form.name.data e.info = form.info.data e.venue_id = form.venue.data e.start_time = form.start_time.data e.end_time = form.end_time.data db.session().commit() return redirect(url_for("events_index"))
def events_edit(event_id): if request.method == "GET": events_index() if Event.get_event_owner(event_id) == current_user.id: form = EventForm(request.form) if not form.validate(): form.description.data, form.duration.data = "", 0 return render_template( "events/list.html", events=list(Event.find_events_user_has_permissions_to(current_user.id)), category=Category.query.filter(Category.id == Event.category_id).first(), form=form ) c = Event.query.get(event_id) c.category_id = form.category_id.data.id c.description = form.description.data c.duration = form.duration.data db.session().commit() return redirect(url_for("events_index"))
def events_form(): return render_template("events/new.html", form=EventForm())
def new_event(): return render_template( "/events/new_event.html", form=EventForm(), sign_ups=Sign_up.query.filter_by(account_id=current_user.id).all())