Passed
Push — 2.x ( e94308...699219 )
by Jordi
09:28
created

senaite.core.extender   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 14
dl 0
loc 21
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ExtLabelField.get() 0 3 1
A ExtLabelField.set() 0 5 2
1
# -*- coding: utf-8 -*-
2
3
from archetypes.schemaextender.field import ExtensionField
4
from bika.lims import api
5
from Products.Archetypes.Field import LinesField
6
from senaite.core.api import label as label_api
7
8
9
class ExtLabelField(ExtensionField, LinesField):
10
    """Extended Field for Labels
11
    """
12
    def get(self, instance, **kw):
13
        labels = label_api.get_obj_labels(instance)
14
        return labels
15
16
    def set(self, instance, value, **kw):
17
        if api.is_string(value):
18
            value = filter(None, value.split("\r\n"))
19
        labels = label_api.to_labels(value)
20
        return label_api.set_obj_labels(instance, labels)
21