BaseManagerQuerySet.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1 1
from django.db.models import Manager, QuerySet
2 1
from django.utils import timezone
3
4
5 1
class BaseManager(Manager):
6 1
    def __init__(self, *args, **kwargs):
7 1
        self.this_year_lookup = kwargs.pop('this_year_lookup',
8
                                           'created_on__year')
9 1
        super().__init__(*args, **kwargs)
10
11 1
    def get_queryset(self):
12 1
        return BaseManagerQuerySet(self.model,
13
                                   using=self._db,
14
                                   this_year_lookup=self.this_year_lookup)
15
16 1
    def from_year(self, year, *ar, **kw):
17 1
        return self.get_queryset().from_year(year, *ar, **kw)
18
19 1
    def this_year(self, *ar, **kw):
20 1
        return self.get_queryset().this_year(*ar, **kw)
21
22
23 1
class BaseManagerQuerySet(QuerySet):
24 1
    def __init__(self, *args, **kwargs):
25 1
        self.this_year_lookup = kwargs.pop('this_year_lookup',
26
                                           'created_on__year')
27 1
        super().__init__(*args, **kwargs)
28
29 1
    def from_year(self, year):
30 1
        return self.filter(**{self.this_year_lookup: year})
31
32 1
    def this_year(self):
33
        return self.filter(**{self.this_year_lookup: timezone.now().year})
34