Coretex
task.py
1 # Copyright (C) 2023 Coretex LLC
2 
3 # This file is part of Coretex.ai
4 
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
9 
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
14 
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 
18 from typing import Optional, Dict
19 from typing_extensions import Self
20 
21 from .base import BaseObject
22 from ..utils import isEntityNameValid
23 from ...codable import KeyDescriptor
24 
25 
27 
28  """
29  Represents the task entity from Coretex.ai\n
30  Contains properties that describe the task
31  """
32 
33  isDefault: bool
34  taskId: int
35 
36  @classmethod
37  def _keyDescriptors(cls) -> Dict[str, KeyDescriptor]:
38  descriptors = super()._keyDescriptors()
39  descriptors["taskId"] = KeyDescriptor("parentId")
40 
41  return descriptors
42 
43  @classmethod
44  def createTask(cls, name: str, projectId: int, description: Optional[str]=None) -> Optional[Self]:
45  """
46  Creates a new task with the provided name and description
47  Task is added to the project with provided project id
48 
49  Parameters
50  ----------
51  name : str
52  task name
53  projectId : int
54  project id the task belongs to
55  description : Optional[str]
56  task description
57 
58  Returns
59  -------
60  Optional[Self] -> The created task object
61 
62  Example
63  -------
64  >>> from coretex import Task
65  \b
66  >>> dummyTask = Task.createTask(
67  name = "dummyTask",
68  projectId = 23,
69  description = "This is dummy task"
70  )
71  >>> if dummyTask is None:
72  print("Failed to create task")
73  """
74 
75  if not isEntityNameValid(name):
76  raise ValueError(">> [Coretex] Task name is invalid. Requirements: alphanumeric characters (\"a-z\", and \"0-9\") and dash (\"-\") with length between 3 to 50")
77 
78  return cls.create(
79  name = name,
80  parent_id = projectId,
81  description = description
82  )
Optional[Self] createTask(cls, str name, int projectId, Optional[str] description=None)
Definition: task.py:44