Ejemplo n.º 1
0
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))
Ejemplo n.º 2
0
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)