Passed
Push — 2.x ( f5d3d8...6a1f51 )
by Ramon
13:20 queued 07:31
created

senaite.core.patches.isFactoryContained()   A

Complexity

Conditions 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 3
nop 1
1
# -*- coding: utf-8 -*-
2
3
from Acquisition import aq_base
4
from Acquisition import aq_inner
5
from Acquisition import aq_parent
6
from Products.Archetypes import utils
7
8
9
def isFactoryContained(obj):
10
    """Are we inside the portal_factory?
11
    """
12
    if obj.isTemporary():
13
        return True
14
    parent = aq_parent(aq_inner(obj))
15
    if parent is None:
16
        # We don't have enough context to know where we are
17
        return False
18
    meta_type = getattr(aq_base(parent), "meta_type", "")
19
    return meta_type == "TempFolder"
20
21
22
# https://pypi.org/project/collective.monkeypatcher/#patching-module-level-functions 
23
utils.isFactoryContained = isFactoryContained
24