articles.py 838 Bytes
Newer Older
luxcem's avatar
luxcem committed
1
2
3
4
from rp.models import Article
from .votes import UDList


cynddl's avatar
cynddl committed
5
class ArticleListFlux(UDList):
luxcem's avatar
luxcem committed
6
    model = Article
cynddl's avatar
cynddl committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    paginate_by = 10

    def get_queryset(self):
        filter_view = self.kwargs.get("filter_view", "draft")

        if filter_view == "published":
            qs = Article.objects.filter(status="PUBLISHED")
        elif filter_view == "draft":
            qs = Article.objects.filter(und_score__gte=3, status="PENDING")
        else:
            qs = Article.objects.filter(status="PENDING")

        return qs.order_by('-created_at')

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context["filter_view"] = self.kwargs.get("filter_view", "draft")
        context["nb_draft"] = Article.objects.filter(und_score__gte=3, status="PENDING").count()
        return context