projectal.entities.task_template

 1from projectal.entity import Entity
 2from projectal.linkers import *
 3
 4
 5class TaskTemplate(
 6    Entity,
 7    ResourceLinker,
 8    SkillLinker,
 9    FileLinker,
10    StaffLinker,
11    RebateLinker,
12    NoteLinker,
13    TagLinker,
14):
15    """
16    Implementation of the
17    [Task Template](https://projectal.com/docs/latest/#tag/Task-Template) API.
18    """
19
20    _path = "template/task"
21    _name = "task_template"
22    _links = [
23        ResourceLinker,
24        SkillLinker,
25        FileLinker,
26        StaffLinker,
27        RebateLinker,
28        NoteLinker,
29        TagLinker,
30    ]
31
32    def clone(self, holder, entity):
33        url = "/api/template/task/clone?holder={}&reference={}".format(
34            holder["uuId"], self["uuId"]
35        )
36        response = api.post(url, entity)
37        return response["jobClue"]["uuId"]
38
39    @classmethod
40    def create(cls, holder, entity):
41        """Create a Task Template
42
43        `holder`: `uuId` of the owner
44
45        `entity`: The fields of the entity to be created
46        """
47        holder = holder["uuId"] if isinstance(holder, dict) else holder
48        params = "?holder=" + holder
49        return super().create(entity, params)
50
51    @classmethod
52    def list(cls, expand=False, links=None):
53        """Return a list of all entity UUIDs of this type.
54
55        You may pass in `expand=True` to get full Entity objects
56        instead, but be aware this may be very slow if you have
57        thousands of objects.
58
59        If you are expanding the objects, you may further expand
60        the results with `links`.
61        """
62
63        payload = {
64            "name": "List all entities of type {}".format(cls._name.upper()),
65            "type": "msql",
66            "start": 0,
67            "limit": -1,
68            "select": [["PROJECT_TEMPLATE.{}.uuId".format(cls._name.upper())]],
69        }
70        ids = api.query(payload)
71        ids = [id_[0] for id_ in ids]
72        if ids:
73            return cls.get(ids, links=links) if expand else ids
74        return []
75
76    @classmethod
77    def link_predecessor_task(cls, task, predecessor_task):
78        return cls.__plan(task, predecessor_task, "add")
79
80    @classmethod
81    def relink_predecessor_task(cls, task, predecessor_task):
82        return cls.__plan(task, predecessor_task, "update")
83
84    @classmethod
85    def unlink_predecessor_task(cls, task, predecessor_task):
86        return cls.__plan(task, predecessor_task, "delete")
87
88    @classmethod
89    def __plan(cls, from_task, to_task, operation):
90        url = "/api/template/task/plan/task/{}".format(operation)
91        payload = {"uuId": from_task["uuId"], "taskList": [to_task]}
92        api.post(url, payload=payload)
93        return True
 6class TaskTemplate(
 7    Entity,
 8    ResourceLinker,
 9    SkillLinker,
10    FileLinker,
11    StaffLinker,
12    RebateLinker,
13    NoteLinker,
14    TagLinker,
15):
16    """
17    Implementation of the
18    [Task Template](https://projectal.com/docs/latest/#tag/Task-Template) API.
19    """
20
21    _path = "template/task"
22    _name = "task_template"
23    _links = [
24        ResourceLinker,
25        SkillLinker,
26        FileLinker,
27        StaffLinker,
28        RebateLinker,
29        NoteLinker,
30        TagLinker,
31    ]
32
33    def clone(self, holder, entity):
34        url = "/api/template/task/clone?holder={}&reference={}".format(
35            holder["uuId"], self["uuId"]
36        )
37        response = api.post(url, entity)
38        return response["jobClue"]["uuId"]
39
40    @classmethod
41    def create(cls, holder, entity):
42        """Create a Task Template
43
44        `holder`: `uuId` of the owner
45
46        `entity`: The fields of the entity to be created
47        """
48        holder = holder["uuId"] if isinstance(holder, dict) else holder
49        params = "?holder=" + holder
50        return super().create(entity, params)
51
52    @classmethod
53    def list(cls, expand=False, links=None):
54        """Return a list of all entity UUIDs of this type.
55
56        You may pass in `expand=True` to get full Entity objects
57        instead, but be aware this may be very slow if you have
58        thousands of objects.
59
60        If you are expanding the objects, you may further expand
61        the results with `links`.
62        """
63
64        payload = {
65            "name": "List all entities of type {}".format(cls._name.upper()),
66            "type": "msql",
67            "start": 0,
68            "limit": -1,
69            "select": [["PROJECT_TEMPLATE.{}.uuId".format(cls._name.upper())]],
70        }
71        ids = api.query(payload)
72        ids = [id_[0] for id_ in ids]
73        if ids:
74            return cls.get(ids, links=links) if expand else ids
75        return []
76
77    @classmethod
78    def link_predecessor_task(cls, task, predecessor_task):
79        return cls.__plan(task, predecessor_task, "add")
80
81    @classmethod
82    def relink_predecessor_task(cls, task, predecessor_task):
83        return cls.__plan(task, predecessor_task, "update")
84
85    @classmethod
86    def unlink_predecessor_task(cls, task, predecessor_task):
87        return cls.__plan(task, predecessor_task, "delete")
88
89    @classmethod
90    def __plan(cls, from_task, to_task, operation):
91        url = "/api/template/task/plan/task/{}".format(operation)
92        payload = {"uuId": from_task["uuId"], "taskList": [to_task]}
93        api.post(url, payload=payload)
94        return True

Implementation of the Task Template API.

def clone(self, holder, entity):
33    def clone(self, holder, entity):
34        url = "/api/template/task/clone?holder={}&reference={}".format(
35            holder["uuId"], self["uuId"]
36        )
37        response = api.post(url, entity)
38        return response["jobClue"]["uuId"]

Clones an entity and returns its uuId.

Each entity has its own set of required values when cloning. Check the API documentation of that entity for details.

@classmethod
def create(cls, holder, entity):
40    @classmethod
41    def create(cls, holder, entity):
42        """Create a Task Template
43
44        `holder`: `uuId` of the owner
45
46        `entity`: The fields of the entity to be created
47        """
48        holder = holder["uuId"] if isinstance(holder, dict) else holder
49        params = "?holder=" + holder
50        return super().create(entity, params)

Create a Task Template

holder: uuId of the owner

entity: The fields of the entity to be created

@classmethod
def list(cls, expand=False, links=None):
52    @classmethod
53    def list(cls, expand=False, links=None):
54        """Return a list of all entity UUIDs of this type.
55
56        You may pass in `expand=True` to get full Entity objects
57        instead, but be aware this may be very slow if you have
58        thousands of objects.
59
60        If you are expanding the objects, you may further expand
61        the results with `links`.
62        """
63
64        payload = {
65            "name": "List all entities of type {}".format(cls._name.upper()),
66            "type": "msql",
67            "start": 0,
68            "limit": -1,
69            "select": [["PROJECT_TEMPLATE.{}.uuId".format(cls._name.upper())]],
70        }
71        ids = api.query(payload)
72        ids = [id_[0] for id_ in ids]
73        if ids:
74            return cls.get(ids, links=links) if expand else ids
75        return []

Return a list of all entity UUIDs of this type.

You may pass in expand=True to get full Entity objects instead, but be aware this may be very slow if you have thousands of objects.

If you are expanding the objects, you may further expand the results with links.