def select_top_coder(): # Top Coder Layer try: # 오늘 요일 월1 ~ 일7 dayOfWeekNum = datetime.now().isoweekday() # 요일 별 제출 기간 추려내기 minusDays = {1: -1, 2: -2, 3: -3, 4: -4, 5: -5, 6: -6, 7: -0} addDays = {1: 5, 2: 4, 3: 3, 4: 2, 5: 1, 6: 0, 7: 6} # 금주의 시작일과 끝일 구함 submissionDatePeriod = dayOfWeek(minusDays=minusDays[dayOfWeekNum], addDays=addDays[dayOfWeekNum]) # 이번주에 낸 제출 목록 ranks = select_ranks( select_between_days_last_submissions( select_last_submissions(memberIdIndex=None, problemIndex=None).subquery(), submissionDatePeriod).subquery()).subquery() ranks = join_member_id( ranks, subMemberIdIndex=ranks.c.memberIdIndex).subquery() # 랭킹 동률 처리 topCoders = ranks_sorted(rankTieProcess(ranks).subquery()).all() except Exception: topCoders = [] return topCoders
def article_notice(filterCondition, keyWord, pageNum): try: # get Notice Articles articlesOnBoard = select_articles().subquery() # Get MemberId articlesOnBoard = join_member_id(articlesOnBoard, subMemberIdIndex = articlesOnBoard.c.\ writerIdIndex).subquery() # Get Problem Name articlesOnBoard = join_problems_name( subquery=articlesOnBoard, subProblemIndex=articlesOnBoard.c.problemIndex).subquery() # 과목 공지글 try: if request.method == 'POST': for form in request.form: # FilterCondition if 'keyWord' != form: filterCondition = form keyWord = get_request_value(form=request.form, name='keyWord') pageNum = 1 if not keyWord: keyWord = ' ' # Notices Sorted articleNoticeRecords = select_sorted_articles( articlesOnBoard, FilterFindParameter(filterCondition, (keyWord if keyWord != ' ' else '')), isAll=True) # Get Notices count count = select_count(articleNoticeRecords.subquery().\ c.\ articleIndex).first().\ count # Get Notices in Page articleNoticeRecords = get_page_record(articleNoticeRecords, pageNum=pageNum).all() except Exception: count = 0 articleNoticeRecords = [] return render_template( HTMLResources().const.ARTICLE_NOTICE_HTML, articleNoticeRecords=articleNoticeRecords, pages=get_page_pointed(pageNum, count), # 검색시 FilterCondition List Filters=[ LanguageResources().const.All, LanguageResources().const.Writer, LanguageResources().const.Title ], filterCondition=filterCondition, keyWord=keyWord) except Exception as e: return unknown_error(e)
def article_notice(filterCondition, keyWord, pageNum): try: # get Notice Articles articlesOnBoard = select_articles().subquery() # Get MemberId articlesOnBoard = join_member_id(articlesOnBoard, subMemberIdIndex = articlesOnBoard.c.\ writerIdIndex).subquery() # Get Problem Name articlesOnBoard = join_problems_name(subquery = articlesOnBoard, subProblemIndex = articlesOnBoard.c.problemIndex).subquery() # 과목 공지글 try: if request.method == 'POST': for form in request.form: # FilterCondition if 'keyWord' != form: filterCondition = form keyWord = get_request_value(form = request.form, name = 'keyWord') pageNum = 1 if not keyWord: keyWord = ' ' # Notices Sorted articleNoticeRecords = select_sorted_articles(articlesOnBoard, FilterFindParameter(filterCondition, (keyWord if keyWord != ' ' else '')), isAll = True) # Get Notices count count = select_count(articleNoticeRecords.subquery().\ c.\ articleIndex).first().\ count # Get Notices in Page articleNoticeRecords = get_page_record(articleNoticeRecords, pageNum = pageNum).all() except Exception: count = 0 articleNoticeRecords = [] return render_template(HTMLResources().const.ARTICLE_NOTICE_HTML, articleNoticeRecords = articleNoticeRecords, pages = get_page_pointed(pageNum, count), # 검색시 FilterCondition List Filters = [LanguageResources().const.All, LanguageResources().const.Writer, LanguageResources().const.Title], filterCondition = filterCondition, keyWord = keyWord) except Exception as e: return unknown_error(e)
def select_all_submissions(memberIdIndex=None, problemIndex=None, lastSubmission=None): if lastSubmission == None: # Submissions Table join Keys dataOfSubmissionBoard = select_data_of_submission_board( None, memberIdIndex, problemIndex).subquery() submissions = dao.query(dataOfSubmissionBoard.c.memberIdIndex, dataOfSubmissionBoard.c.problemIndex, dataOfSubmissionBoard.c.viewCount, dataOfSubmissionBoard.c.submissionReplyCount, dataOfSubmissionBoard.c.sumOfLikeCount, Submissions).\ join(Submissions, dataOfSubmissionBoard.c.submissionIndex == Submissions.submissionIndex).\ subquery() # lastSubmissions Not None Case (Problem Submitted Records) else: submissions = dao.query(lastSubmission.c.memberIdIndex, lastSubmission.c.problemIndex, lastSubmission.c.viewCount, lastSubmission.c.submissionReplyCount, lastSubmission.c.sumOfLikeCount, Submissions).\ join(Submissions, and_(lastSubmission.c.solutionCheckCount == Submissions.solutionCheckCount, lastSubmission.c.submissionIndex == Submissions.submissionIndex)).\ group_by(Submissions.submissionIndex).\ subquery() submissions = join_languages_name( submissions, submissions.c.usedLanguageIndex).subquery() submissions = join_problems_name(submissions, submissions.c.problemIndex).subquery() submissions = join_member_id(submissions, submissions.c.memberIdIndex) return submissions
def select_all_submissions(memberIdIndex = None, problemIndex = None, lastSubmission = None): if lastSubmission == None: # Submissions Table join Keys dataOfSubmissionBoard = select_data_of_submission_board(None, memberIdIndex, problemIndex).subquery() submissions = dao.query(dataOfSubmissionBoard.c.memberIdIndex, dataOfSubmissionBoard.c.problemIndex, dataOfSubmissionBoard.c.viewCount, dataOfSubmissionBoard.c.submissionReplyCount, dataOfSubmissionBoard.c.sumOfLikeCount, Submissions).\ join(Submissions, dataOfSubmissionBoard.c.submissionIndex == Submissions.submissionIndex).\ subquery() # lastSubmissions Not None Case (Problem Submitted Records) else: submissions = dao.query(lastSubmission.c.memberIdIndex, lastSubmission.c.problemIndex, lastSubmission.c.viewCount, lastSubmission.c.submissionReplyCount, lastSubmission.c.sumOfLikeCount, Submissions).\ join(Submissions, and_(lastSubmission.c.solutionCheckCount == Submissions.solutionCheckCount, lastSubmission.c.submissionIndex == Submissions.submissionIndex)).\ group_by(Submissions.submissionIndex).\ subquery() submissions = join_languages_name(submissions, submissions.c.usedLanguageIndex).subquery() submissions = join_problems_name(submissions, submissions.c.problemIndex).subquery() submissions = join_member_id(submissions, submissions.c.memberIdIndex) return submissions
def select_top_coder(): # Top Coder Layer try: # 오늘 요일 월1 ~ 일7 dayOfWeekNum = datetime.now().isoweekday() # 요일 별 제출 기간 추려내기 minusDays = {1: -1, 2: -2, 3: -3, 4: -4, 5: -5, 6: -6, 7: -0} addDays = {1: 5, 2: 4, 3: 3, 4: 2, 5: 1, 6: 0, 7: 6} # 금주의 시작일과 끝일 구함 submissionDatePeriod = dayOfWeek(minusDays = minusDays[dayOfWeekNum], addDays = addDays[dayOfWeekNum]) # 이번주에 낸 제출 목록 ranks = select_ranks(select_between_days_last_submissions(select_last_submissions(memberIdIndex = None, problemIndex = None).subquery(), submissionDatePeriod).subquery()).subquery() ranks = join_member_id(ranks, subMemberIdIndex = ranks.c.memberIdIndex).subquery() # 랭킹 동률 처리 topCoders= ranks_sorted(rankTieProcess(ranks).subquery()).all() except Exception: topCoders = [] return topCoders
def rank(sortCondition, pageNum, error =None): # Not Accept URL Check if sortCondition not in (LanguageResources().const.Rate[1], LanguageResources().const.SolvedProblems[1]): return page_not_found() try: #Searched MemberId memberId = None try: # Auto Complete MemberIds memberRecords = select_members().all() except Exception: memberRecords = [] # Last Submission Max Count submissions = select_ranks(select_last_submissions().subquery()).subquery() submissions = join_member_id(submissions, subMemberIdIndex = submissions.c.memberIdIndex).subquery() # records count try: count = select_count(submissions.c.memberIdIndex).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 memberId = get_request_value(form = request.form, name = 'memberId') try: memberIdIndex = select_match_member_id(memberId).first().memberIdIndex # 순차 탐색으로 찾아야 함 for i in range(1, pages['allPage'] + 1): # memberId in Pages ranks = get_page_record(submissions, pageNum = i).subquery() # finding MemberId in Pages if select_match_member_sub(ranks, memberIdIndex = memberIdIndex).first() != None: # Finding move to page pageNum = i # searchLine Check # RePaging Pointed pages = get_page_pointed(pageNum = pageNum, count = count) break except Exception: error = LanguageResources().const.NotExist # 랭크 정보 try: rankMemberRecords = get_page_record(submissions, pageNum = pageNum).all() except Exception: rankMemberRecords = [] return render_template(HTMLResources().const.RANK_HTML, sortCondition = sortCondition, memberRecords = memberRecords, rankMemberRecords = rankMemberRecords, pages = pages, memberId = memberId, error = error) # 페이지 정보 except Exception as e: return unknown_error(e)
def submission_code(memberIdIndex, status, problemIndex, error=None): try: # Get endDateOfSubmission of Problem # are Not Access. conditions is an Administrator and endOfSubmission ago if SETResources().const.ADMINISTRATOR in session[SessionResources().const.AUTHORITY]\ or memberIdIndex == session[SessionResources().const.MEMBER_ID_INDEX]: # Get SubmissionIndex dataOfSubmissionBoard = select_data_of_submission_board( None, memberIdIndex, problemIndex) if dataOfSubmissionBoard.first(): submissionIndex = dataOfSubmissionBoard.first().submissionIndex # 내가 Code에 누른 좋아요 정보 try: isLikeCancelled = select_code_is_like(submissionIndex, memberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX]).first().\ isLikeCancelled except Exception: # Non-Exist Case isLikeCancelled = None if request.method == 'POST': authorityCheck = is_authority( session[SessionResources().const.AUTHORITY]) for form in request.form: # 댓글 달기 if form == 'writeCodeReply': # 새로운 댓글 정보articleParameter codeReplyContent = get_request_value( form=request.form, name='writeCodeReply') if codeReplyContent: dao.add( insert_replies_on_code( submissionIndex, memberIdIndex=session[SessionResources( ).const.MEMBER_ID_INDEX], articleParameter=ArticleParameter( title=None, content=codeReplyContent, updateIp=socket.gethostbyname( socket.gethostname()), updateDate=datetime.now()))) # remove duplicated read count update_code_view_reply_counting( submissionIndex, VIEW_INCREASE=-1, REPLY_INCREASE=1) break # 댓글 삭제 elif 'deleteCodeReply' in form: # Get Reply Index replyIndex = len('deleteCodeReply') submissionReplyIndex = int(form[replyIndex:]) try: writerIndex = select_replies_on_code( submissionIndex=None, submissionReplyIndex=submissionReplyIndex ).first() except Exception: writerIndex = None if (authorityCheck[0] or authorityCheck[1])\ or writerIndex.codeReplierIdIndex == session['memberIdIndex']: update_replies_on_code_delete( submissionReplyIndex, isDeleted=ENUMResources().const.TRUE) # remove duplicated read count update_code_view_reply_counting( submissionIndex, VIEW_INCREASE=-1, REPLY_INCREASE=-1) else: error = LanguageResources().const.GetOutHere break # Commit Modify elif 'modifyCodeReplyContent' in form: replyIndex = len('modifyCodeReplyContent') submissionReplyIndex = int(form[replyIndex:]) try: writerIndex = select_replies_on_code( submissionIndex=None, submissionReplyIndex=submissionReplyIndex ).first() except Exception: writerIndex = None if writerIndex.codeReplierIdIndex == session[ 'memberIdIndex']: submissionReplyContent = get_request_value( form=request.form, name='modifyCodeReplyContent{0}'.format( form[replyIndex:])) if submissionReplyContent: #update comment update_replies_on_code_modify( submissionReplyIndex, ArticleParameter( title=None, content=submissionReplyContent, updateIp=socket.gethostbyname( socket.gethostname()), updateDate=datetime.now())) # remove duplicated read count update_code_view_reply_counting( submissionIndex, VIEW_INCREASE=-1) else: error = LanguageResources().const.GetOutHere break # end Loop # Commit Exception try: dao.commit() except Exception: dao.rollback() error = LanguageResources().const.DBFailed try: # replies 정보 repliesOnSubmissionRecords = select_replies_on_code( submissionIndex).subquery() repliesOnSubmissionRecords = join_member_id( repliesOnSubmissionRecords, repliesOnSubmissionRecords.c.codeReplierIdIndex) # 내가 게시글 리플에 누른 좋아요 정보 repliesOnSubmissionIsLikeRecords = select_replies_on_code_like( repliesOnSubmissionRecords.subquery(), session[ SessionResources().const.MEMBER_ID_INDEX]).all() repliesOnSubmissionRecords = repliesOnSubmissionRecords.all( ) except Exception: repliesOnSubmissionIsLikeRecords = [] repliesOnSubmissionRecords = [] # 읽은 횟수 카운팅 update_code_view_reply_counting(submissionIndex, VIEW_INCREASE=1) # Commit Exception try: dao.commit() except Exception: dao.rollback() # Problem Information (LimitedTime, LimitedMemory try: problemName = select_problem(problemIndex = problemIndex).first().\ problemName except Exception: problemName = None # Problem Solved Users try: # last Submissions Info lastSubmission = select_last_submissions( memberIdIndex=memberIdIndex, problemIndex=problemIndex).subquery() problemSolvedMemberRecords = select_all_submissions( memberIdIndex=memberIdIndex, problemIndex=problemIndex, lastSubmission=lastSubmission).first() except Exception: problemSolvedMemberRecords = [] # Submitted Files Information import codecs try: submittedFileRecords = select_submitted_files( dataOfSubmissionBoard.subquery()).all() fileData = [] for raw in submittedFileRecords: # Open filePath = '{0}/{1}'.format(raw.filePath, raw.fileName) # EUC_KR type try: with codecs.open(filePath, 'r', encoding='cp949') as f: # Read data = f.read() fileData.append(data) # UTF-8 Type except Exception: with codecs.open(filePath, 'r', encoding='utf8') as f: # Read data = f.read() fileData.append(data) except Exception: submittedFileRecords = [] fileData = [] return render_template(HTMLResources().const.SUBMISSION_CODE_HTML, memberIdIndex = memberIdIndex, submissionIndex = submissionIndex, submittedFileRecords = submittedFileRecords, fileData = fileData, problemName = problemName, problemSolvedMemberRecords = problemSolvedMemberRecords, isLikeCancelled = isLikeCancelled, sumOfLikeCount = dataOfSubmissionBoard.first().\ sumOfLikeCount, repliesOnSubmissionIsLikeRecords = repliesOnSubmissionIsLikeRecords, repliesOnSubmissionRecords = repliesOnSubmissionRecords, browserName = request.user_agent.browser, browserVersion = request.user_agent.version, error = error) #Access Rejection else: return redirect( url_for( RouteResources().const.PROBLEM_RECORD, status=status, problemIndex=problemIndex, sortCondition=LanguageResources().const.SubmissionDate[1])) except Exception as e: return unknown_error(e)
def article_board(filterCondition, keyWord, pageNum): try: # get Articles articlesOnBoard = select_articles().subquery() # Get MemberId articlesOnBoard = join_member_id(articlesOnBoard, subMemberIdIndex = articlesOnBoard.c.\ writerIdIndex).subquery() # Get Problem Name articlesOnBoard = join_problems_name( articlesOnBoard, subProblemIndex=articlesOnBoard.c.problemIndex).subquery() # 과목 공지글 try: articleNoticeRecords = select_sorted_articles( articlesOnBoard).all() except Exception: articleNoticeRecords = [] # 과목 게시글 try: # Search Event if request.method == 'POST': for form in request.form: # FilterCondition if 'keyWord' != form: filterCondition = form keyWord = get_request_value(form=request.form, name='keyWord') pageNum = 1 if not keyWord: keyWord = ' ' articlesOnBoardSub = select_sorted_articles( articlesOnBoard, FilterFindParameter(filterCondition, (keyWord if keyWord != ' ' else '')), articleType=ENUMResources().const.QUESTION) count = select_count(articlesOnBoardSub.subquery().\ c.articleIndex).first().\ count articleRecords = get_page_record(articlesOnBoardSub, pageNum=pageNum, LIST=int(20)).all() except Exception: count = 0 articleRecords = [] return render_template( HTMLResources().const.BOARD_HTML, articleRecords=articleRecords, articleNoticeRecords=articleNoticeRecords, pages=get_page_pointed(pageNum, count, int(20)), # 검색시 FilterCondition List Filters=[ LanguageResources().const.All, LanguageResources().const.Writer, LanguageResources().const.Title ], filterCondition=filterCondition, keyWord=keyWord) except Exception as e: return unknown_error(e)
def read(articleIndex, error=None): ''' when you push a title of board content ''' try: # 내가 게시글에 누른 좋아요 정보 try: isLikeCancelled = select_article_is_like(articleIndex, memberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX]).first().\ isLikeCancelled except Exception: # Non-Exist Case isLikeCancelled = None if request.method == 'POST': authorityCheck = is_authority( session[SessionResources().const.AUTHORITY]) for form in request.form: # 댓글 달기 if form == 'writeArticleReply': # 새로운 댓글 정보articleParameter boardReplyContent = get_request_value( form=request.form, name='writeArticleReply') if boardReplyContent: dao.add( insert_replies_on_board( articleIndex, session[ SessionResources().const.MEMBER_ID_INDEX], ArticleParameter(title=None, content=boardReplyContent, updateIp=socket.gethostbyname( socket.gethostname()), updateDate=datetime.now()))) # remove duplicated read count update_view_reply_counting(articleIndex, VIEW_INCREASE=-1, REPLY_INCREASE=1) break # 댓글 삭제 elif 'deleteArticleReply' in form: # Get Reply Index replyIndex = len('deleteArticleReply') boardReplyIndex = int(form[replyIndex:]) try: writerIndex = select_replies_on_board( articleIndex=None, boardReplyIndex=boardReplyIndex).first() except Exception: writerIndex = None if authorityCheck[0]\ or writerIndex.boardReplierIdIndex == session[SessionResources().const.MEMBER_ID_INDEX]: update_replies_on_board_delete( boardReplyIndex, isDeleted=ENUMResources().const.TRUE) # remove duplicated read count update_view_reply_counting(articleIndex, VIEW_INCREASE=-1, REPLY_INCREASE=-1) else: error = LanguageResources().const.GetOutHere break # Commit Modify elif 'modifyArticleReplyContent' in form: replyIndex = len('modifyArticleReplyContent') boardReplyIndex = int(form[replyIndex:]) try: writerIndex = select_replies_on_board( articleIndex=None, boardReplyIndex=boardReplyIndex).first() except Exception: writerIndex = None if writerIndex.boardReplierIdIndex == session[ SessionResources().const.MEMBER_ID_INDEX]: boardReplyContent = get_request_value( form=request.form, name='modifyArticleReplyContent{0}'.format( form[replyIndex:])) if boardReplyContent: #update comment update_replies_on_board_modify( boardReplyIndex, ArticleParameter(title=None, content=boardReplyContent, updateIp=socket.gethostbyname( socket.gethostname()), updateDate=datetime.now())) # remove duplicated read count update_view_reply_counting(articleIndex, VIEW_INCREASE=-1) else: error = LanguageResources().const.GetOutHere break # 게시물 삭제 elif form == 'deleteArticle': try: writerIndex = select_article( articleIndex=articleIndex).first() except Exception: writerIndex = None if authorityCheck[0]\ or writerIndex.writerIdIndex == session[SessionResources().const.MEMBER_ID_INDEX]: update_article_delete( articleIndex, isDeleted=ENUMResources().const.TRUE) # Commit Exception try: dao.commit() except Exception: dao.rollback() error = LanguageResources().const.DBFailed return redirect( url_for(RouteResources().const.ARTICLE_BOARD, filterCondition=' ', keyWord=' ', pageNum=1)) else: error = LanguageResources().const.GetOutHere # end Loop # Commit Exception try: dao.commit() except Exception: dao.rollback() error = LanguageResources().const.DBFailed # Get or Post # 게시글 정보 try: articlesOnBoard = select_article(articleIndex).subquery() #Get ProblemName articlesOnBoard = join_problems_name( subquery=articlesOnBoard, subProblemIndex=articlesOnBoard.c.problemIndex).subquery() # Get MemberId articlesOnBoard = join_member_id(articlesOnBoard, subMemberIdIndex = articlesOnBoard.c.\ writerIdIndex).first() except Exception: articlesOnBoard = [] try: # replies 정보 repliesOnBoardRecords = select_replies_on_board( articleIndex).subquery() # Get MemberId repliesOnBoardRecords = join_member_id(repliesOnBoardRecords, subMemberIdIndex = repliesOnBoardRecords.c.\ boardReplierIdIndex) # 내가 게시글 리플에 누른 좋아요 정보 repliesOnBoardIsLikeRecords = select_replies_on_board_like( repliesOnBoardRecords.subquery(), memberIdIndex=session[ SessionResources().const.MEMBER_ID_INDEX]).all() repliesOnBoardRecords = repliesOnBoardRecords.all() except Exception: repliesOnBoardIsLikeRecords = [] repliesOnBoardRecords = [] # 읽은 횟수 카운팅 update_view_reply_counting(articleIndex, VIEW_INCREASE=1) # Commit Exception try: dao.commit() except Exception: dao.rollback() return render_template( HTMLResources().const.ARTICLE_READ_HTML, articlesOnBoard=articlesOnBoard, repliesOnBoardRecords=repliesOnBoardRecords, repliesOnBoardIsLikeRecords=repliesOnBoardIsLikeRecords, isLikeCancelled=isLikeCancelled, error=error) except Exception: # Exception View return redirect( url_for(RouteResources().const.ARTICLE_BOARD, pageNum=1))
def rank(sortCondition, pageNum, error=None): # Not Accept URL Check if sortCondition not in (LanguageResources().const.Rate[1], LanguageResources().const.SolvedProblems[1]): return page_not_found() try: #Searched MemberId memberId = None try: # Auto Complete MemberIds memberRecords = select_members().all() except Exception: memberRecords = [] # Last Submission Max Count submissions = select_ranks( select_last_submissions().subquery()).subquery() submissions = join_member_id( submissions, subMemberIdIndex=submissions.c.memberIdIndex).subquery() # records count try: count = select_count(submissions.c.memberIdIndex).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 memberId = get_request_value(form=request.form, name='memberId') try: memberIdIndex = select_match_member_id( memberId).first().memberIdIndex # 순차 탐색으로 찾아야 함 for i in range(1, pages['allPage'] + 1): # memberId in Pages ranks = get_page_record(submissions, pageNum=i).subquery() # finding MemberId in Pages if select_match_member_sub( ranks, memberIdIndex=memberIdIndex).first() != None: # Finding move to page pageNum = i # searchLine Check # RePaging Pointed pages = get_page_pointed(pageNum=pageNum, count=count) break except Exception: error = LanguageResources().const.NotExist # 랭크 정보 try: rankMemberRecords = get_page_record(submissions, pageNum=pageNum).all() except Exception: rankMemberRecords = [] return render_template(HTMLResources().const.RANK_HTML, sortCondition=sortCondition, memberRecords=memberRecords, rankMemberRecords=rankMemberRecords, pages=pages, memberId=memberId, error=error) # 페이지 정보 except Exception as e: return unknown_error(e)
def submission_code(memberIdIndex, status, problemIndex, error = None): try: # Get endDateOfSubmission of Problem # are Not Access. conditions is an Administrator and endOfSubmission ago if SETResources().const.ADMINISTRATOR in session[SessionResources().const.AUTHORITY]\ or memberIdIndex == session[SessionResources().const.MEMBER_ID_INDEX]: # Get SubmissionIndex dataOfSubmissionBoard = select_data_of_submission_board(None, memberIdIndex, problemIndex) if dataOfSubmissionBoard.first(): submissionIndex = dataOfSubmissionBoard.first().submissionIndex # 내가 Code에 누른 좋아요 정보 try: isLikeCancelled = select_code_is_like(submissionIndex, memberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX]).first().\ isLikeCancelled except Exception: # Non-Exist Case isLikeCancelled = None if request.method == 'POST': authorityCheck = is_authority(session[SessionResources().const.AUTHORITY]) for form in request.form: # 댓글 달기 if form == 'writeCodeReply': # 새로운 댓글 정보articleParameter codeReplyContent = get_request_value(form = request.form, name = 'writeCodeReply') if codeReplyContent: dao.add(insert_replies_on_code(submissionIndex, memberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX], articleParameter = ArticleParameter(title = None, content = codeReplyContent, updateIp = socket.gethostbyname(socket.gethostname()), updateDate = datetime.now()))) # remove duplicated read count update_code_view_reply_counting(submissionIndex, VIEW_INCREASE = -1, REPLY_INCREASE = 1) break # 댓글 삭제 elif 'deleteCodeReply' in form: # Get Reply Index replyIndex = len('deleteCodeReply') submissionReplyIndex = int(form[replyIndex:]) try: writerIndex = select_replies_on_code(submissionIndex = None, submissionReplyIndex = submissionReplyIndex).first() except Exception: writerIndex = None if (authorityCheck[0] or authorityCheck[1])\ or writerIndex.codeReplierIdIndex == session['memberIdIndex']: update_replies_on_code_delete(submissionReplyIndex, isDeleted = ENUMResources().const.TRUE) # remove duplicated read count update_code_view_reply_counting(submissionIndex, VIEW_INCREASE = -1, REPLY_INCREASE = -1) else: error = LanguageResources().const.GetOutHere break # Commit Modify elif 'modifyCodeReplyContent' in form: replyIndex = len('modifyCodeReplyContent') submissionReplyIndex = int(form[replyIndex:]) try: writerIndex = select_replies_on_code(submissionIndex = None, submissionReplyIndex = submissionReplyIndex).first() except Exception: writerIndex = None if writerIndex.codeReplierIdIndex == session['memberIdIndex']: submissionReplyContent = get_request_value(form = request.form, name = 'modifyCodeReplyContent{0}'.format(form[replyIndex:])) if submissionReplyContent: #update comment update_replies_on_code_modify(submissionReplyIndex, ArticleParameter(title = None, content = submissionReplyContent, updateIp = socket.gethostbyname(socket.gethostname()), updateDate = datetime.now())) # remove duplicated read count update_code_view_reply_counting(submissionIndex, VIEW_INCREASE = -1) else: error = LanguageResources().const.GetOutHere break # end Loop # Commit Exception try: dao.commit() except Exception: dao.rollback() error = LanguageResources().const.DBFailed try: # replies 정보 repliesOnSubmissionRecords = select_replies_on_code(submissionIndex).subquery() repliesOnSubmissionRecords = join_member_id(repliesOnSubmissionRecords, repliesOnSubmissionRecords.c.codeReplierIdIndex) # 내가 게시글 리플에 누른 좋아요 정보 repliesOnSubmissionIsLikeRecords = select_replies_on_code_like(repliesOnSubmissionRecords.subquery(), session[SessionResources().const.MEMBER_ID_INDEX]).all() repliesOnSubmissionRecords = repliesOnSubmissionRecords.all() except Exception: repliesOnSubmissionIsLikeRecords = [] repliesOnSubmissionRecords = [] # 읽은 횟수 카운팅 update_code_view_reply_counting(submissionIndex, VIEW_INCREASE = 1) # Commit Exception try: dao.commit() except Exception: dao.rollback() # Problem Information (LimitedTime, LimitedMemory try: problemName = select_problem(problemIndex = problemIndex).first().\ problemName except Exception: problemName = None # Problem Solved Users try: # last Submissions Info lastSubmission = select_last_submissions(memberIdIndex = memberIdIndex, problemIndex = problemIndex).subquery() problemSolvedMemberRecords = select_all_submissions(memberIdIndex = memberIdIndex, problemIndex = problemIndex, lastSubmission = lastSubmission).first() except Exception: problemSolvedMemberRecords = [] # Submitted Files Information import codecs try: submittedFileRecords = select_submitted_files(dataOfSubmissionBoard.subquery()).all() fileData = [] for raw in submittedFileRecords: # Open filePath = '{0}/{1}'.format(raw.filePath, raw.fileName) # EUC_KR type try: with codecs.open(filePath, 'r', encoding = 'cp949') as f: # Read data = f.read() fileData.append(data) # UTF-8 Type except Exception: with codecs.open(filePath, 'r', encoding = 'utf8') as f: # Read data = f.read() fileData.append(data) except Exception: submittedFileRecords = [] fileData = [] return render_template(HTMLResources().const.SUBMISSION_CODE_HTML, memberIdIndex = memberIdIndex, submissionIndex = submissionIndex, submittedFileRecords = submittedFileRecords, fileData = fileData, problemName = problemName, problemSolvedMemberRecords = problemSolvedMemberRecords, isLikeCancelled = isLikeCancelled, sumOfLikeCount = dataOfSubmissionBoard.first().\ sumOfLikeCount, repliesOnSubmissionIsLikeRecords = repliesOnSubmissionIsLikeRecords, repliesOnSubmissionRecords = repliesOnSubmissionRecords, browserName = request.user_agent.browser, browserVersion = request.user_agent.version, error = error) #Access Rejection else: return redirect(url_for(RouteResources().const.PROBLEM_RECORD, status = status, problemIndex = problemIndex, sortCondition = LanguageResources().const.SubmissionDate[1])) except Exception as e: return unknown_error(e)
def article_board(filterCondition, keyWord, pageNum): try: # get Articles articlesOnBoard = select_articles().subquery() # Get MemberId articlesOnBoard = join_member_id(articlesOnBoard, subMemberIdIndex = articlesOnBoard.c.\ writerIdIndex).subquery() # Get Problem Name articlesOnBoard = join_problems_name(articlesOnBoard, subProblemIndex = articlesOnBoard.c.problemIndex).subquery() # 과목 공지글 try: articleNoticeRecords = select_sorted_articles(articlesOnBoard).all() except Exception: articleNoticeRecords = [] # 과목 게시글 try: # Search Event if request.method == 'POST': for form in request.form: # FilterCondition if 'keyWord' != form: filterCondition = form keyWord = get_request_value(form = request.form, name = 'keyWord') pageNum = 1 if not keyWord: keyWord = ' ' articlesOnBoardSub = select_sorted_articles(articlesOnBoard, FilterFindParameter(filterCondition, (keyWord if keyWord != ' ' else '')), articleType = ENUMResources().const.QUESTION) count = select_count(articlesOnBoardSub.subquery().\ c.articleIndex).first().\ count articleRecords = get_page_record(articlesOnBoardSub, pageNum = pageNum, LIST = int(20)).all() except Exception: count = 0 articleRecords = [] return render_template(HTMLResources().const.BOARD_HTML, articleRecords = articleRecords, articleNoticeRecords = articleNoticeRecords, pages = get_page_pointed(pageNum, count, int(20)), # 검색시 FilterCondition List Filters = [LanguageResources().const.All, LanguageResources().const.Writer, LanguageResources().const.Title], filterCondition = filterCondition, keyWord = keyWord) except Exception as e: return unknown_error(e)
def read(articleIndex, error = None): ''' when you push a title of board content ''' try: # 내가 게시글에 누른 좋아요 정보 try: isLikeCancelled = select_article_is_like(articleIndex, memberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX]).first().\ isLikeCancelled except Exception: # Non-Exist Case isLikeCancelled = None if request.method == 'POST': authorityCheck = is_authority(session[SessionResources().const.AUTHORITY]) for form in request.form: # 댓글 달기 if form == 'writeArticleReply': # 새로운 댓글 정보articleParameter boardReplyContent = get_request_value(form = request.form, name = 'writeArticleReply') if boardReplyContent: dao.add(insert_replies_on_board(articleIndex, session[SessionResources().const.MEMBER_ID_INDEX], ArticleParameter(title = None, content = boardReplyContent, updateIp = socket.gethostbyname(socket.gethostname()), updateDate = datetime.now()))) # remove duplicated read count update_view_reply_counting(articleIndex, VIEW_INCREASE = -1, REPLY_INCREASE = 1) break # 댓글 삭제 elif 'deleteArticleReply' in form: # Get Reply Index replyIndex = len('deleteArticleReply') boardReplyIndex = int(form[replyIndex:]) try: writerIndex = select_replies_on_board(articleIndex = None, boardReplyIndex = boardReplyIndex).first() except Exception: writerIndex = None if authorityCheck[0]\ or writerIndex.boardReplierIdIndex == session[SessionResources().const.MEMBER_ID_INDEX]: update_replies_on_board_delete(boardReplyIndex, isDeleted = ENUMResources().const.TRUE) # remove duplicated read count update_view_reply_counting(articleIndex, VIEW_INCREASE = -1, REPLY_INCREASE = -1) else: error = LanguageResources().const.GetOutHere break # Commit Modify elif 'modifyArticleReplyContent' in form: replyIndex = len('modifyArticleReplyContent') boardReplyIndex = int(form[replyIndex:]) try: writerIndex = select_replies_on_board(articleIndex = None, boardReplyIndex = boardReplyIndex).first() except Exception: writerIndex = None if writerIndex.boardReplierIdIndex == session[SessionResources().const.MEMBER_ID_INDEX]: boardReplyContent = get_request_value(form = request.form, name = 'modifyArticleReplyContent{0}'.format(form[replyIndex:])) if boardReplyContent: #update comment update_replies_on_board_modify(boardReplyIndex, ArticleParameter(title = None, content = boardReplyContent, updateIp = socket.gethostbyname(socket.gethostname()), updateDate = datetime.now())) # remove duplicated read count update_view_reply_counting(articleIndex, VIEW_INCREASE = -1) else: error = LanguageResources().const.GetOutHere break # 게시물 삭제 elif form == 'deleteArticle': try: writerIndex = select_article(articleIndex = articleIndex).first() except Exception: writerIndex = None if authorityCheck[0]\ or writerIndex.writerIdIndex == session[SessionResources().const.MEMBER_ID_INDEX]: update_article_delete(articleIndex, isDeleted = ENUMResources().const.TRUE) # Commit Exception try: dao.commit() except Exception: dao.rollback() error = LanguageResources().const.DBFailed return redirect(url_for(RouteResources().const.ARTICLE_BOARD, filterCondition = ' ', keyWord = ' ', pageNum = 1)) else: error = LanguageResources().const.GetOutHere # end Loop # Commit Exception try: dao.commit() except Exception: dao.rollback() error = LanguageResources().const.DBFailed # Get or Post # 게시글 정보 try: articlesOnBoard = select_article(articleIndex).subquery() #Get ProblemName articlesOnBoard = join_problems_name(subquery = articlesOnBoard, subProblemIndex = articlesOnBoard.c.problemIndex).subquery() # Get MemberId articlesOnBoard = join_member_id(articlesOnBoard, subMemberIdIndex = articlesOnBoard.c.\ writerIdIndex).first() except Exception: articlesOnBoard = [] try: # replies 정보 repliesOnBoardRecords = select_replies_on_board(articleIndex).subquery() # Get MemberId repliesOnBoardRecords = join_member_id(repliesOnBoardRecords, subMemberIdIndex = repliesOnBoardRecords.c.\ boardReplierIdIndex) # 내가 게시글 리플에 누른 좋아요 정보 repliesOnBoardIsLikeRecords = select_replies_on_board_like(repliesOnBoardRecords.subquery(), memberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX]).all() repliesOnBoardRecords = repliesOnBoardRecords.all() except Exception: repliesOnBoardIsLikeRecords = [] repliesOnBoardRecords = [] # 읽은 횟수 카운팅 update_view_reply_counting(articleIndex, VIEW_INCREASE = 1) # Commit Exception try: dao.commit() except Exception: dao.rollback() return render_template(HTMLResources().const.ARTICLE_READ_HTML, articlesOnBoard = articlesOnBoard, repliesOnBoardRecords = repliesOnBoardRecords, repliesOnBoardIsLikeRecords = repliesOnBoardIsLikeRecords, isLikeCancelled = isLikeCancelled, error = error) except Exception: # Exception View return redirect(url_for(RouteResources().const.ARTICLE_BOARD, pageNum = 1))