Example #1
0
    def post(self):

        data = Content.parser.parse_args()
        content = ContentModel(0, data['pages'], data['title'],
                               data['creator'], data['description'],
                               data['language'], data['year'],
                               data['imageURL'], data['documentURL'])

        interests = data['interests']

        for interestData in interests:
            keyword = interestData["keyword"]

            interest = InterestModel.find_by_keyword(keyword)

            if not interest:
                interest = InterestModel(keyword)

            interest.contents.append(content)
            content.interests.append(interest)

        print(content)

        try:
            content.save_to_db()
        except:
            return {"message": "An error occurred creating the content."}, 500

        return {"message": "Content created successfully."}, 201
Example #2
0
    def post(self):
        data = Content.parser.parse_args()
        content = ContentModel(**data)

        try:
            content.save_to_db()
        except:
            return {"message": "An error occurred inserting the item."}, 500

        return content.json(), 201
Example #3
0
    def put(cls):
        '''更新或新增md数据并转化'''
        data = _user_parser.parse_args()
        article = ArticleModel.find_by_id(data['id'])
        if article:
            my_content = ContentModel.find_by_id(data['id'])
            if my_content:
                my_content.content_md = data['content_md']
            else:
                my_content = ContentModel(data['id'], data['content_md'], '')

            main_parse.exe_mdToHTML(my_content)
            try:
                my_content.save_to_db(article)
            except:
                return {"message": "后台数据处理发生异常,请联系网站管理员。"}, 500
        else:
            return {
                'message': "文章ID '{}' 不存在,请优先新建文章。".format(data['id'])
            }, 400

        return {
            "my_content": my_content.json(),
            "message": "更新/新增项目状态成功!"
        }, 201
Example #4
0
 def post(cls):
     '''上传md数据,并进行转档,转化为html'''
     data = _user_parser.parse_args()
     article = ArticleModel.find_by_id(data['id'])
     if article:
         if ContentModel.find_by_id(data['id']):
             return {
                 'message':
                 "文章ID '{}' 详细资料已存在,如需更新请使用put请求。".format(data['id'])
             }, 400
         else:
             my_content = ContentModel(data['id'], data['content_md'], '')
             main_parse.exe_mdToHTML(my_content)
             try:
                 my_content.save_to_db(article)
                 return {
                     "my_content": my_content.json(),
                     "message": "更新/新增项目状态成功!"
                 }, 201
             except:
                 return {"message": "后台数据处理发生异常,请联系网站管理员。"}, 500
     else:
         return {
             'message': "文章ID '{}' 不存在,请优先新建文章。".format(data['id'])
         }, 400
Example #5
0
    def post(self):
        file = request.files['file']
        if file.filename == "":
            return http_response(422, {"status": "please use valid mp4 file"})

        if file and allowed_file(file.filename):
            upload(request.files['file'])
            content = {}
            content['content'] = file.filename
            content['bucket'] = VIDEO_CONTENT_BUCKET
            content['status'] = 'PENDING'
            ContentModel().insert(content)
        else:
            return http_response(422, {"status": "please use valid mp4 file"})
        return http_response(201, {"status": "video content record added"})
Example #6
0
    def post(self, name):
        parser = reqparse.RequestParser()
        parser.add_argument('id',
                            type=int,
                            required=True,
                            help="Must have an id.")
        data = parser.parse_args()
        booklist = BooklistModel.find_by_name(name)

        if booklist:
            content = ContentModel.find_by_id(data['id'])

            if content:
                booklist.contents.append(content)
                booklist.save_to_db()
                return {"message": "Content added successfully."}, 201
            return {"message": "Content does not exist."}, 404
        return {"message": "Booklist does not exist."}, 404
Example #7
0
def articles(topic):
    article = ArticleModel.find_by_id(topic)
    if article:
        project = ProjectModel.find_by_id(article.link_project)
        articles_list = project.get_all_article(None)
        content = ContentModel.find_by_id(article.id)
        if content:
            article_content = content.content_HTML
        else:
            article_content = None
    else:
        abort(404)
    return render_template(
        'generic.html',
        article_id=topic,
        articles={
            "articles_len": len(articles_list['articles']),
            "articles": articles_list['articles'],
            "article_content": article_content,
            "article_name": article.topic
        },
        sidebar_project=ProjectModel.get_all_projects_bytree())
Example #8
0
 def get(self, id):
     content = ContentModel.find_by_id(id)
     if content:
         return content.json()
     return {'message': 'Content not found'}, 404
Example #9
0
    def delete(self, id):
        store = ContentModel.find_by_id(id)
        if store:
            store.delete_from_db()

        return {'message': 'Content deleted'}
Example #10
0
 def delete(self):
     ContentModel.delete_all()
     return {'message': 'All contents deleted'}
Example #11
0
    def delete(self, content_id):
        content = ContentModel.find_by_id(content_id)
        if content:
            content.delete_from_db()

        return {'message': 'Content deleted'}
Example #12
0
    def put(self, content_id):
        data = Content.parser.parse_args()

        content = ContentModel.find_by_id(content_id)

        if content is None:
            content = ContentModel(**data)
        else:
            content.section_id = data['section_id']
            # content.content_type_id = data['content_type_id']
            content.content_value = data['content_value']
            content.content_description = data['content_description']
            content.content_order = data['content_order']
            content.content_update = datetime.now()

        content.save_to_db()

        return content.json()
 def test_Categories_Delete(self):
     inserted = ContentModel().insert(SAMPLE_CONTENT_OBJECT)
     inserted_id = inserted.inserted_id
     inserted = ContentModel().delete(inserted_id)
     deleted = ContentModel().getById(inserted_id)
     self.assertIsNone(deleted)
 def test_Content_Post(self):
     inserted = ContentModel().insert(SAMPLE_CONTENT_OBJECT)
     fetch_inserted = ContentModel().getById(inserted.inserted_id)
     self.assertEqual(SAMPLE_CONTENT_OBJECT['content'],
                      fetch_inserted['content'])
 def test_Content_Get(self):
     m = ContentModel().get({})
     self.assertGreaterEqual(m.count(), NUM_KEYS)