Passed
Pull Request — 2.x (#1913)
by Jordi
13:12 queued 07:23
created

senaite.core.patches.dexterity   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 15
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A is_tmp_id() 0 2 1
A isTemporary() 0 7 3
1
# -*- coding: utf-8 -*-
2
3
import re
4
5
from Acquisition import aq_inner
6
from Acquisition import aq_parent
7
from bika.lims import api
8
from senaite.core import logger
9
10
TMP_RX = re.compile("[a-z0-9]{32}$")
11
12
13
def is_tmp_id(id):
14
    return TMP_RX.match(id)
15
16
17
def isTemporary(self):
18
    parent = aq_parent(aq_inner(self))
19
    # Fix indexing of temporary objects resulting in orphan entries in catalog
20
    if is_tmp_id(self.id) or is_tmp_id(parent.id):
21
        logger.debug("DX object %s is temporary!" % api.get_path(self))
22
        return True
23
    return False
24