articles.py 1.05 KB
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
    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":
cynddl's avatar
cynddl committed
15
16
17
18
            qs = Article.objects.extra(where=[
                "und_score_up + und_score_down >= 3",
                "status='PENDING'"
            ])
luxcem's avatar
luxcem committed
19
20
        elif filter_view == "rejected":
            qs = Article.objects.filter(status="REJECTED")
cynddl's avatar
cynddl committed
21
22
23
24
25
26
27
28
        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")
cynddl's avatar
cynddl committed
29
30
31
32
        context["nb_draft"] = Article.objects.extra(where=[
            "und_score_up + und_score_down >= 3",
            "status='PENDING'"
        ]).count()
cynddl's avatar
cynddl committed
33
        return context