示例#1
0
文件: newsAPI.py 项目: bintao/cteemo
 def get(self, tags, page):
     if tags != 'all':
         tags = tags.split('+')
         news_list = News.objects(tags__all=tags).exclude(
             'content', 'comments').order_by(
             '-date')[10 * page: 10 * (page + 1)]
     else:
         news_list = News.objects().exclude('content', 'comments').order_by(
             '-date')[10 * page: 10 * (page + 1)]
     return news_list_serialize(news_list)
示例#2
0
文件: newsAPI.py 项目: bintao/cteemo
    def post(self):
        args = newsParser.parse_args()
        id = args['id']
        title = args['title']
        abstract = args['abstract']
        news_pic = args['news_pic']
        content = args['content']
        tags = request.json['tags']

        if id is None or title is None:
            abort(400)

        news = News.objects(id=id).exclude('comments').first()
        if news is None:
            abort(400)

        news.title = title
        news.abstract = abstract
        news.news_pic = news_pic
        news.content = content
        news.tags = tags
        news.save()
        cache.delete(title)

        return news_serialize(news)
示例#3
0
文件: newsAPI.py 项目: bintao/cteemo
    def post(self):
        args = searchParser.parse_args()
        search = args['search']
        tags = request.json['tags']
        page = args['page']

        if tags is None or len(tags) == 0:
            news_list = News.objects().exclude(
                'content', 'comments').order_by('-date')
        else:
            news_list = News.objects(tags__all=tags).exclude(
                'content', 'comments').order_by('-date')
        if search is not None and search is not '':
            news_list = news_list.filter(title__icontains=search)

        return news_list_serialize(news_list[10 * page: 10 * (page + 1)])
示例#4
0
文件: newsAPI.py 项目: bintao/cteemo
    def delete(self):
        args = newsParser.parse_args()
        id = args['id']

        if id is None:
            abort(400)

        news = News.objects(id=id).first()
        if news is None:
            abort(400)

        news.delete()
        return {'status': 'success'}
示例#5
0
    def put(self):
        args = commnetParser.parse_args()
        title = args['title']
        username = args['username']
        content = args['content']

        if title is None or username is None or content is None:
            abort(400)

        comment = Comment(username=username, content=content)
        success = News.objects(title=title).only(
            'comments').update_one(push__comments=comment)
        if success is 0:
            abort(400)
        cache.delete(title + "_comment")

        return {'status': 'success'}
示例#6
0
    def get(self):
        args = commnetParser.parse_args()
        title = args['title']

        if title is None:
            abort(400)

        comemnts = cache.get(title + "_comment")
        if comemnts is not None:
            return comments_serialize(comemnts)

        news = News.objects(title=title).only('comments').first()
        if news is None:
            abort(400)
        cache.set(title + "_comment", news.comments, timeout=360000)

        return comments_serialize(news.comments)
示例#7
0
文件: newsAPI.py 项目: bintao/cteemo
    def get(self):
        args = newsParser.parse_args()
        title = args['title']

        if title is None:
            abort(400)

        news = cache.get(title)
        if news is not None:
            return news_serialize(news)

        news = News.objects(title=title).exclude('comments').first()
        if news is None:
            abort(400)
        news.update(inc__news_views=1)
        cache.set(title, news, timeout=60)

        return news_serialize(news)