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

iplweb / bpp / 18634744198

19 Oct 2025 07:00PM UTC coverage: 31.618% (-29.9%) from 61.514%
18634744198

push

github

mpasternak
Merge branch 'release/v202510.1270'

657 of 9430 branches covered (6.97%)

Branch coverage included in aggregate %.

229 of 523 new or added lines in 42 files covered. (43.79%)

11303 existing lines in 316 files now uncovered.

14765 of 39346 relevant lines covered (37.53%)

0.38 hits per line

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

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

3
from django.db import models
1✔
4
from django.db.models import JSONField
1✔
5
from django.utils.functional import cached_property
1✔
6

7

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

12
    class Meta:
1✔
13
        abstract = True
1✔
14

15

16
MAX_TEXT_FIELD_LENGTH = 350
1✔
17

18

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

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

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

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

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

60
    @cached_property
1✔
61
    def current_version(self):
1✔
62
        if self.versions:
1!
63
            for elem in self.versions:
1!
64
                if elem["current"]:
1!
65
                    return elem
1✔
66

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

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

86
    def value_or_none(self, *path):
1✔
87
        return self.value(*path, return_none=True)
1✔
88

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

92
    class Meta:
1✔
93
        abstract = True
1✔
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