Пример #1
0
 def get(self, request):
     try:
         index, size, args = utils.pagination_util(request)
         filters = {'followers': request.user}
         if args.get('title'):
             filters['title__icontains'] = args['title']
         rss_list = self.model.objects.filter(**filters)
         total = rss_list.count()
         data = self.get_serializer(rss_list[index:size], many=True).data
         return responses.SuccessResponse(data, index=index,
                                          total=total).send()
     except (exceptions.CustomException,
             drf_exceptions.ValidationError) as e:
         return responses.ErrorResponse(message=e.detail,
                                        status=e.status_code).send()
Пример #2
0
 def get(self, request, id):
     try:
         index, size, args = utils.pagination_util(request)
         comment_list = Comment.objects.filter(feed__id=id,
                                               feed__is_deleted=False,
                                               is_deleted=False)
         if args.get('order_by') and args['order_by'] == 'OLDEST':
             comment_list = comment_list.order_by('created')
         total = comment_list.count()
         data = self.get_serializer(comment_list[index:size],
                                    many=True).data
         return responses.SuccessResponse(data, index=index,
                                          total=total).send()
     except (exceptions.CustomException,
             drf_exceptions.ValidationError) as e:
         return responses.ErrorResponse(message=e.detail,
                                        status=e.status_code).send()
Пример #3
0
 def get(self, request):
     try:
         index, size, args = utils.pagination_util(request)
         filters = {'favorites': request.user}
         feed_list = self.model.objects.filter(**filters)
         if args.get('search'):
             feed_list = feed_list.filter(
                 Q(title__icontains=args['search'])
                 | Q(description__icontains=args['search'])).distinct()
         if args.get('order_by') and args['order_by'] == 'OLDEST':
             feed_list = feed_list.order_by('published')
         total = feed_list.count()
         data = self.get_serializer(feed_list[index:size], many=True).data
         return responses.SuccessResponse(data, index=index,
                                          total=total).send()
     except (exceptions.CustomException,
             drf_exceptions.ValidationError) as e:
         return responses.ErrorResponse(message=e.detail,
                                        status=e.status_code).send()
Пример #4
0
    def get(self, request, id):
        try:
            index, size, args = utils.pagination_util(request)
            rss = Rss.objects.get(id=id, is_active=True)
            # Update last seen this rss
            FollowRss.objects.filter(
                rss=rss, user=request.user).update(last_seen=utils.now_time())

            filters = {'rss': rss}
            if args.get('title'):
                filters['title__icontains'] = args['title']

            feed_list = self.model.objects.filter(**filters)
            if args.get('order_by') and args['order_by'] == 'OLDEST':
                feed_list = feed_list.order_by('published')
            total = feed_list.count()
            data = self.get_serializer(feed_list[index:size], many=True).data
            return responses.SuccessResponse(data, index=index,
                                             total=total).send()
        except (exceptions.CustomException, drf_exceptions.ValidationError,
                Rss.DoesNotExist) as e:
            return responses.ErrorResponse(message=e.detail,
                                           status=e.status_code).send()