示例#1
0
def event_apply(profile, event):
    workflow = event.workflow()
    if not workflow.can_apply():
        flash("Hacknight is not accepting participants now, please try after sometime.")
        return render_redirect(event.url_for())
    values = {'profile': profile.name, 'event': event.name}
    participant = Participant.get(g.user, event)
    if not participant:
        # If no participant is found create a new participant entry
        # First collect some information about the new participant
        user = g.user
        form = ParticipantForm(obj=user)
        if form.validate_on_submit():
            total_participants = Participant.query.filter_by(event_id=event.id).count()
            participant = Participant(user=user, event=event)
            form.populate_obj(participant)
            participant.save_defaults()
            participant.status = PARTICIPANT_STATUS.PENDING if event.maximum_participants > total_participants else PARTICIPANT_STATUS.WL
            db.session.add(participant)
            db.session.commit()
            flash(u"Your request to participate has been recorded; you will be notified by the event manager", "success")
        else:
            return render_form(form=form, message=Markup(event.apply_instructions) if event.apply_instructions else "",
                title="Participant Details", submit=u"Participate",
                cancel_url=event.url_for(), ajax=False)
    # FIXME: Don't change anything unless this is a POST request
    elif participant.status == PARTICIPANT_STATUS.WITHDRAWN:
        participant.status = PARTICIPANT_STATUS.PENDING
        db.session.commit()
        flash(u"Your request to participate has been recorded; you will be notified by the event manager", "success")
    else:
        flash(u"Your request is pending", "error")
    return render_redirect(event.url_for(), code=303)
示例#2
0
def event_new(profile):
    if profile.userid not in g.user.user_organizations_owned_ids():
        abort(403)
    form = EventForm(parent=profile, model=Event)
    form.start_datetime.timezone = app.config['tz']
    form.end_datetime.timezone = app.config['tz']
    if form.validate_on_submit():
        event = Event(profile=profile)
        form.populate_obj(event)
        if not event.name:
            event.make_name()
        db.session.add(event)
        participant = Participant(user=g.user, event=event)
        participant.status = PARTICIPANT_STATUS.CONFIRMED
        db.session.add(participant)
        db.session.commit()
        flash(u"New event created", "success")
        return render_redirect(url_for('event_view',
                                       profile=profile.name,
                                       event=event.name),
                               code=303)
    return render_form(form=form,
                       title="New Event",
                       submit=u"Create",
                       cancel_url=profile.url_for(),
                       ajax=False)