Ejemplo n.º 1
0
def project_join(profile, project, event):
    if not profile:
        abort(404)
    if not event:
        abort(404)
    if not project:
        abort(404)

    user = User.query.filter_by(userid=g.user.userid).first()
    participant = Participant.query.filter_by(
        user_id=user.id,
        event_id=event.id,
        status=PARTICIPANT_STATUS.CONFIRMED).first()
    if participant == None:
        flash("You need to be a confirmed participant to join this team.",
              "fail")
        return redirect(
            url_for('project_view',
                    profile=profile.name,
                    project=project.url_name,
                    event=event.name))
    elif ProjectMember.query.filter_by(project_id=project.id,
                                       participant_id=participant.id).first():
        flash("You are already part of this team!", "fail")
    else:
        project_member = ProjectMember()
        project_member.project_id = project.id
        project_member.participant_id = participant.id
        db.session.add(project_member)
        db.session.commit()
        flash("You are now part of this team!", "success")
        return redirect(
            url_for('project_view',
                    profile=profile.name,
                    project=project.url_name,
                    event=event.name))
    return redirect(
        url_for('project_view',
                profile=profile.name,
                project=project.url_name,
                event=event.name))
Ejemplo n.º 2
0
def project_join(profile, project, event):
    if not profile:
        abort(404)
    if not event:
        abort(404)
    if not project:
        abort(404)

    user = User.query.filter_by(userid=g.user.userid).first()
    participant = Participant.query.filter_by(user_id=user.id, event_id=event.id, status=PARTICIPANT_STATUS.CONFIRMED).first()
    if participant==None:
        flash("You need to be a confirmed participant to join this team.", "fail")
        return redirect(url_for('project_view',profile=profile.name, project=project.url_name, event=event.name))
    elif ProjectMember.query.filter_by(project_id=project.id, participant_id=participant.id).first():
        flash("You are already part of this team!", "fail")
    else:
        project_member = ProjectMember()
        project_member.project_id = project.id
        project_member.participant_id = participant.id
        db.session.add(project_member)
        db.session.commit()
        flash("You are now part of this team!", "success")
        return redirect(url_for('project_view',profile=profile.name, project=project.url_name, event=event.name))
    return redirect(url_for('project_view',profile=profile.name, project=project.url_name, event=event.name))