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

senaite.core.extender.ExtLabelField.set()   A

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 2
nop 4
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