@@ -77,6 +77,43 @@ def get_all_tasks(self, **kwargs):
77
77
self .project .space .team .id , list_ids = [self .id ], ** kwargs
78
78
)
79
79
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
+
80
117
81
118
class Project (BaseModel ):
82
119
"""project model"""
@@ -197,6 +234,15 @@ def __repr__(self):
197
234
class Task (BaseModel ):
198
235
"""Task object"""
199
236
237
+ class Priority :
238
+ """task priority enum"""
239
+
240
+ NONE = 0
241
+ URGENT = 1
242
+ HIGH = 2
243
+ NORMAL = 3
244
+ LOW = 4
245
+
200
246
def __init__ (self , data , ** kwargs ):
201
247
"""override to parse the data"""
202
248
super (Task , self ).__init__ (data , ** kwargs )
0 commit comments