Exemplo n.º 1
0
def board_edit(current_uid, board_id, settings):
    # settings로 넘어오는 내용
    # path, name: 보드 전체 경로
    # description: 보드 짧은 설명
    # owner: 보대 ID. uid로 변환해야 함.
    # cover: 긴 설명, cover에 들어가는 내용
    # board_type: 0 - 폴더, 1 - 게시판
    # can_write_by_other: 쓰기 가능/불가능
    # can_comment: 0 - 불가능, 1 - 가능
    # indexable: 0 - 검색 제외, 1 - 검색 포함
    # show_avatar: 0 - 안 보임, 1 - 보임
    if not acl.is_allowed('board', board_id, current_uid, 'edit'):
        return (False, _('NO_PERMISSION'))
    original_board_info = get_board_info(board_id)
    if original_board_info == None:
        return (False, _('NO_SUCH_BOARD'))
    settings['board_id'] = board_id
    new_path = posixpath.join(settings['path'], settings['name'])
    if not util.validate_boardname(new_path):
        return (False, _('INVALID_BOARDNAME'))
    if settings['board_type'] == 2:
        if article._get_article_count(board_id) > 0:
            return (False, _('ALIAS_CANT_HAVE_ARTICLE'))
        if _get_board_id_from_path(settings['description']) < 0 or settings['description'].strip() == '':
            return (False, _('NO_SUCH_BOARD'))
    old_path = original_board_info.bName
    old_directory = posixpath.dirname(old_path)
    new_directory = settings['path']
    if _get_board_id_from_path(new_path) > 0 and old_path != new_path:
        return (False, _('BOARD_ALREADY_EXIST'))
    new_parent_id = _get_board_id_from_path(settings['path'])
    if new_parent_id < 0:
        return (False, _('INVALID_PARENT'))
    if new_parent_id != original_board_info.bParent:
        if not acl.is_allowed('board', new_parent_id, current_uid, 'create'):
            return (False, _('NO_PERMISSION_ON_NEW_PARENT'))

    t = db.transaction()
    try:
        result = db.update('Boards', vars=settings, where='bSerial = $board_id',
                bInformation = settings['cover'], bDescription = settings['description'],
                bType = settings['board_type'], 
                bReply = 1, bComment = settings['can_comment'],
                indexable = settings['indexable'], 
                stylesheet = settings['stylesheet'],
                show_avatar = settings['show_avatar'],
                bWrite = settings['can_write_by_other'], 
                uSerial = settings['owner'],
                bName = new_path, bParent = new_parent_id)
        result = move_child_boards(board_id, old_path, new_path)
    except:
        t.rollback()
    else:
        t.commit()
    return (True, new_path)
Exemplo n.º 2
0
    def read_get(self, board_name, board_id, article_id):
        board_info = board.get_board_info(board_id)
        board_desc = board_info.bDescription
        a = article.get_article(board_id, article_id)
        comment = article.get_comment(article_id)

        #새글읽기 처리
        if web.ctx.session.has_key('uid'):
            uSerial = web.ctx.session.uid
            user.read_article(uSerial, article_id) 

        read_articles = web.cookies().get('read_articles')
        if read_articles:
            try:
                read_articles = [int(i) for i in read_articles.split(';')]
                if article_id not in read_articles:
                    article.increase_read_count(article_id)
                    read_articles.append(article_id)
            except ValueError:
                read_articles = []
        else:
            article.increase_read_count(article_id)
            read_articles = [article_id]
        read_articles.sort()
        read_articles = ';'.join(['%s' % i for i in read_articles])
        web.setcookie('read_articles', read_articles, 3600)

        prev_id = -1
        next_id = -1

        if not a:
            raise web.notfound(util.render().error(error_message = _('NO_SUCH_ARTICLE'), help_context='error'))
        if a.aIndex > 1:
            prev_id = article.get_article_id_by_index(board_id, a.aIndex - 1)
        if a.aIndex < article._get_article_count(board_id):
            next_id = article.get_article_id_by_index(board_id, a.aIndex + 1)
        page_no = article.get_page_by_article_id(board_id, article_id, config.page_size)
        uploads = attachment.get_attachment(article_id)
        thumbs = attachment.get_thumbnail(article_id, web.config.theme)

        return util.render().article(article = a,
            title = u"%s - %s" % (a.aIndex, a.aTitle),
            stylesheet = board_info.stylesheet,
            board_path = board_name, board_desc = board_desc,
            comments = comment, page_no = page_no,
            prev_id = prev_id, next_id = next_id, feed = True,
            attachment = uploads, thumbnail = thumbs,
            help_context = 'read_article')