def set_task(self, task): """ This function is called from GTG core whenever a task should be saved, either because it's a new one or it has been modified. This function will look into the loaded XML object if the task is present, and if it's not, it will create it. Then, it will save the task data in the XML object. @param task: the task object to save """ tid = task.get_id() # We create an XML representation of the task t_xml = taskxml.task_to_xml(self.doc, task) # we find if the task exists in the XML treenode. existing = None for node in self.xmlproj.childNodes: if node.nodeName == TASK_NODE and node.getAttribute("id") == tid: existing = node modified = False # We then replace the existing node if existing and t_xml: # We will write only if the task has changed if t_xml.toxml() != existing.toxml(): self.xmlproj.replaceChild(t_xml, existing) modified = True # If the node doesn't exist, we create it else: self.xmlproj.appendChild(t_xml) modified = True # if the XML object has changed, we save it to file if modified and self._parameters["path"] and self.doc: cleanxml.savexml(self.get_path(), self.doc)
def set_task(self, task): """ Propagate a change in local tasks into server """ if self._parameters["state"] != "online": return sync_tags = self._xmpp.get_synchronized_tags() tags = task.get_tags_name() tag_overlap = set(sync_tags) & set(tags) if not tag_overlap: return if task.get_id() in self._changed_remotely: self._changed_remotely.remove(task.get_id()) return Log.info("GTG --set--> PubSub: [%s] '%s'" % (task.get_id(), task.get_title())) doc = xml.dom.minidom.parseString("<task></task>") task_id = task.get_id() task_xml = task_to_xml(doc, task).toxml() tags = task.get_tags_name() self._xmpp.set_task(task_id, tags, task_xml) self._sync_tasks.add(task_id) self._changed_locally.add(task_id)