articles/views.py
def what_to_read_next(self, request):
        """
        Get related articles for the user to read,
        If nothing show him the latest.
        """
        current_article = request.GET.get('current_article', None)
        category = request.GET.get('category', None)
        page = request.GET.get('page', None)
        article_set = None
        NO_OF_ARTICLES = 4

        # exclude the article the user is currently reading
        if current_article:
            article_set = Article.objects.exclude(slug=current_article)

        # Prefer to get articles from the same category the user is currently reading
        if category:
            article_set = article_set.filter(category__slug=category)

        # Check if we have a minimum of 4 articles to show based on the user
        # else fill with other articles
        if article_set:
            if article_set.count() < NO_OF_ARTICLES:
                article_set = article_set | Article.objects.exclude(slug=current_article)[:NO_OF_ARTICLES - article_set.count()]
        else:
            article_set = Article.objects.exclude(slug=current_article)

        # Create a pagination to show 4 recommendations at a time
        pages = Paginator(article_set, 4)

        try:
            article_set = pages.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            print "not an interger"
            article_set = pages.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            article_set = pages.page(pages.num_pages)

        serializer = NextArticleToReadSerializer(article_set, many=True)
        if serializer.data:
            return Response(serializer.data)
        else:
            return Response({}, status=404)

        Get related articles for the user to read,
        If nothing show him the latest.
        
Get related articles for the user to read,
If nothing show him the latest.
Get related articles for the user to read If nothing show him the latest .
def what_to_read_next(self, request):
        current_article = request.GET.get('current_article', None)
        category = request.GET.get('category', None)
        page = request.GET.get('page', None)
        article_set = None
        NO_OF_ARTICLES = 4
        if current_article:
            article_set = Article.objects.exclude(slug=current_article)
        if category:
            article_set = article_set.filter(category__slug=category)
        if article_set:
            if article_set.count() < NO_OF_ARTICLES:
                article_set = article_set | Article.objects.exclude(slug=current_article)[:NO_OF_ARTICLES - article_set.count()]
        else:
            article_set = Article.objects.exclude(slug=current_article)
        pages = Paginator(article_set, 4)
        try:
            article_set = pages.page(page)
        except PageNotAnInteger:
            print "not an interger"
            article_set = pages.page(1)
        except EmptyPage:
            article_set = pages.page(pages.num_pages)
        serializer = NextArticleToReadSerializer(article_set, many=True)
        if serializer.data:
            return Response(serializer.data)
        else:
            return Response({}, status=404)
def what_to_read_next ( self , request ) : current_article = request . GET . get ( 'current_article' , None ) category = request . GET . get ( 'category' , None ) page = request . GET . get ( 'page' , None ) article_set = None NO_OF_ARTICLES = 4 if current_article : article_set = Article . objects . exclude ( slug = current_article ) if category : article_set = article_set . filter ( category__slug = category ) if article_set : if article_set . count ( ) < NO_OF_ARTICLES : article_set = article_set | Article . objects . exclude ( slug = current_article ) [ : NO_OF_ARTICLES - article_set . count ( ) ] else : article_set = Article . objects . exclude ( slug = current_article ) pages = Paginator ( article_set , 4 ) try : article_set = pages . page ( page ) except PageNotAnInteger : print "not an interger" article_set = pages . page ( 1 ) except EmptyPage : article_set = pages . page ( pages . num_pages ) serializer = NextArticleToReadSerializer ( article_set , many = True ) if serializer . data : return Response ( serializer . data ) else : return Response ( { } , status = 404 )
Get related articles for the user to read,
If nothing show him the latest.
Get related articles for the user to read If nothing show him the latest .
"""
        Get related articles for the user to read,
        If nothing show him the latest.
        """ # exclude the article the user is currently reading # Prefer to get articles from the same category the user is currently reading # Check if we have a minimum of 4 articles to show based on the user # else fill with other articles # Create a pagination to show 4 recommendations at a time # If page is not an integer, deliver first page. # If page is out of range (e.g. 9999), deliver last page of results.
self
request