def code_like_click(submissionIndex): # 게시글 좋아요 Push # 내가 게시글에 누른 좋아요 정보 try: isLikeCancelled = select_code_is_like(submissionIndex, memberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX]).first().\ isLikeCancelled except Exception: # Non-Exist Case isLikeCancelled = None # 좋아요를 누른적 없을 때 if not isLikeCancelled: # Insert Like dao.add( insert_likes_on_code( submissionIndex, memberIdIndex=session[ SessionResources().const.MEMBER_ID_INDEX])) # Counting +1 LIKE_INCREASE = 1 else: # 다시 좋아요 누를 때 if isLikeCancelled == ENUMResources().const.TRUE: # Counting +1 LIKE_INCREASE = 1 isLikeCancelled = ENUMResources().const.FALSE # 좋아요 취소 할 때 else: # if it's already exist then change the value of 'pushedLike' # Counting -1 LIKE_INCREASE = -1 isLikeCancelled = ENUMResources().const.TRUE # Update Like update_code_is_like( submissionIndex, memberIdIndex=session[SessionResources().const.MEMBER_ID_INDEX], isLikeCancelled=isLikeCancelled) # Article 좋아요 갯수 올리기 update_code_like_counting(submissionIndex, LIKE_INCREASE=LIKE_INCREASE) try: dao.commit() # return like count try: count = select_data_of_submission_board(submissionIndex, memberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX]).first().\ sumOfLikeCount except Exception: count = 0 return Response(str(count)) except Exception: dao.rollback() return Response()
def code_like_click(submissionIndex): # 게시글 좋아요 Push # 내가 게시글에 누른 좋아요 정보 try: isLikeCancelled = select_code_is_like(submissionIndex, memberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX]).first().\ isLikeCancelled except Exception: # Non-Exist Case isLikeCancelled = None # 좋아요를 누른적 없을 때 if not isLikeCancelled: # Insert Like dao.add(insert_likes_on_code(submissionIndex, memberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX])) # Counting +1 LIKE_INCREASE = 1 else: # 다시 좋아요 누를 때 if isLikeCancelled == ENUMResources().const.TRUE: # Counting +1 LIKE_INCREASE = 1 isLikeCancelled = ENUMResources().const.FALSE # 좋아요 취소 할 때 else: # if it's already exist then change the value of 'pushedLike' # Counting -1 LIKE_INCREASE = -1 isLikeCancelled = ENUMResources().const.TRUE # Update Like update_code_is_like(submissionIndex, memberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX], isLikeCancelled = isLikeCancelled) # Article 좋아요 갯수 올리기 update_code_like_counting(submissionIndex, LIKE_INCREASE = LIKE_INCREASE) try: dao.commit() # return like count try: count = select_data_of_submission_board(submissionIndex, memberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX]).first().\ sumOfLikeCount except Exception: count = 0 return Response(str(count)) except Exception: dao.rollback() return Response()
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 access_authority_check(problemLevel=None, memberIdIndex=None, submissionIndex=None, problemIndex=None, submissionReplyIndex=None, articleIndex=None, boardReplyIndex=None, isAdministrator=None, isWrite=None, isCode=None): try: # Zero Index Check if memberIdIndex == 0\ or problemIndex == 0\ or submissionReplyIndex == 0\ or (articleIndex == 0 and not isWrite)\ or boardReplyIndex == 0: return False # Get Authority type Turple authority = is_authority(session[SessionResources().const.AUTHORITY]) # Get my Index thisMemberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX] # Authority check authority is turple, size 3 if isAdministrator and authority[0]: if problemLevel\ and problemLevel not in (LanguageResources().const.GoldLevel[1], LanguageResources().const.SilverLevel[1], LanguageResources().const.BronzeLevel[1]): return False return True elif isAdministrator and not authority[0]: return False else: # Division Index if submissionIndex: submissionIndex = select_data_of_submission_board( submissionIndex).first() memberIdIndex = submissionIndex.memberIdIndex problemIndex = submissionIndex.problemIndex # MemberIdIndex Check if memberIdIndex\ and not select_member(memberIdIndex).first(): return False if problemIndex\ and not course_problem_check(isAdministrator, authority, memberIdIndex, problemIndex, thisMemberIdIndex, isCode): return False # Submission Reply Index check if submissionReplyIndex: replySubmissionIndex = select_replies_on_code( submissionIndex=None, submissionReplyIndex=submissionReplyIndex).first() replySubmissionIndex = select_data_of_submission_board( replySubmissionIndex.submissionIndex).first() if not course_problem_check(isAdministrator, authority, replySubmissionIndex.memberIdIndex, replySubmissionIndex.problemIndex, thisMemberIdIndex, isCode): return False # Board Check if articleIndex: article = select_article(articleIndex).first() if isWrite\ and article.writerIdIndex != thisMemberIdIndex: return False # All Pass Authority return True except Exception as e: Log.error(str(e)) return False
def access_authority_check(problemLevel = None, memberIdIndex = None, submissionIndex = None, problemIndex = None, submissionReplyIndex = None, articleIndex = None, boardReplyIndex = None, isAdministrator = None, isWrite = None, isCode = None): try: # Zero Index Check if memberIdIndex == 0\ or problemIndex == 0\ or submissionReplyIndex == 0\ or (articleIndex == 0 and not isWrite)\ or boardReplyIndex == 0: return False # Get Authority type Turple authority = is_authority(session[SessionResources().const.AUTHORITY]) # Get my Index thisMemberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX] # Authority check authority is turple, size 3 if isAdministrator and authority[0]: if problemLevel\ and problemLevel not in (LanguageResources().const.GoldLevel[1], LanguageResources().const.SilverLevel[1], LanguageResources().const.BronzeLevel[1]): return False return True elif isAdministrator and not authority[0]: return False else: # Division Index if submissionIndex: submissionIndex = select_data_of_submission_board(submissionIndex).first() memberIdIndex = submissionIndex.memberIdIndex problemIndex = submissionIndex.problemIndex # MemberIdIndex Check if memberIdIndex\ and not select_member(memberIdIndex).first(): return False if problemIndex\ and not course_problem_check(isAdministrator, authority, memberIdIndex, problemIndex, thisMemberIdIndex, isCode): return False # Submission Reply Index check if submissionReplyIndex: replySubmissionIndex = select_replies_on_code(submissionIndex = None, submissionReplyIndex = submissionReplyIndex).first() replySubmissionIndex = select_data_of_submission_board(replySubmissionIndex.submissionIndex).first() if not course_problem_check(isAdministrator, authority, replySubmissionIndex.memberIdIndex, replySubmissionIndex.problemIndex, thisMemberIdIndex, isCode): return False # Board Check if articleIndex: article = select_article(articleIndex).first() if isWrite\ and article.writerIdIndex != thisMemberIdIndex: return False # All Pass Authority return True except Exception as e: Log.error(str(e)) return False
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)