projectal.entities.note

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

Implementation of the Note API.

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

Create a Note

holder: uuId of the owner

entity: The fields of the entity to be created