projectal.entities.note

 1import copy
 2
 3import projectal
 4from projectal.entity import Entity
 5from projectal.linkers import *
 6
 7
 8class Note(Entity, TagLinker):
 9    """
10    Implementation of the [Note](https://projectal.com/docs/latest/#tag/Note) API.
11    """
12
13    _path = "note"
14    _name = "note"
15    _links = [TagLinker]  # TODO: user?
16
17    @classmethod
18    def create(
19        cls,
20        holder,
21        entity,
22        batch_linking=True,
23        disable_system_features=True,
24        enable_system_features_on_exit=True,
25    ):
26        """Create a Note
27
28        `holder`: `uuId` of the owner
29
30        `entity`: The fields of the entity to be created
31        """
32        holder_id = holder["uuId"] if isinstance(holder, dict) else holder
33        params = "?holder=" + holder_id
34        out = super().create(
35            entity,
36            params,
37            batch_linking,
38            disable_system_features,
39            enable_system_features_on_exit,
40        )
41        # Notes use "empty linkers" during creation which don't go through our
42        # usual linker pipeline where the internal list is updated. Do it here
43        # manually.
44        if isinstance(holder, Entity):
45            nl = holder.get("noteList", [])
46            nl.append(out)
47            holder.set_readonly("noteList", copy.deepcopy(nl))
48
49        # Notes contain references to the objects that made and hold them. We don't get this
50        # information from the creation api method, but we can insert them ourselves because
51        # we know what they are.
52        time = projectal.response_timestamp
53
54        def add_fields(obj):
55            obj.set_readonly("created", time)
56            obj.set_readonly("modified", time)
57            obj.set_readonly("author", projectal.api_auth_details.get("name"))
58            obj.set_readonly("authorRef", projectal.api_auth_details.get("uuId"))
59            obj.set_readonly("holderRef", holder_id)
60            tag = None
61            if isinstance(holder, Entity):
62                tag = holder._name.upper()
63            obj.set_readonly("holderTag", tag)
64
65        if isinstance(out, dict):
66            add_fields(out)
67        if isinstance(out, list):
68            for obj in out:
69                add_fields(obj)
70        return out
 9class Note(Entity, TagLinker):
10    """
11    Implementation of the [Note](https://projectal.com/docs/latest/#tag/Note) API.
12    """
13
14    _path = "note"
15    _name = "note"
16    _links = [TagLinker]  # TODO: user?
17
18    @classmethod
19    def create(
20        cls,
21        holder,
22        entity,
23        batch_linking=True,
24        disable_system_features=True,
25        enable_system_features_on_exit=True,
26    ):
27        """Create a Note
28
29        `holder`: `uuId` of the owner
30
31        `entity`: The fields of the entity to be created
32        """
33        holder_id = holder["uuId"] if isinstance(holder, dict) else holder
34        params = "?holder=" + holder_id
35        out = super().create(
36            entity,
37            params,
38            batch_linking,
39            disable_system_features,
40            enable_system_features_on_exit,
41        )
42        # Notes use "empty linkers" during creation which don't go through our
43        # usual linker pipeline where the internal list is updated. Do it here
44        # manually.
45        if isinstance(holder, Entity):
46            nl = holder.get("noteList", [])
47            nl.append(out)
48            holder.set_readonly("noteList", copy.deepcopy(nl))
49
50        # Notes contain references to the objects that made and hold them. We don't get this
51        # information from the creation api method, but we can insert them ourselves because
52        # we know what they are.
53        time = projectal.response_timestamp
54
55        def add_fields(obj):
56            obj.set_readonly("created", time)
57            obj.set_readonly("modified", time)
58            obj.set_readonly("author", projectal.api_auth_details.get("name"))
59            obj.set_readonly("authorRef", projectal.api_auth_details.get("uuId"))
60            obj.set_readonly("holderRef", holder_id)
61            tag = None
62            if isinstance(holder, Entity):
63                tag = holder._name.upper()
64            obj.set_readonly("holderTag", tag)
65
66        if isinstance(out, dict):
67            add_fields(out)
68        if isinstance(out, list):
69            for obj in out:
70                add_fields(obj)
71        return out

Implementation of the Note API.

@classmethod
def create( cls, holder, entity, batch_linking=True, disable_system_features=True, enable_system_features_on_exit=True):
18    @classmethod
19    def create(
20        cls,
21        holder,
22        entity,
23        batch_linking=True,
24        disable_system_features=True,
25        enable_system_features_on_exit=True,
26    ):
27        """Create a Note
28
29        `holder`: `uuId` of the owner
30
31        `entity`: The fields of the entity to be created
32        """
33        holder_id = holder["uuId"] if isinstance(holder, dict) else holder
34        params = "?holder=" + holder_id
35        out = super().create(
36            entity,
37            params,
38            batch_linking,
39            disable_system_features,
40            enable_system_features_on_exit,
41        )
42        # Notes use "empty linkers" during creation which don't go through our
43        # usual linker pipeline where the internal list is updated. Do it here
44        # manually.
45        if isinstance(holder, Entity):
46            nl = holder.get("noteList", [])
47            nl.append(out)
48            holder.set_readonly("noteList", copy.deepcopy(nl))
49
50        # Notes contain references to the objects that made and hold them. We don't get this
51        # information from the creation api method, but we can insert them ourselves because
52        # we know what they are.
53        time = projectal.response_timestamp
54
55        def add_fields(obj):
56            obj.set_readonly("created", time)
57            obj.set_readonly("modified", time)
58            obj.set_readonly("author", projectal.api_auth_details.get("name"))
59            obj.set_readonly("authorRef", projectal.api_auth_details.get("uuId"))
60            obj.set_readonly("holderRef", holder_id)
61            tag = None
62            if isinstance(holder, Entity):
63                tag = holder._name.upper()
64            obj.set_readonly("holderTag", tag)
65
66        if isinstance(out, dict):
67            add_fields(out)
68        if isinstance(out, list):
69            for obj in out:
70                add_fields(obj)
71        return out

Create a Note

holder: uuId of the owner

entity: The fields of the entity to be created