Coretex
base.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 datetime import datetime
20 
21 from .project_type import ProjectType
22 from ..utils import isEntityNameValid
23 from ...codable import KeyDescriptor
24 from ...networking import NetworkObject
25 
26 
27 class BaseObject(NetworkObject):
28 
29  """
30  Represents the base class for Project/Task objects from Coretex.ai
31 
32  Properties
33  ----------
34  name : str
35  name of object
36  description : Optional[str]
37  description of object
38  createdOn : datetime
39  date of creation of object
40  createdById : str
41  id of user that created object
42  projectType : ProjectType
43  project type of created object
44  """
45 
46  name: str
47  description: Optional[str]
48  createdOn: datetime
49  createdById: str
50  projectType: ProjectType
51 
52  @classmethod
53  def _endpoint(cls) -> str:
54  return "project"
55 
56  @classmethod
57  def _keyDescriptors(cls) -> Dict[str, KeyDescriptor]:
58  descriptors = super()._keyDescriptors()
59  descriptors["projectType"] = KeyDescriptor("project_task", ProjectType)
60 
61  return descriptors
62 
63  def rename(self, name: str) -> bool:
64  """
65  Renames the Project/Task
66 
67  Parameters
68  ----------
69  name : str
70  new name
71 
72  Returns
73  -------
74  bool -> True if Project/Task was renamed, False if Project/Task was not renamed
75  """
76 
77  if not isEntityNameValid(name):
78  raise ValueError(">> [Coretex] Object name is invalid. Requirements: alphanumeric characters (\"a-z\", and \"0-9\") and dash (\"-\") with length between 3 to 50")
79 
80  if self.namename == name:
81  return False
82 
83  success = self.update(name = name)
84 
85  if success:
86  self.namename = name
87 
88  return success
89 
90  def updateDescription(self, description: str) -> bool:
91  """
92  Updates the Project/Task's description
93 
94  Parameters
95  ----------
96  description : str
97  new description
98 
99  Returns
100  bool -> True if Project/Task's description was updated,
101  False if Project/Task's description was not updated
102  """
103 
104  if self.descriptiondescription == description:
105  return False
106 
107  success = self.update(description = description)
108  if success:
109  self.descriptiondescription = description
110 
111  return success
bool updateDescription(self, str description)
Definition: base.py:90
bool rename(self, str name)
Definition: base.py:63