BaseArticleMixin   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 5
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
dl 0
loc 5
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A get_queryset() 0 2 1
1
from django.utils.translation import get_language
2
from django.views.generic import ListView, DetailView
3
from .models import Article
4
from parler.views import TranslatableSlugMixin
5
6
7
class BaseArticleMixin(object):
8
    # Only show published articles.
9
10
    def get_queryset(self):
11
        return super(BaseArticleMixin, self).get_queryset().filter(published=True)
12
13
14
class ArticleListView(BaseArticleMixin, ListView):
15
    model = Article
16
    template_name = 'article/list.html'
17
18
    def get_queryset(self):
19
        # Only show objects translated in the current language.
20
        language = get_language()
21
        return super(ArticleListView, self).get_queryset().filter(translations__language_code=language)
22
23
24
class ArticleDetailView(BaseArticleMixin, TranslatableSlugMixin, DetailView):
25
    model = Article
26
    template_name = 'article/details.html'  # This works as expected
27