コード例 #1
0
def select_notices():
    # Notices Layer
    
        # 로그인 상태
    if session:
                # 허용 과목 리스트
        myCourses = select_current_courses(select_accept_courses().subquery()).subquery()
        
        # TabActive Course or All Articles
        # get course or All Articles 
        articlesOnBoard = join_courses_names(# get TabActive Articles
                                             select_articles(OtherResources().const.ALL,
                                                             isDeleted = ENUMResources().const.FALSE).subquery(),
                                             myCourses).subquery()
    # Not Login     
    else:  
                # 서버 공지만
        myCourses = select_accept_courses().subquery()
        try:
            serverAdministratorId = dao.query(Members.memberId).\
                                        filter(Members.authority == SETResources().const.SERVER_ADMINISTRATOR).\
                                        first().\
                                        memberId
        except:
            serverAdministratorId = None
            
        # TabActive Course or All Articles
        # get course or All Articles 
        articlesOnBoard = join_courses_names(select_server_notice(serverAdministratorId,
                                                                  isNotice = ENUMResources().const.TRUE,
                                                                  isDeleted = ENUMResources().const.FALSE).subquery(),
                                             myCourses).subquery()
    try:
                # 과목 공지글
        # Get ServerAdministrator is All, CourseAdministrators, Users is server and course Notice
                # 서버 관리자는 모든 공지
                # 과목 관리자 및 유저는 담당 과목 공지
        articleNoticeRecords = get_page_record((select_sorted_articles(articlesOnBoard,
                                                                       isNotice = ENUMResources().const.TRUE)),
                                               pageNum = int(1),
                                               LIST = OtherResources().const.NOTICE_LIST).all()
    except Exception:
        articleNoticeRecords = []
       
    return articleNoticeRecords 
コード例 #2
0
def board(activeTabCourseId, pageNum):    
    try:
        # 검색시 FilterCondition List
        Filters = ['모두', '작성자', '제목 및 내용']
        
                # 허용 과목 리스트
        myCourses = select_current_courses(select_accept_courses().subquery()).subquery()
        # TabActive Course or All Articles
        # get course or All Articles 
        articlesOnBoard = join_courses_names(# get TabActive Articles
                                             select_articles(activeTabCourseId = activeTabCourseId,
                                                             isDeleted = ENUMResources().const.FALSE).subquery(),
                                             myCourses).subquery()
                # 과목 공지글    
        try:  
            articleNoticeRecords = get_page_record((select_sorted_articles(articlesOnBoard,
                                                                           isNotice = ENUMResources().const.TRUE)),
                                                   pageNum = int(1),
                                                   LIST = OtherResources().const.NOTICE_LIST).all()
        except Exception:
            articleNoticeRecords = []
                # 과목 게시글
        try:
            if request.method == 'POST':
                try:
                    for form in request.form:
                        # FilterCondition
                        if 'keyWord' != form:
                            filterCondition = form
                            keyWord = request.form['keyWord']
                except Exception:
                    filterCondition = None
                    keyWord = None
            else:
                filterCondition = None
                keyWord = None
                
            articlesOnBoardSub = select_sorted_articles(articlesOnBoard,
                                                        isNotice = ENUMResources().const.FALSE,
                                                        filterFindParameter = FilterFindParameter(filterCondition,
                                                                                                  keyWord))
            count = select_count(articlesOnBoardSub.subquery().\
                                                    c.articleIndex).first().\
                                                                    count
            articleRecords = get_page_record(articlesOnBoardSub,
                                             pageNum = pageNum).all()
        except Exception:
            count = 0
            articleRecords = []
            
        try:
            myCourses = dao.query(myCourses).all()
        except Exception:
            myCourses = []
        # myCourses Default Add ALL
        myCourses.insert(0, OtherResources().const.ALL)
        
        return render_template(HTMLResources().const.BOARD_HTML,
                               SETResources = SETResources,
                               SessionResources = SessionResources,
                               LanguageResources = LanguageResources,
                               articleRecords = articleRecords,
                               articleNoticeRecords =  articleNoticeRecords,
                               myCourses = myCourses,
                               pages = get_page_pointed(pageNum,
                                                        count),
                               Filters = Filters,
                               activeTabCourseId = activeTabCourseId) # classType, condition은 검색 할 때 필요한 변수    
        
    except Exception:
        return unknown_error()
