예제 #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)