def team_apply(userid, id): team = Team.query.filter_by(id=id).first() user = User.query.filter(User.id==userid).first() flag = True number = TeamUserRelation.query.filter(TeamUserRelation.team_id==team.id).filter(TeamUserRelation.is_accepted==True).count() if int(number) < int(user.team_min): flag=False flash('团队人数不足!') if flag: turs = TeamUserRelation.query.join(User, User.id == TeamUserRelation.user_id).filter( TeamUserRelation.is_accepted == False).filter(TeamUserRelation.team_id == team.id).add_columns(User.id, User.user_id, User.username, User.gender).all() turs = [tur for tur in turs if tur[0].is_accepted==False] for tur in turs: user = User.query.filter_by(id=tur[1]).first() db.session.delete(tur[0]) user.in_team = False Message.sendMessage(11, user.id, '你的团队加入申请已被拒绝') db.session.add(user) team.status = 1 db.session.add(team) db.session.commit() flash('成功') return redirect(url_for('student.my_team', id=userid))
def rejectreason(teacherid,teamid): form = RejectReasonForm() if form.validate_on_submit(): reason = form.content.data teamlist = TeamUserRelation.query.filter(TeamUserRelation.team_id == teamid).filter(TeamUserRelation.is_accepted == True).all() for user in teamlist: Message.sendMessage(teacherid,user.user_id,'团队申请已驳回:'+reason) return redirect(url_for('teacher.reject',teacherid = teacherid,teamid = teamid)) return render_template('teacher/reject_reason.html',teacherid = teacherid,teamid = teamid,form=form)
def permit(teacherid,teamid): team=Team.query.filter(Team.id==teamid).first() team.status=3 db.session.add(team) db.session.commit() stulist=TeamUserRelation.query.filter(TeamUserRelation.team_id==teamid).filter(TeamUserRelation.is_accepted==True).all() for stu in stulist: Message.sendMessage(teacherid,stu.user_id,'提交团队申请已通过') flash('已通过该团队申请!') return redirect(url_for('teacher.team'))
def permit(id,userid): flag=True team=TeamUserRelation.query.filter(TeamUserRelation.user_id==id).first() number=TeamUserRelation.query.filter(TeamUserRelation.team_id==team.team_id).filter(TeamUserRelation.is_accepted==True).count() user=User.query.filter(User.id==id).first() if number >= user.team_max: flag=False flash('团队人数已到上限!不可再加入成员') if flag: stuPermit=TeamUserRelation.query.filter_by(user_id=userid).first() stuPermit.is_accepted=True db.session.add(stuPermit) db.session.commit() Message.sendMessage(id, userid, '你的团队加入申请已被接受!') flash('已同意该同学的申请!') return redirect(url_for('student.my_team',id=id))
def adjust_add(teacherid,userid,teamid): userlist=TeamUserRelation.query.filter(TeamUserRelation.user_id==userid).first() if(int(teamid)==int(userlist.team_id)): flash('该学生已在本团队了!') else: userlist.team_id=teamid userlist.is_adjust=False db.session.add(userlist) db.session.commit() Message.sendMessage(teacherid,userid,'你已经被老师调整至其他组!请注意查看') flash('已将该学生调整到该团队!') translist=session['deleted_stu'] for user in translist: if user['id'] == int(userid): translist.remove(user) session['deleted_stu']=translist return redirect(url_for('teacher.team_adjust', teacherid=teacherid, teamid=teamid))
def trans_master(id,userid): flag=True if id==userid: flag=False flash('请设置为其他人!') return redirect(url_for('student.my_team', id=id)) if flag: user2 = TeamUserRelation.query.filter(TeamUserRelation.user_id==id).first() user2.is_master = False db.session.add(user2) userlist=TeamUserRelation.query.filter(TeamUserRelation.user_id==userid).first() print(userid) userlist.is_master=True db.session.add(userlist) db.session.commit() flash('已经将其设为组长') Message.sendMessage(id, userid, '你已经被原组长设为组长') return redirect(url_for('student.my_team', id=id))
def task_edit_score(courseid,taskid,teamid,teacherid): taskscore=TaskTeamRelation.query.filter(TaskTeamRelation.task_id==taskid).filter(TaskTeamRelation.team_id==teamid).first() form = TaskScoreForm() if form.validate_on_submit(): taskscore.score=form.task_score.data if int(form.task_score.data)>=100 or int(form.task_score.data)<0: flash('分数必须在0-100之间') userlist=TeamUserRelation.query.filter(TeamUserRelation.team_id==teamid).all() for user in userlist: Message.sendMessage(teacherid,user.user_id,'批改意见:'+form.content.data) db.session.add(taskscore) db.session.commit() flash('已经提交分数!') return redirect(url_for('teacher.task_give_score',courseid=courseid,taskid=taskid)) if taskscore.score>=0: form.task_score.data=taskscore.score form.content.data='' return render_template('teacher/set_score.html',form=form,courseid=courseid,taskid=taskid,teamid=teamid)