Passed
Pull Request — 2.x (#1845)
by Ramon
05:22
created

EditForm.initialized()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nop 2
1
# -*- coding: utf-8 -*-
2
3
from bika.lims import api
4
from bika.lims import senaiteMessageFactory as _
5
from senaite.core.browser.form.adapters import EditFormAdapterBase
6
7
8
class EditForm(EditFormAdapterBase):
9
    """Edit form adapter for Lab Contact
10
    """
11
12
    def initialized(self, data):
13
        return self.data
14
15
    def modified(self, data):
16
        name = data.get("name")
17
        value = data.get("value")
18
19
        # Populate the default department
20
        if name == "Departments":
21
            departments = map(api.get_object_by_uid, value)
22
            default_dpt = self.context.getDefaultDepartment()
23
            empty = [{"title": _("None"), "value": None}]
24
            opts = map(lambda o: dict(
25
                title=api.get_title(o), value=api.get_uid(o)), departments)
26
            self.add_update_field("DefaultDepartment", {
27
                "selected": [api.get_uid(default_dpt)] if default_dpt else [],
28
                "options": empty + opts})
29
30
        return self.data
31