MCPcopy Create free account
hub / github.com/O365/python-o365 / save

Method save

O365/tasks.py:305–356  ·  view source on GitHub ↗

Create a new task or update an existing one by checking what values have changed and update them on the server :return: Success / Failure :rtype: bool

(self)

Source from the content-addressed store, hash-verified

303 return bool(response)
304
305 def save(self):
306 """ Create a new task or update an existing one by checking what
307 values have changed and update them on the server
308
309 :return: Success / Failure
310 :rtype: bool
311 """
312
313 if self.task_id:
314 # update task
315 if not self._track_changes:
316 return True # there's nothing to update
317 url = self.build_url(
318 self._endpoints.get('task').format(id=self.task_id))
319 method = self.con.patch
320 data = self.to_api_data(restrict_keys=self._track_changes)
321 else:
322 # new task
323 if self.folder_id:
324 url = self.build_url(
325 self._endpoints.get('task_folder').format(
326 id=self.folder_id))
327 else:
328 url = self.build_url(self._endpoints.get('task_default'))
329 method = self.con.post
330 data = self.to_api_data()
331
332 response = method(url, data=data)
333 if not response:
334 return False
335
336 self._track_changes.clear() # clear the tracked changes
337
338 if not self.task_id:
339 # new task
340 task = response.json()
341
342 self.task_id = task.get(self._cc('id'), None)
343
344 self.__created = task.get(self._cc('createdDateTime'), None)
345 self.__modified = task.get(self._cc('lastModifiedDateTime'), None)
346 self.__completed = task.get(self._cc('Completed'), None)
347
348 self.__created = parse(self.__created).astimezone(
349 self.protocol.timezone) if self.__created else None
350 self.__modified = parse(self.__modified).astimezone(
351 self.protocol.timezone) if self.__modified else None
352 self.__is_completed = task.get(self._cc('status'), None) == 'Completed'
353 else:
354 self.__modified = dt.datetime.now().replace(tzinfo=self.protocol.timezone)
355
356 return True
357
358 def get_body_text(self):
359 """ Parse the body html and returns the body text using bs4

Callers

nothing calls this directly

Calls 6

to_api_dataMethod · 0.95
build_urlMethod · 0.80
jsonMethod · 0.80
_ccMethod · 0.80
getMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected