예제 #1
0
def make_team(error = None):
    """ 
    doesn't have any application of button. 
    you need to make the button app. 
    """
    try:
        global gTeamMembersId, gTeamName, gTeamDescription
                # 자동 완성을 위한 모든 유저기록
        try :
            memberRecords = select_all_users().all()
        except Exception:
            memberRecords = []
        
        print "?", memberRecords
        for k in memberRecords:
            print k.memberId
                
        if request.method == 'GET':
            del gTeamMembersId[:]
            gTeamName, gTeamDescription = None, None
            
            return render_template(HTMLResources().const.TEAM_MAKE_HTML,
                                   SETResources = SETResources,
                                   SessionResources = SessionResources,
                                   LanguageResources = LanguageResources,
                                   memberRecords = memberRecords)
              
        elif request.method == 'POST':
                # 뷰를 인벨리 데이트 하기전에 인풋값 저장
            gTeamName = request.form['teamName']
            gTeamDescription = request.form['teamDescription'] if request.form['teamDescription'] else None
            
            for form in request.form:
                # Making Team
                if form == 'makeTeam':
                    
                                        # 인풋 확인
                    if not gTeamName:
                        return render_template(HTMLResources().const.TEAM_MAKE_HTML,
                                               SETResources = SETResources,
                                               SessionResources = SessionResources,
                                               LanguageResources = LanguageResources,
                                               memberRecords = memberRecords,
                                               gTeamMembersId = gTeamMembersId,
                                               gTeamDescription = gTeamDescription,
                                               error = '팀 명'  + get_message('fillData'))
                                        # 중복 팀명 확인
                    try:
                        if check_team_name(gTeamName).first().\
                                                      isDeleted == ENUMResources().const.FALSE:
                            # don't Exception
                            return render_template(HTMLResources().const.TEAM_MAKE_HTML,
                                                   SETResources = SETResources,
                                                   SessionResources = SessionResources,
                                                   LanguageResources = LanguageResources,
                                                   memberRecords = memberRecords,
                                                   gTeamMembersId = gTeamMembersId,
                                                   gTeamDescription = gTeamDescription,
                                                   error = get_message('existTeamName'))
                        # Deleted Teams
                        else:
                            # Update Team
                            dao.query(Teams).\
                                filter(Teams.teamName == gTeamName).\
                                update(dict(isDeleted = ENUMResources().const.FALSE))
                    except Exception:
                        # Insert Team
                        newTeam = Teams(teamName = gTeamName,
                                        teamDescription = gTeamDescription)
                        dao.add(newTeam)
                        
                    
                    # Commit Exception
                    try:
                        # this Commit Succeeded Go Next Step
                        dao.commit()
                                                # 마스터 정보first().teamName
                        insert_team_member_id(gTeamName,
                                              session[SessionResources().const.MEMBER_ID],
                                              ENUMResources().const.TRUE)
                        # this Commit Succeeded Go Next Step
                        try:
                            dao.commit()
                            for inviteeId in gTeamMembersId:
                                error = insert_invitee_id(gTeamName,
                                                          inviteeId)
                                # Exception Check
                                if error:
                                    break
                            #init
                            del gTeamMembersId[:]
                            gTeamName, gTeamDescription = None, None
                            flash(get_message('makeTeamSucceeded'))

                            return redirect(url_for(RouteResources().const.TEAM,
                                                    pageNum = 1))
                        except Exception:
                            dao.rollback()
                            error = get_message('updateFailed')
                    except Exception:
                        dao.rollback()
                        error = get_message('updateFailed')
                    
                # Add Members
                elif form == 'inviteeMember':
                    try:
                        inviteeId = request.form['inviteeId'].split()[0]
                    except Exception:
                        inviteeId = None
                    # teamMember Invitee
                    error = check_invitee_member(inviteeId)
                        
                    break
                # Delete Members
                elif 'deleteInviteeMember' in form:
                    # form의 name이 deleteMemberi -> i=Index이므로 해당 인덱스 값 제거
                    gTeamMembersId.pop(int(form[-1]))
                    
                    break
                
            return render_template(HTMLResources().const.TEAM_MAKE_HTML,
                                   SETResources = SETResources,
                                   SessionResources = SessionResources,
                                   LanguageResources = LanguageResources,
                                   memberRecords = memberRecords,
                                   gTeamMembersId = gTeamMembersId,
                                   gTeamName = gTeamName,
                                   gTeamDescription = gTeamDescription,
                                   error = error)
    except Exception:
        # Unknown Error
        del gTeamMembersId[:]
        gTeamName, gTeamDescription = None, None
        
        return unknown_error()
예제 #2
0
def rank(activeTabCourseId, sortCondition, pageNum, error =None):
    
    try:
        findMemberId = None
        try:
            # Auto Complete MemberIds
            memberRecords = select_all_users(isServerAdministrator = None,
                                             isCourseAdministrator = None).all()
        except Exception:
            memberRecords = []
            
        # Last Submission Max Count
        submissions = select_ranks(select_last_submissions(memberCourseProblemParameter = MemberCourseProblemParameter(memberId = None,
                                                                                                                       courseId = activeTabCourseId)).subquery()).subquery()
        
        # records count
        try:
            count = select_count(submissions.c.memberId).first().\
                                                         count
        except Exception:
            count = 0
            
        # Paging Pointed
        pages = get_page_pointed(pageNum = pageNum,
                                 count = count)
        submissions = ranks_sorted(submissions,
                                   sortCondition = sortCondition)
        # Find MemberId 뷰 호출
        if request.method == 'POST':
            # Finding MemberId
            findMemberId = request.form['memberId']
                        # 순차 탐색으로 찾아야 함
            for i in range(1, pages['allPage'] + 1):
                # memberId in Pages 
                ranks = get_page_record(submissions,
                                        pageNum = i).subquery()
                # finding MemberId in Pages
                try:
                    if select_match_member_sub(ranks,
                                               memberCourseProblemParameter = MemberCourseProblemParameter(memberId = findMemberId)).first().\
                                                                                                                                     memberId:
                        # Finding move to page
                        pageNum = i
                        # searchLine Check
                    
                        break
                except Exception:
                    pass
            else:
                                # 같은 아이디가 없을 때 메세지
                error = get_message('notExists')
       
                # 랭크 정보
        try:
            rankMemberRecords = get_page_record(submissions,
                                                pageNum = pageNum).all()
        except Exception:
            rankMemberRecords = []
        
        try:
            myCourses = select_current_courses(select_accept_courses().subquery()).all()
        except Exception:
            myCourses = []
        # myCourses Default Add ALL
        myCourses.insert(0, OtherResources().const.ALL)
       
        return render_template(HTMLResources().const.RANK_HTML,
                               activeTabCourseId = activeTabCourseId,
                               sortCondition =  sortCondition,
                               memberRecords = memberRecords,
                               rankMemberRecords = rankMemberRecords,
                               myCourses = myCourses,
                               pages = pages,
                               findMemberId = findMemberId,
                               error = error) # 페이지 정보
    except Exception:
        return unknown_error()