示例#1
0
文件: event.py 项目: d1on/hacknight
def event_view(profile, event):
    projects = Project.query.filter_by(event_id=event.id)
    participants = Participant.query.filter(
        Participant.status != PARTICIPANT_STATUS.WITHDRAWN,
        Participant.event == event)
    accepted_participants = [p for p in participants if p.status == PARTICIPANT_STATUS.CONFIRMED]
    accepted_participants_projects = dict((participant, None) for participant in accepted_participants)
    for p in accepted_participants:
        accepted_participants_projects[p] = ProjectMember.query.filter_by(participant_id=p.id).all()
    rest_participants = [p for p in participants if p.status != PARTICIPANT_STATUS.CONFIRMED]
    rest_participants_projects = dict((participant, None) for participant in rest_participants)
    for p in rest_participants:
        rest_participants_projects[p] = Project.query.filter_by(participant_id=p.id).all()
    applied = 0
    for p in participants:
        if p.user == g.user:
            applied = 1
            break
    current_participant = Participant.get(user=g.user, event=event) if g.user else None
    return render_template('event.html', profile=profile, event=event,
        projects=projects,
        accepted_participants_projects=accepted_participants_projects,
        rest_participants_projects=rest_participants_projects,
        applied=applied,
        current_participant=current_participant,
        sponsors=event.sponsors)
示例#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)
    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,
                                  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=url_for('profile_view',
                                          profile=profile.name),
                       ajax=False)
示例#3
0
def event_apply(profile, event):
    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, title="Participant Details",
                submit=u"Participate", cancel_url=url_for('event_view',
                event=event.name, profile=profile.name), 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(url_for('event_view', **values), code=303)
示例#4
0
def event_view(profile, event):
    projects = Project.query.filter_by(event_id=event.id)
    participants = Participant.query.filter(
        Participant.status != PARTICIPANT_STATUS.WITHDRAWN,
        Participant.event == event)

    acceptedP = [p for p in participants if p.status == PARTICIPANT_STATUS.CONFIRMED]
    restP = [p for p in participants if p.status != PARTICIPANT_STATUS.CONFIRMED]
    applied = 0
    for p in participants:
        if p.user == g.user:
            applied = 1
            break
    current_participant = Participant.get(user=g.user, event=event) if g.user else None
    return render_template('event.html', profile=profile, event=event,
        projects=projects,
        acceptedparticipants=acceptedP,
        restparticipants=restP,
        applied=applied,
        current_participant=current_participant,
        sponsors=event.sponsors)
示例#5
0
def event_view(profile, event):
    projects = Project.query.filter_by(event_id=event.id)
    participants = Participant.query.filter(
        Participant.status != PARTICIPANT_STATUS.WITHDRAWN,
        Participant.event == event)
    accepted_participants = [
        p for p in participants if p.status == PARTICIPANT_STATUS.CONFIRMED
    ]
    accepted_participants_projects = dict(
        (participant, None) for participant in accepted_participants)
    for p in accepted_participants:
        accepted_participants_projects[p] = ProjectMember.query.filter_by(
            participant_id=p.id).all()
    rest_participants = [
        p for p in participants if p.status != PARTICIPANT_STATUS.CONFIRMED
    ]
    rest_participants_projects = dict(
        (participant, None) for participant in rest_participants)
    for p in rest_participants:
        rest_participants_projects[p] = Project.query.filter_by(
            participant_id=p.id).all()
    applied = 0
    for p in participants:
        if p.user == g.user:
            applied = 1
            break
    current_participant = Participant.get(user=g.user,
                                          event=event) if g.user else None
    return render_template(
        'event.html',
        profile=profile,
        event=event,
        projects=projects,
        accepted_participants_projects=accepted_participants_projects,
        rest_participants_projects=rest_participants_projects,
        applied=applied,
        current_participant=current_participant,
        sponsors=event.sponsors)
示例#6
0
 def confirmed_participant_is(self, user):
     from hacknight.models.participant import Participant, PARTICIPANT_STATUS
     p = Participant.get(user, self)
     return p and p.status == PARTICIPANT_STATUS.CONFIRMED
示例#7
0
 def participant_is(self, user):
     from hacknight.models.participant import Participant
     return Participant.get(user, self) is not None
示例#8
0
 def confirmed_participant_is(self, user):
     from hacknight.models.participant import Participant, PARTICIPANT_STATUS
     p = Participant.get(user, self)
     return p and p.status == PARTICIPANT_STATUS.CONFIRMED
示例#9
0
 def participant_is(self, user):
     from hacknight.models.participant import Participant
     return Participant.get(user, self) is not None