예제 #1
0
def createTeam():
    if session.get("id") is None:
        return redirect("/user/login")
    name = session.get("name")
    if request.method == "GET":
        return render_template('student_templates/createTeam.html', name=name)
    else:
        name = request.form.get("name")
        userId = session.get("id")
        course = CourseAndStudent.query.filter(
            CourseAndStudent.studentId == userId).first()
        with db.auto_commit():
            team = Team()
            team.courseId = course.CourseId
            team.TeamName = name
            team.isFinish = 0
            db.session.add(team)
            team = Team.query.filter(
                Team.courseId == course.CourseId).order_by(
                    Team.TeamNumber.desc()).first()

            member = Member()
            member.studentId = userId
            member.teamId = team.TeamNumber
            member.votenum = 0

            db.session.add(member)

        return redirect('/student/display')
예제 #2
0
def join():
    if session.get("id") is None:
        return redirect("/user/login")
    name = session.get("name")
    teamId = request.args.get("id")
    team = Team.query.filter_by(TeamNumber=teamId).first()
    #查询该成员是否满员,如果满员禁止加入

    if team.isFinish == 1:
        return render_template('student_templates/viewinvitation.html',
                               name=name,
                               message="该小组满员了")

    courseId = CourseAndStudent.query.filter_by(
        studentId=session.get("id")).first().CourseId
    totalNum = Course.query.filter_by(CourseId=courseId).first().numofmember
    with db.auto_commit():
        memberr = Member()
        memberr.teamId = teamId
        memberr.studentId = session.get("id")
        memberr.votenum = 0
        db.session.add(memberr)

    countMember = Member.query.filter_by(teamId=teamId).count()
    if totalNum == countMember:

        team.isFinish = 1
        db.session.commit()

    invitelst = Invite.query.filter_by(inviteId=session.get("id")).delete()

    #检查该小组是否满员,满员则设置为isFInish=1
    #如果成功加入小组,则清除邀请信息
    invitelst = Invite.query.filter(Invite.inviteId == session.get("id"))

    result = []
    for i in invitelst:
        dict1 = {}
        studentname = Student.query.filter(
            Student.id == i.inviteeId).first().name
        dict1['info'] = studentname
        dict1['teamId'] = i.teamId
        result.append(dict1)

    return render_template('student_templates/viewinvitation.html',
                           name=name,
                           result=result)