Beispiel #1
0
def api_wikis_update(wid):
    ' update wiki name, description, content by id. '
    wiki = _get_wiki(wid)
    i = ctx.request.input()
    update = False
    if 'name' in i:
        wiki.name = assert_not_empty(i.name, 'name')
        update = True
    if 'description' in i:
        wiki.description = i.description.strip()
        update = True
    if 'content' in i:
        content = assert_not_empty(i.content, 'content')
        wiki.content = content
        update = True
    old_cover_id = ''
    if 'cover' in i:
        f = i.cover
        if f:
            # update cover:
            old_cover_id = wiki.cover_id
            atta = uploaders.upload_cover(wiki.name, f.file.read())
            wiki.cover_id = atta._id
            update = True
    if hasattr(wiki, 'content'):
        wiki.content_id = texts.set(wiki._id, wiki.content)
    if update:
        wiki.update()
    if old_cover_id:
        uploaders.delete_attachment(old_cover_id)
    return dict(result=True)
Beispiel #2
0
def api_delete_article(aid):
    a = Articles.get_by_id(aid)
    if a is None:
        raise notfound()
    a.delete()
    uploaders.delete_attachment(a.cover_id)
    comments.delete_comments(aid)
    return dict(result=True)
Beispiel #3
0
def api_delete_article(aid):
    a = Articles.get_by_id(aid)
    if a is None:
        raise notfound()
    a.delete()
    uploaders.delete_attachment(a.cover_id)
    comments.delete_comments(aid)
    return dict(result=True)
Beispiel #4
0
def api_wikis_delete(wid):
    ' delete a wiki by id. '
    wiki = _get_wiki(wid)
    count = WikiPages.count('where wiki_id=?', wid)
    if count > 0:
        raise APIValueError('id', 'cannot delete non-empty wiki.')
    wiki.delete()
    comments.delete_comments(wid)
    uploaders.delete_attachment(wiki.cover_id)
    return dict(result=True)
Beispiel #5
0
def api_update_article(aid):
    article = Articles.get_by_id(aid)
    if article is None:
        raise notfound()
    i = ctx.request.input()
    update = False
    if 'name' in i:
        article.name = assert_not_empty(i.name, 'name')
        update = True
    if 'summary' in i:
        article.summary = assert_not_empty(i.summary, 'summary')
        update = True
    if 'category_id' in i:
        article.category_id = _check_category_id(i.category_id)
        update = True
    if 'tags' in i:
        article.tags = texts.format_tags(i.tags)
        update = True
    # update draft first:
    if 'draft' in i:
        if i.draft.lower() == 'true':
            if not article.draft:  # change False to True:
                article.draft = True
                if article.publish_time < TIME_FEATURE:
                    article.publish_time = article.publish_time + TIME_FEATURE
                update = True
        else:
            if article.draft:  # change True to False:
                article.draft = False
                # update publish time:
                if 'publish_time' in i and i.publish_time.strip():
                    article.publish_time = time2timestamp(i.publish_time)
                else:
                    article.publish_time = time.time()
                update = True
    if 'content' in i:
        content = assert_not_empty(i.content, 'content')
        article.content = content
        update = True
    old_cover_id = ''
    if 'cover' in i:
        f = i.cover
        if f:
            # update cover:
            old_cover_id = article.cover_id
            atta = uploaders.upload_cover(article.name, f.file.read())
            article.cover_id = atta._id
            update = True
    if hasattr(article, 'content'):
        article.content_id = texts.set(article._id, article.content)
    if update:
        article.update()
    if old_cover_id:
        uploaders.delete_attachment(old_cover_id)
    return dict(_id=article._id)
Beispiel #6
0
def api_update_article(aid):
    article = Articles.get_by_id(aid)
    if article is None:
        raise notfound()
    i = ctx.request.input()
    update = False
    if 'name' in i:
        article.name = assert_not_empty(i.name, 'name')
        update = True
    if 'summary' in i:
        article.summary = assert_not_empty(i.summary, 'summary')
        update = True
    if 'category_id' in i:
        article.category_id = _check_category_id(i.category_id)
        update = True
    if 'tags' in i:
        article.tags = texts.format_tags(i.tags)
        update = True
    # update draft first:
    if 'draft' in i:
        if i.draft.lower()=='true':
            if not article.draft: # change False to True:
                article.draft = True
                if article.publish_time < TIME_FEATURE:
                    article.publish_time = article.publish_time + TIME_FEATURE
                update = True
        else:
            if article.draft: # change True to False:
                article.draft = False
                # update publish time:
                if 'publish_time' in i and i.publish_time.strip():
                    article.publish_time = time2timestamp(i.publish_time)
                else:
                    article.publish_time = time.time()
                update = True
    if 'content' in i:
        content = assert_not_empty(i.content, 'content')
        article.content = content
        update = True
    old_cover_id = ''
    if 'cover' in i:
        f = i.cover
        if f:
            # update cover:
            old_cover_id = article.cover_id
            atta = uploaders.upload_cover(article.name, f.file.read())
            article.cover_id = atta._id
            update = True
    if hasattr(article, 'content'):
        article.content_id = texts.set(article._id, article.content)
    if update:
        article.update()
    if old_cover_id:
        uploaders.delete_attachment(old_cover_id)
    return dict(_id=article._id)
Beispiel #7
0
def api_delete_attachment(aid):
    uploaders.delete_attachment(aid)
    return dict(result=True)
Beispiel #8
0
def api_delete_attachment(aid):
    uploaders.delete_attachment(aid)
    return dict(result=True)