CrashManager   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 9
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get_queryset() 0 2 1
A __getattr__() 0 5 2
1
# coding: utf8
2
3
"""
4
This software is licensed under the Apache 2 license, quoted below.
5
6
Copyright 2014 Crystalnix Limited
7
8
Licensed under the Apache License, Version 2.0 (the "License"); you may not
9
use this file except in compliance with the License. You may obtain a copy of
10
the License at
11
12
    http://www.apache.org/licenses/LICENSE-2.0
13
14
Unless required by applicable law or agreed to in writing, software
15
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
License for the specific language governing permissions and limitations under
18
the License.
19
"""
20
21
from django.db.models.query import QuerySet
22
from django.db import models
23
from django.db.models import F, Sum
24
25
class CrashQuerySet(QuerySet):
26
    def filter_by_enabled(self, *args, **kwargs):
27
        return self.filter(is_enabled=True, *args, **kwargs)
28
29
    def get_size(self):
30
        return self.aggregate(size=Sum(F('archive_size') + F('minidump_size')))['size'] or 0
31
32
class CrashManager(models.Manager):
33
    def get_queryset(self):
34
        return CrashQuerySet(self.model, using=self._db)
35
36
    def __getattr__(self, name):
37
        if name.startswith('_'):
38
            raise AttributeError
39
        else:
40
            return getattr(self.get_queryset(), name)
41
42
class SymbolsQuerySet(QuerySet):
43
    def filter_by_enabled(self, *args, **kwargs):
44
        return self.filter(is_enabled=True, *args, **kwargs)
45
46
    def get_size(self):
47
        return self.aggregate(size=Sum('file_size'))['size'] or 0
48
49
class SymbolsManager(models.Manager):
50
    def get_queryset(self):
51
        return SymbolsQuerySet(self.model, using=self._db)
52
53
    def __getattr__(self, name):
54
        if name.startswith('_'):
55
            raise AttributeError
56
        else:
57
            return getattr(self.get_queryset(), name)
58