コード例 #3
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))
コード例 #4
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()
コード例 #5
0
def sign_in():
    '''
    @@ Success sign in flash
    
    When the page redirected from sign up page,
    It display flash message.    
    '''
    if '?' in request.url:
        flash('Signed up successfully')
        
    ''' main page before sign in'''
    from GradeServer.utils.utilMessages import get_message
    
    from GradeServer.utils.memberCourseProblemParameter import MemberCourseProblemParameter
    
    from GradeServer.utils.utilArticleQuery import select_notices
    from GradeServer.utils.utilQuery import select_accept_courses, select_past_courses, select_current_courses, select_match_member
    from GradeServer.utils.utilRankQuery import select_top_coder
    
    from GradeServer.resource.setResources import SETResources
    from GradeServer.resource.htmlResources import HTMLResources
    from GradeServer.resource.sessionResources import SessionResources
    from GradeServer.resource.languageResources import LanguageResources

    error = None
    
    if request.method == 'POST':
        checker = True
        language = {'kr':0, # default
                    'en':1}
        
        for form in request.form:
            if "language" in form:
                checker = False
                lang = request.form['language']
                session['language'] = language[lang]
                
        if checker:        
            if not request.form['memberId']:
                error = '아이디'  + get_message('fillData')
            elif not request.form['password']:
                error = '암호'  + get_message('fillData')
            else:
                try:
                    """ DB Password check """
                    memberId = request.form['memberId'].split()[0]
                    password = request.form['password']
                    
                    check = select_match_member(memberCourseProblemParameter = MemberCourseProblemParameter(memberId = memberId)).first()
                    
                    from werkzeug.security import check_password_hash
                    
                    from GradeServer.resource.otherResources import OtherResources
                    from GradeServer.py3Des.pyDes import *
                    
                    tripleDes = triple_des(OtherResources().const.TRIPLE_DES_KEY,
                                           mode = ECB,
                                           IV = "\0\0\0\0\0\0\0\0",
                                           pad = None,
                                           padmode = PAD_PKCS5)
                    #Checking Success
                    if check_password_hash (check.password,
                                            tripleDes.encrypt(str(password))):
                        flash(get_message('login'))
                        #push Session Cache 
                        session[SessionResources().const.MEMBER_ID] = memberId
                        session[SessionResources().const.AUTHORITY] = list(check.authority)
                        session[SessionResources().const.LAST_ACCESS_DATE] = datetime.now()
                        
                        # set default language
                        session['language'] = language['kr']
                                                    
                        ownCourses = select_accept_courses().subquery()
                        # Get My Accept Courses
                        try:
                            session[SessionResources().const.OWN_CURRENT_COURSES] = select_current_courses(ownCourses).all()
                        except Exception:
                            session[SessionResources().const.OWN_CURRENT_COURSES] = []
                        try:
                            session[SessionResources().const.OWN_PAST_COURSES] = select_past_courses(ownCourses).all()
                        except Exception:
                            session[SessionResources().const.OWN_PAST_COURSES] = []
                        update_recent_access_date(memberId)
                        # Commit Exception
                        try:
                            dao.commit()
                        except Exception:
                            dao.rollback()
                            error = get_message('updateFailed')
                    else:
                        error = get_message('tryAgain')
                # Not Exist MemberId
                except Exception:
                    error = get_message('notExists')
            
    return render_template(HTMLResources().const.MAIN_HTML,
                           SETResources = SETResources,
                           SessionResources = SessionResources,
                           LanguageResources = LanguageResources,
                           noticeRecords = select_notices(),
                           topCoderId = select_top_coder(),
                           error = error)