• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

iplweb / bpp / 7cc51f57-696c-4e24-b7c6-e519e63d08ef

20 Aug 2025 07:40PM UTC coverage: 43.324% (+3.6%) from 39.761%
7cc51f57-696c-4e24-b7c6-e519e63d08ef

push

circleci

mpasternak
Merge branch 'release/v202508.1191'

5 of 5 new or added lines in 2 files covered. (100.0%)

1828 existing lines in 117 files now uncovered.

16520 of 38131 relevant lines covered (43.32%)

0.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

44.83
src/pbn_api/models/base.py
1
import warnings
2✔
2

3
from django.db import models
2✔
4
from django.db.models import JSONField
2✔
5

6
from django.utils.functional import cached_property
2✔
7

8

9
class BasePBNModel(models.Model):
2✔
10
    created_on = models.DateTimeField(auto_now_add=True)
2✔
11
    last_updated_on = models.DateTimeField(auto_now=True)
2✔
12

13
    class Meta:
2✔
14
        abstract = True
2✔
15

16

17
MAX_TEXT_FIELD_LENGTH = 350
2✔
18

19

20
class BasePBNMongoDBModel(BasePBNModel):
2✔
21
    mongoId = models.CharField(max_length=32, primary_key=True)
2✔
22
    status = models.CharField(max_length=32, db_index=True)
2✔
23
    verificationLevel = models.CharField(max_length=32, db_index=True)
2✔
24
    verified = models.BooleanField(default=False, db_index=True)
2✔
25
    versions = JSONField()
2✔
26

27
    # Nazwy pól wyciaganych "na wierzch" do pól obiektu
28
    # ze słownika JSONa (pole 'values')
29
    pull_up_on_save = None
2✔
30

31
    def _pull_up_on_save(self):
2✔
UNCOV
32
        for attr in self.pull_up_on_save:
×
UNCOV
33
            if hasattr(self, f"pull_up_{attr}"):
×
UNCOV
34
                fn = getattr(self, f"pull_up_{attr}")
×
UNCOV
35
                v = fn()
×
36
            else:
UNCOV
37
                v = self.value_or_none("object", attr)
×
38

UNCOV
39
            if v is not None:
×
40
                # Tylko błędne rekordy (takie, które zawieraja pola dlugosci kilkudziesieciu kilobajtow)
41
                # zawieraja bardzo dlugie wpisy. Np jeden rekord w polu 'nazwisko' ma 10 kb nazwisk,
42
                # po przecinku. Oczywiscie, ze sa bledne. PostgreSQL jednakze ma limit na wielkosc
43
                # wiersza indeksu. I tego limitu bedziemy teraz przestrzegali:
UNCOV
44
                if isinstance(v, str):
×
UNCOV
45
                    if len(v) >= MAX_TEXT_FIELD_LENGTH:
×
46
                        v = v[:MAX_TEXT_FIELD_LENGTH]
×
UNCOV
47
            setattr(self, attr, v)
×
48

49
    def save(
2✔
50
        self, force_insert=False, force_update=False, using=None, update_fields=None
51
    ):
UNCOV
52
        if self.pull_up_on_save:
×
UNCOV
53
            self._pull_up_on_save()
×
UNCOV
54
        return super().save(
×
55
            force_insert=force_insert,
56
            force_update=force_update,
57
            using=using,
58
            update_fields=update_fields,
59
        )
60

61
    @cached_property
2✔
62
    def current_version(self):
2✔
UNCOV
63
        if self.versions:
×
UNCOV
64
            for elem in self.versions:
×
UNCOV
65
                if elem["current"]:
×
UNCOV
66
                    return elem
×
67

68
    def value(self, *path, return_none=False):
2✔
UNCOV
69
        v = self.current_version
×
UNCOV
70
        if v is None:
×
71
            warnings.warn(
×
72
                f"Model {self.__class__} with id {self.mongoId} has NO current_version!"
73
            )
74
            if return_none:
×
75
                return
×
76
            return "[brak current_version]"
×
77

UNCOV
78
        for elem in path:
×
UNCOV
79
            if elem in v:
×
UNCOV
80
                v = v[elem]
×
81
            else:
UNCOV
82
                if return_none:
×
UNCOV
83
                    return None
×
84
                return f"[brak {elem}]"
×
UNCOV
85
        return v
×
86

87
    def value_or_none(self, *path):
2✔
UNCOV
88
        return self.value(*path, return_none=True)
×
89

90
    def website(self):
2✔
91
        return self.value("object", "website")
×
92

93
    class Meta:
2✔
94
        abstract = True
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc