Example #1
0
def test_add_article():
    seed_user = User.get()
    article = Article.create(source=1,
                             publish_date=datetime.now(),
                             url='www.test.com/article',
                             author='Tester',
                             title='Testing test.',
                             body='I am testing this article.')

    def query():
        return UserArticle.get(UserArticle.user == seed_user, UserArticle.article == article)

    with pytest.raises(UserArticle.DoesNotExist):
        query()

    seed_user.add_article(article)
    assert query() is not None
Example #2
0
    def post(self):
        iKwargs = request.form.to_dict()
        VaiLogs.info(iKwargs)
        # 创建一篇新文章
        newarticle = ArticleModel.create(iKwargs)
        # 添加文章目录分类 只能一个目录分类
        article = ArticleModel.mustFindOne(str(newarticle.get('_id')))
        if 'category' in iKwargs:
            category = CategoryModel.find({'name': iKwargs["category"]})
            # if 'cateid' in iKwargs:
            #     category = CategoryModel.mustFindOne(iKwargs['cateid'])
            category.addArticleModel(article)
            VaiLogs.info(category)
            cate = {
                "mk": category.get("mk", ""),
                "name": category.get("name", "")
            }
            article.set('category', cate)
            article.save()

        # 添加文章tag属性 可以多个tag属性
        if 'taglist' in iKwargs:
            tagList = eval(iKwargs['taglist'])
            for tagid in tagList:
                tag = TagModel.mustFindOne(tagid)
                tag.addArticleModel(article)
                article.addTagModel(tag)

        resp = {
            'id': str(article.get('_id', '')),
            'mk': str(article.get('mk', '')),
            'title': article.get('title', ''),
            'summary': article.get('summary', ''),
            'content': article.get('content', ''),
            'category': article.get('category', ''),
            'tag': article.get('tag', ''),
            'createDate': article.get('createDate', ''),
            'updateDate': article.get('updateDate', '')
        }
        return resp
Example #3
0
def api_new():
    form = request.get_json()
    status, data, msgs = Article.create(form)
    return iv_json_response(status, data, msgs)