Skip to content

Commit 685eecd

Browse files
committed
[Feature]: adding basic support for creating tasks
1 parent 701a23a commit 685eecd

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

pyclickup/globals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55

6-
__version__ = "0.1.0"
6+
__version__ = "0.1.1"
77

88

99
LIBRARY = "pyclickup"

pyclickup/models/__init__.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,43 @@ def get_all_tasks(self, **kwargs):
7777
self.project.space.team.id, list_ids=[self.id], **kwargs
7878
)
7979

80+
def create_task(
81+
self,
82+
name, # string
83+
content="", # optional, but nice
84+
assignees=None, # list of User objects, or int IDs
85+
status="Open", # needs to match your given statuses for the list
86+
priority=0, # default to no priority (0). check Task class for enum
87+
due_date=None, # integer posix time, or python datetime
88+
):
89+
"""
90+
creates a task within this list, returning the id of the task.
91+
92+
unfortunately right now, there is no way to retreive a task by id
93+
this will return the ID of the newly created task,
94+
but you'll need to re-query the list for tasks to get the task object
95+
"""
96+
task_data = {"name": name, "content": content, "status": status}
97+
98+
if assignees and isinstance(list, assignees):
99+
if isinstance(User, assignees[0]):
100+
task_data["assignees"] = [x.id for x in assignees]
101+
elif isinstance(int, assignees[0]):
102+
task_data["assignees"] = assignees
103+
104+
if due_date:
105+
task_data["due_date"] = (
106+
due_date if isinstance(due_date, int) else datetime_to_ts(due_date)
107+
)
108+
109+
if priority > 0:
110+
task_data["priority"] = priority
111+
112+
new_task_call = self._client.post(
113+
"list/{}/task".format(self.id), data=task_data
114+
)
115+
return new_task_call["id"]
116+
80117

81118
class Project(BaseModel):
82119
"""project model"""
@@ -197,6 +234,15 @@ def __repr__(self):
197234
class Task(BaseModel):
198235
"""Task object"""
199236

237+
class Priority:
238+
"""task priority enum"""
239+
240+
NONE = 0
241+
URGENT = 1
242+
HIGH = 2
243+
NORMAL = 3
244+
LOW = 4
245+
200246
def __init__(self, data, **kwargs):
201247
"""override to parse the data"""
202248
super(Task, self).__init__(data, **kwargs)

0 commit comments

Comments
 (0)