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 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 write(articleIndex, error=None): articleType, problemIndex, title, content, articlesOnBoard = None, None, None, None, None try: # Modify Case if articleIndex: try: articlesOnBoard = select_article(articleIndex).subquery() articlesOnBoard = join_problems_name( subquery=articlesOnBoard, subProblemIndex=articlesOnBoard.c.problemIndex).first() except Exception: articlesOnBoard = [] # 작성시 빈칸 검사 if request.method == 'POST': if not articleIndex\ or articlesOnBoard.writerIdIndex == session[SessionResources().const.MEMBER_ID_INDEX]: # Get ProblemIndex problemIndex = get_request_value(form=request.form, name='problemIndex') # Get ArticleType articleType = get_request_value(form=request.form, name='articleType') # 타이틀 가져오기 title = get_request_value(form=request.form, name='title') # Get Exist Content content = get_request_value(form=request.form, name='content') # Success Post if title and len(title) <= 100\ and content: updateDate = datetime.now() updateIp = socket.gethostbyname(socket.gethostname()) # 새로 작성 if not articleIndex: newPost = insert_articles_on_board( problemIndex=problemIndex, memberIdIndex=session[ SessionResources().const.MEMBER_ID_INDEX], articleType=articleType, articleParameter=ArticleParameter( title=title, content=content, updateDate=updateDate, updateIp=updateIp)) dao.add(newPost) # Commit Exception try: dao.commit() except exc.SQLAlchemyError: dao.rollback() error = LanguageResources().const.DBFailed return redirect( url_for(RouteResources().const.ARTICLE_BOARD, filterCondition=' ', keyWord=' ', pageNum=1)) # 게시물 수정 else: # 수정 할 글 정보 update_article_modify( articleIndex, problemIndex=problemIndex, articleType=articleType, articleParameter=ArticleParameter( title=title, content=content, updateIp=updateIp, updateDate=updateDate)) # Commit Exception try: dao.commit() except exc.SQLAlchemyError: dao.rollback() error = LanguageResources().const.DBFailed return redirect( url_for(RouteResources().const.ARTICLE_READ, articleIndex=articleIndex)) else: error = LanguageResources().const.GetOutHere return render_template(HTMLResources().const.ARTICLE_WRITE_HTML, articlesOnBoard=articlesOnBoard, articleTypes=[ ENUMResources().const.NOTICE, ENUMResources().const.QUESTION, ENUMResources().const.NORMAL ], articleType=articleType, problemIndex=problemIndex, title=title, content=content, error=error) except Exception as e: # Unknown Error 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 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 write(articleIndex, error = None): articleType, problemIndex, title, content, articlesOnBoard = None, None, None, None, None try: # Modify Case if articleIndex: try: articlesOnBoard = select_article(articleIndex).subquery() articlesOnBoard = join_problems_name(subquery = articlesOnBoard, subProblemIndex = articlesOnBoard.c.problemIndex).first() except Exception: articlesOnBoard = [] # 작성시 빈칸 검사 if request.method == 'POST': if not articleIndex\ or articlesOnBoard.writerIdIndex == session[SessionResources().const.MEMBER_ID_INDEX]: # Get ProblemIndex problemIndex = get_request_value(form = request.form, name = 'problemIndex') # Get ArticleType articleType = get_request_value(form = request.form, name = 'articleType') # 타이틀 가져오기 title = get_request_value(form = request.form, name = 'title') # Get Exist Content content = get_request_value(form = request.form, name = 'content') # Success Post if title and len(title) <= 100\ and content: updateDate = datetime.now() updateIp = socket.gethostbyname(socket.gethostname()) # 새로 작성 if not articleIndex: newPost = insert_articles_on_board(problemIndex = problemIndex, memberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX], articleType = articleType, articleParameter = ArticleParameter(title = title, content = content, updateDate = updateDate, updateIp = updateIp)) dao.add(newPost) # Commit Exception try: dao.commit() except exc.SQLAlchemyError: dao.rollback() error = LanguageResources().const.DBFailed return redirect(url_for(RouteResources().const.ARTICLE_BOARD, filterCondition = ' ', keyWord = ' ', pageNum = 1)) # 게시물 수정 else: # 수정 할 글 정보 update_article_modify(articleIndex, problemIndex = problemIndex, articleType = articleType, articleParameter = ArticleParameter(title = title, content = content, updateIp = updateIp, updateDate = updateDate)) # Commit Exception try: dao.commit() except exc.SQLAlchemyError: dao.rollback() error = LanguageResources().const.DBFailed return redirect(url_for(RouteResources().const.ARTICLE_READ, articleIndex = articleIndex)) else: error = LanguageResources().const.GetOutHere return render_template(HTMLResources().const.ARTICLE_WRITE_HTML, articlesOnBoard = articlesOnBoard, articleTypes = [ENUMResources().const.NOTICE, ENUMResources().const.QUESTION, ENUMResources().const.NORMAL], articleType = articleType, problemIndex = problemIndex, title = title, content = content, error = error) except Exception as e: # Unknown Error 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))