Пример #1
0
def article_like_click(articleIndex):
    # 게시글 좋아요  Push
    # 내가 게시글에 누른 좋아요 정보
    try:
        isLikeCancelled = select_article_is_like(articleIndex,
                                                 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_board(
                articleIndex,
                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_article_is_like(
            articleIndex,
            memberIdIndex=session[SessionResources().const.MEMBER_ID_INDEX],
            isLikeCancelled=isLikeCancelled)
    # Article 좋아요 갯수 올리기
    update_article_like_counting(articleIndex, LIKE_INCREASE=LIKE_INCREASE)

    try:
        dao.commit()
        # return like count
        try:
            count =  select_article(articleIndex = articleIndex).first().\
                                                                 sumOfLikeCount
        except Exception:
            count = 0

        return Response(str(count))
    except Exception:
        dao.rollback()

    return Response()
def article_like_click(articleIndex):
        # 게시글 좋아요  Push
        # 내가 게시글에 누른 좋아요 정보
    try:
        isLikeCancelled = select_article_is_like(articleIndex,
                                                 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_board(articleIndex,
                                      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_article_is_like(articleIndex,
                               memberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX],
                               isLikeCancelled = isLikeCancelled)
    # Article 좋아요 갯수 올리기
    update_article_like_counting(articleIndex,
                                 LIKE_INCREASE = LIKE_INCREASE)
    
    
    try:
        dao.commit()
        # return like count
        try:
            count =  select_article(articleIndex = articleIndex).first().\
                                                                 sumOfLikeCount
        except Exception:
            count = 0
        
        return Response(str(count))
    except Exception:
        dao.rollback()
        
    return Response()
Пример #3
0
def write(activeTabCourseId, articleIndex, error =None):
    title, content, articlesOnBoard = None, None, None
    try:
        # 수강  과목 정보
        myCourses = select_current_courses(select_accept_courses().subquery()).subquery()
        
        # Modify Case
        if articleIndex > 0: 
            try:
                articlesOnBoard = join_courses_names(select_article(articleParameter = ArticleParameter(articleIndex = articleIndex),
                                                                    isDeleted = ENUMResources().const.FALSE).subquery(),
                                                     myCourses).first()
            except Exception:
                articlesOnBoard = []
                        
        try:
            myCourses = dao.query(myCourses).all()
        except Exception:
            myCourses = []
                # 작성시 빈칸 검사
        if request.method == 'POST':
            # Not None
            try:
                courseId = request.form['courseId']
                # request.form['courseId']가 ex)2015100101 전산학 실습 일경우 중간의 공백을 기준으로 나눔
                courseId = courseId.split()[0]
                if courseId == OtherResources().const.ALL:
                    courseId = None
                    
                                # 타이틀 가져오기
                title = request.form['title']
                # Get Exist Content
                content = request.form['content']
            
                if not title:
                    error ='제목' +get_message('fillData')
                elif not request.form['content']:
                    error ='내용' +get_message('fillData')
                elif len(title) > 50:
                    error = 'Title is too long. please write less than 50 letters'
                # All Fill InputText
                else:
                    isNotice = ENUMResources().const.TRUE
                    currentDate = datetime.now()
                    currentIP = socket.gethostbyname(socket.gethostname())
                                        # 새로 작성
                    if articleIndex == 0:
                        # Set isNotice
                        if SETResources().const.USER in session['authority']: 
                            isNotice = ENUMResources().const.FALSE
                            # user None courseId reject 
                            
                        newPost = ArticlesOnBoard(problemId = None,
                                                  courseId = courseId,
                                                  writerId = session[SessionResources().const.MEMBER_ID],
                                                  isNotice = isNotice,
                                                  title = title,
                                                  content = content,
                                                  writtenDate = currentDate,
                                                  writerIp = currentIP)
                        dao.add(newPost)
                        # Commit Exception
                        try:
                            dao.commit()
                            flash(get_message('writtenPost'))
                        except Exception:
                            dao.rollback()
                            error =get_message('updateFailed')
                            
                        return redirect(url_for(RouteResources().const.BOARD,
                                                activeTabCourseId = activeTabCourseId,
                                                pageNum = 1))
                                        # 게시물 수정    
                    else:
                                                # 수정 할 글 정보
                        articlesOnBoard = select_article(articleParameter = ArticleParameter(articleIndex = articleIndex),
                                                         isDeleted = ENUMResources().const.FALSE).update(dict(courseId = courseId,
                                                                                                              title = title,
                                                                                                              content = content,
                                                                                                              writtenDate = currentDate,
                                                                                                              writerIp = currentIP))
                        
                        # Commit Exception
                        try:
                            dao.commit()
                            flash(get_message('modifiedPost'))
                        except Exception:
                            dao.rollback()
                            error =get_message('updateFailed')
                        
                        return redirect(url_for(RouteResources().const.ARTICLE_READ,
                                                activeTabCourseId = activeTabCourseId,
                                                articleIndex = articleIndex))
            except Exception:
                # User None Course Posting Rejection
                if SETResources().const.USER in session['authority']:
                    error = get_message('banPosting')
                else:
                    error = get_message()
            
                
        return render_template(HTMLResources().const.ARTICLE_WRITE_HTML,
                               SETResources = SETResources,
                               SessionResources = SessionResources,
                               LanguageResources = LanguageResources,
                               myCourses = myCourses,
                               articlesOnBoard = articlesOnBoard,
                               title = title,
                               content = content,
                               error = error)
    except Exception:
        # Unknown Error
        return unknown_error()
Пример #4
0
def read(activeTabCourseId, articleIndex, error = None):
    ''' when you push a title of board content '''
        
    try:
            # 내가 게시글에 누른 좋아요 정보
        try:
            isLikeCancelled = select_article_is_like(articleParameter = ArticleParameter(articleIndex = articleIndex,
                                                                                    boardLikerId = session[SessionResources().const.MEMBER_ID])).first().\
                                                                                                                                                 isLikeCancelled
        except Exception:
            # Non-Exist Case
            isLikeCancelled = None
            
        if request.method == 'POST':
            # flash message Init
            flashMsg =None
            for form in request.form:
                
                            # 게시글 좋아요  Push
                if form == 'articleLike':
                                    # 좋아요를 누른적 없을 때
                    if not isLikeCancelled:
                        # 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_article_like_counting(articleParameter = ArticleParameter(articleIndex = articleIndex),
                                                 LIKE_INCREASE = LIKE_INCREASE)
                    if not isLikeCancelled:
                        # Insert Like
                        dao.add(LikesOnBoard(articleIndex = articleIndex,
                                             boardLikerId = session[SessionResources().const.MEMBER_ID]))
                    else:
                        # Update Like
                        update_article_is_like(articleParameter = ArticleParameter(articleIndex = articleIndex,
                                                                                   boardLikerId = session[SessionResources().const.MEMBER_ID]),
                                               isLikeCancelled = isLikeCancelled)
                    # remove duplicated read count
                    update_view_reply_counting(articleParameter = ArticleParameter(articleIndex = articleIndex),
                                               VIEW_INCREASE = -1)
                    
                    break 
                            # 댓글 달기
                elif form == 'writeArticleReply':
                                    # 새로운 댓글 정보
                    boardReplyContent = request.form['writeArticleReply']
                    
                    if boardReplyContent:
                        dao.add(RepliesOnBoard(articleIndex = articleIndex,
                                               boardReplierId = session[SessionResources().const.MEMBER_ID],
                                               boardReplyContent = boardReplyContent,
                                               boardReplierIp = socket.gethostbyname(socket.gethostname()),
                                               boardRepliedDate = datetime.now()))
                        # remove duplicated read count
                        update_view_reply_counting(articleParameter = ArticleParameter(articleIndex = articleIndex),
                                                   VIEW_INCREASE = -1,
                                                   REPLY_INCREASE = 1)
                        
                        flashMsg =get_message('writtenComment')
                    else:
                        error = 'data' + get_message('fillData')
                        
                    break 
                            # 댓글 좋아요
                elif 'articleReplyLike' in form:  # the name starts with 'articleReplyLike' and it has its unique number
                    idIndex = len('articleReplyLike')
                                    # 내가 게시글에 누른 좋아요 정보
                    try:
                        isReplyLike = select_replies_on_board_is_like(replyParameter = ReplyParameter(boardReplyIndex = int(form[idIndex:]),
                                                                                                      boardReplyLikerId = session[SessionResources().const.MEMBER_ID])).first().\
                                                                                                                                                                        isLikeCancelled
                    except Exception:
                        # Non-Exist Case
                        isReplyLike = None
                                    # 좋아요를 누른적 없을 때
                    if not isReplyLike:
                        # Counting +1
                        LIKE_INCREASE = 1
                    else:
                                        # 다시 좋아요 누를 때
                        if isReplyLike == 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
                            
                    # Like or UnLIke
                    update_replies_on_board_like_counting(replyParameter = ReplyParameter(boardReplyIndex = int(form[idIndex:])),
                                                          LIKE_INCREASE = LIKE_INCREASE)
                    if not isReplyLike:
                        # Insert Like
                        dao.add(LikesOnReplyOfBoard(boardReplyIndex = int(form[idIndex:]),
                                                    boardReplyLikerId = session[SessionResources().const.MEMBER_ID]))
                    else:
                        # Update Like
                        update_replies_on_board_is_like(replyParameter = ReplyParameter(boardReplyIndex = int(form[idIndex:]),
                                                                                        boardReplyLikerId = session[SessionResources().const.MEMBER_ID]),
                                                        isLikeCancelled = isLikeCancelled)
                    # remove duplicated read count
                    update_view_reply_counting(articleParameter = ArticleParameter(articleIndex = articleIndex),
                                               VIEW_INCREASE = -1)
                    
                    break 
                            # 댓글 삭제   
                elif 'deleteArticleReply' in form:
                    idIndex = len('deleteArticleReply')
                    
                    update_replies_on_board_delete(replyParameter = ReplyParameter(boardReplyIndex = int(form[idIndex:])),
                                                   isDeleted = ENUMResources().const.TRUE)
                    # remove duplicated read count
                    update_view_reply_counting(articleParameter = ArticleParameter(articleIndex = articleIndex),
                                               VIEW_INCREASE = -1,
                                               REPLY_INCREASE = -1)
                    
                    flashMsg = get_message('deletedComment')
                    
                    break 
                # Commit Modify
                elif 'modifyArticleReplyContent' in form:
                    idIndex = len('modifyArticleReplyContent')
                    boardReplyContent = request.form['modifyArticleReplyContent' + form[idIndex:]]
                    
                    if boardReplyContent:
                        #update comment
                        update_replies_on_board_modify(replyParameter = ReplyParameter(boardReplyIndex = int(form[idIndex:]),
                                                                                       boardReplyLikerId = None,
                                                                                       boardReplyContent = boardReplyContent))
                        # remove duplicated read count
                        update_view_reply_counting(articleParameter = ArticleParameter(articleIndex = articleIndex),
                                                   VIEW_INCREASE = -1)
                        
                       
                        flashMsg =get_message('modifiedComment')
                    else:
                        error = 'data' + get_message('fillData')
                        
                    break
                
                            # 게시물 삭제
                elif form == 'deleteArticle':
    
                        update_article_delete(articleParameter = ArticleParameter(articleIndex = articleIndex),
                                              isDeleted = ENUMResources().const.TRUE)                    
                        # Commit Exception
                        try:
                            dao.commit()
                            flash(get_message('deletedPost'))
                        except Exception:
                            dao.rollback()
                            error = get_message('updateFailed')
                            
                        return redirect(url_for(RouteResources().const.BOARD,
                                                activeTabCourseId = OtherResources().const.ALL,
                                                pageNum = 1))
            # end Loop
            # Commit Exception
            try:
                dao.commit()
                # if flash Message exist
                if flashMsg:
                    flash(flashMsg)
            except Exception:
                dao.rollback()
                error = get_message('updateFailed')
            
            # 게시글 정보
        try:
            articlesOnBoard = select_article(articleParameter = ArticleParameter(articleIndex = articleIndex),
                                             isDeleted = ENUMResources().const.FALSE)
                
            articlesOnBoard = join_courses_names(articlesOnBoard.subquery(), 
                                                 select_current_courses(select_accept_courses().subquery()).subquery()).first()
        except Exception:
            articlesOnBoard = []
            
        try:
            # replies 정보
            repliesOnBoardRecords = select_replies_on_board(articleParameter = ArticleParameter(articleIndex = articleIndex),
                                                            isDeleted = ENUMResources().const.FALSE)
                    # 내가 게시글 리플에 누른 좋아요 정보
            repliesOnBoardIsLikeRecords = select_replies_on_board_like(repliesOnBoardRecords.subquery(),
                                                                       memberCourseProblemParameter = MemberCourseProblemParameter(memberId = session[SessionResources().const.MEMBER_ID])).all()
        except Exception:
            repliesOnBoardIsLikeRecords = []
            
        try:
            repliesOnBoardRecords = repliesOnBoardRecords.all()
        except Exception:
            repliesOnBoardRecords = []
            
                # 나의 댓글 좋아요 여부 적용
        subIndex = 0
        isLikeRecords = []
        
        for i in range(0, len(repliesOnBoardRecords)):
                # 나의 댓글 좋아요 정보 비교
            isLikeRecords.append(ENUMResources().const.TRUE)
            for j in range(subIndex, len(repliesOnBoardIsLikeRecords)):
                if repliesOnBoardRecords[i].boardReplyIndex == repliesOnBoardIsLikeRecords[j].boardReplyIndex:
                    isLikeRecords[i] = repliesOnBoardIsLikeRecords[j].isLikeCancelled
                                        # 다음 시작 루프 인덱스 변경
                    subIndex = j
                    
                    break 
            
            # 읽은 횟수 카운팅
        update_view_reply_counting(articleParameter = ArticleParameter(articleIndex = articleIndex),
                                   VIEW_INCREASE = 1)
        
        # Commit Exception
        try:
            dao.commit()
        except Exception:
            dao.rollback()
            
        return render_template(HTMLResources().const.ARTICLE_READ_HTML,
                               SETResources = SETResources,
                               SessionResources = SessionResources,
                               LanguageResources = LanguageResources,
                               articlesOnBoard = articlesOnBoard,
                               activeTabCourseId = activeTabCourseId,
                               repliesOnBoardRecords = repliesOnBoardRecords,
                               isLikeRecords = isLikeRecords,
                               isLikeCancelled = isLikeCancelled,
                               error = error)
    except Exception:
        # Exception View    
        return redirect(url_for(RouteResources().const.BOARD,
                                activeTabCourseId = OtherResources().const.ALL,
                                pageNum = 1))
Пример #5
0
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
Пример #6
0
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)
Пример #7
0
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 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 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))