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 create_user(): if User.query.count() == 0: Event.query.delete() Venue.query.delete() User.query.delete() Role.query.delete() db.session.commit() r = Role(name="admin", description="Administrator") db.session.add(r) u = User( username="******", full_name="Administrator", password="******", email="admin@localhost", ) u.roles.append(r) db.session.add(u) u2 = User( username="******", full_name="Basic User", password="******", email="basic@localhost", ) db.session.add(u2) v1 = Venue(name="Gurula", location="Exactum") db.session.add(v1) v2 = Venue(name="Klusteri", location="Leppäsuonkatu 12, Helsinki") db.session.add(v2) db.session.commit() e = Event( admin_id=u.id, name="Testitapahtuma", info="Testi", venue_id=v1.id, start_time=datetime.now() + timedelta(hours=2), end_time=datetime.now() + timedelta(hours=4), ) db.session().add(e) e = Event( admin_id=u.id, name="Testitapahtuma2", info="Testi2", venue_id=v2.id, start_time=datetime.now() + timedelta(hours=2), end_time=datetime.now() + timedelta(hours=4), ) db.session().add(e) db.session.commit() return redirect(url_for("index"))
def index(): needs_staff=Event.find_unstaffed_events_one_month() if current_user.is_authenticated: upcoming_shifts=Assignment.find_confirmed_registrations_for_coming_events(user_id=current_user.id)[:5] else: upcoming_shifts=[] return render_template("index.html", needs_staff=needs_staff, form = LoginForm(), has_registrations=Event.find_events_with_unconfirmed_registrations(), next_five_shifts=upcoming_shifts, has_assignments=Event.has_assignments(needs_staff))
def event_view_by_id(event_id): e = Event.query.get(event_id) #annetaan yhden tapahtuman näyttävälle sivulle lista kiinnostuneista käyttäjistä, niiden määrä sekä tapahtuman luonut käyttäjä users_interested = Event.find_users_interested_in_specific_event(e.id) amount_of_users = len(users_interested) creator = Event.find_creator_of_event(e.creator_id) return render_template("events/one.html", event=e, form=ModifyForm(), users_interested=users_interested, creator=creator, amount_of_users=amount_of_users)
def admin_list(): events = Event.find_all_events_attend_and_comment_count() eventCount = db.session().query(Event).count() return render_template("events/adminlist.html", events=events, eventCount=eventCount)
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 events_single(event_id): commentForm = CommentForm() e = Event.query.get(event_id) v = Venue.query.get(e.venue_id) organizer = User.query.get(e.admin_id) comments = Event.get_event_comments(event_id) participants = Event.get_event_participants(event_id) return render_template( "events/single.html", event=e, venue=v, organizer=organizer, comments=comments, commentForm=commentForm, participants_list=participants, )
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_index(): myevents = None if current_user.is_authenticated: myevents = User.query.get(current_user.id).events myevents = [e.id for e in myevents] return render_template( "events/list.html", events=Event.list_events().fetchall(), myevents=myevents )
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 admin_show(event_id): event = Event.query.get(event_id) comments = Comment.find_comments_for_event(event_id) participants = Event.find_participants_for_event(event_id) return render_template("events/details.html", event=event, comments=comments, participants=participants)
def index(): myevents = None if current_user.is_authenticated: myevents = User.query.get(current_user.id).events myevents = [e.id for e in myevents] popular_events = Event.event_summary().fetchall() print(len(popular_events)) return render_template("index.html", events=popular_events, myevents=myevents)
def events_delete(event_id): if request.method == "GET": events_index() if Event.get_event_owner(event_id) == current_user.id: c = Event.query.get(event_id) db.session.delete(c) 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_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_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 stats_view(): categories = Statistics.time_spent_on_category(current_user.id) overall_time = datetime.timedelta(0) for i in categories.keys(): overall_time += categories[i][1] return render_template("statistics/stats_view.html", categories=categories, category_ids=categories.keys(), events=list( Event.find_events_user_has_permissions_to( current_user.id)), overall_time=overall_time, user=current_user, form=CategoryForm, str=str)
def event_join(event_id): event = Event.query.get(event_id) attendees = Event.participant_count(event_id) account = User.query.get(current_user.id) # check if event has limit and has space if event.attendee_max > 0: if attendees >= event.attendee_max: return redirect(url_for('event_show', event_id=event.id)) # cancel participation if user has already joined if event in account.attending: event.participants.remove(account) db.session().commit() return redirect(url_for('event_show', event_id=event.id)) event.participants.append(account) db.session().commit() return redirect(url_for('event_show', event_id=event.id))
def event_show(event_id): event = Event.query.get(event_id) comments = Comment.find_comments_for_event(event_id) attendees = Event.participant_count(event_id) account = User.query.get(current_user.id) # format dateinfo for template event.day = datetime.strftime(event.date_time, '%d.') event.month = datetime.strftime(event.date_time, '%B') event.time = datetime.strftime(event.date_time, '%H:%M') event.date = datetime.strftime(event.date_time, '%d.%m.%Y') if event in account.attending: userHasjoined = True else: userHasjoined = False return render_template("events/event.html", event=event, attendees=attendees, comments=comments, form=CommentForm(), userHasjoined=userHasjoined)
def events_own(): events = Event.find_all_events_attend_and_comment_count_for_user( current_user.id) return render_template("events/list.html", events=events)
def events_all(): return render_template( "events/list.html", events=Event.find_all_events_attend_and_comment_count())