def remove_tag(self, tag, execute_action=False): """Remove the given Tag instance from this thread. Does nothing if the tag isn't present. Contains extra logic for validating input and triggering dependent changes. Callers should use this method instead of directly calling Thread.tags.discard(tag). Parameters ---------- tag: Tag instance execute_action: bool True if removing the tag should trigger a syncback action. """ if tag not in self.tags: return self.tags.remove(tag) if execute_action: schedule_action_for_tag(tag.public_id, self, object_session(self), tag_added=False) # Add or remove dependent tags. inbox_tag = self.namespace.tags['inbox'] archive_tag = self.namespace.tags['archive'] unread_tag = self.namespace.tags['unread'] unseen_tag = self.namespace.tags['unseen'] if tag == unread_tag: # Remove the 'unseen' tag when the unread tag is removed. self.tags.discard(unseen_tag) if tag == inbox_tag: self.tags.add(archive_tag) elif tag == archive_tag: self.tags.add(inbox_tag)
def apply_tag(self, tag, execute_action=False): """Add the given Tag instance to this thread. Does nothing if the tag is already applied. Contains extra logic for validating input and triggering dependent changes. Callers should use this method instead of directly calling Thread.tags.add(tag). Parameters ---------- tag: Tag instance execute_action: bool True if adding the tag should trigger a syncback action. """ if tag in self.tags: return self.tags.add(tag) if execute_action: schedule_action_for_tag(tag.public_id, self, object_session(self), tag_added=True) # Add or remove dependent tags. # TODO(emfree) this should eventually live in its own utility function. inbox_tag = self.namespace.tags['inbox'] archive_tag = self.namespace.tags['archive'] sent_tag = self.namespace.tags['sent'] drafts_tag = self.namespace.tags['drafts'] if tag == inbox_tag: self.tags.discard(archive_tag) elif tag == archive_tag: self.tags.discard(inbox_tag) elif tag == sent_tag: self.tags.discard(drafts_tag)
def apply_tag(self, tag, execute_action=False): """ Add the given Tag instance to this thread. Does nothing if the tag is already applied. Contains extra logic for validating input and triggering dependent changes. Callers should use this method instead of directly calling Thread.tags.add(tag). Parameters ---------- tag: Tag instance execute_action: bool True if adding the tag should trigger a syncback action. """ if tag not in self.tags: self.tags.add(tag) if execute_action: schedule_action_for_tag(tag.public_id, self, object_session(self), tag_added=True) # Add or remove dependent tags. inbox_tag = self.namespace.tags['inbox'] archive_tag = self.namespace.tags['archive'] sent_tag = self.namespace.tags['sent'] drafts_tag = self.namespace.tags['drafts'] spam_tag = self.namespace.tags['spam'] trash_tag = self.namespace.tags['trash'] if tag == inbox_tag: self.tags.discard(archive_tag) elif tag == archive_tag: self.tags.discard(inbox_tag) elif tag == sent_tag: self.tags.discard(drafts_tag) elif tag == spam_tag: self.tags.discard(inbox_tag) elif tag == trash_tag: self.tags.discard(inbox_tag) if execute_action: unread_tag = self.namespace.tags['unread'] if tag == unread_tag: for message in self.messages: message.is_read = False
def apply_tag(self, tag, execute_action=False): """ Add the given Tag instance to this thread. Does nothing if the tag is already applied. Contains extra logic for validating input and triggering dependent changes. Callers should use this method instead of directly calling Thread.tags.add(tag). Parameters ---------- tag: Tag instance execute_action: bool True if adding the tag should trigger a syncback action. """ if tag not in self.tags: self.tags.add(tag) if execute_action: schedule_action_for_tag(tag.public_id, self, object_session(self), tag_added=True) # Add or remove dependent tags. inbox_tag = self.namespace.tags['inbox'] archive_tag = self.namespace.tags['archive'] sent_tag = self.namespace.tags['sent'] drafts_tag = self.namespace.tags['drafts'] spam_tag = self.namespace.tags['spam'] trash_tag = self.namespace.tags['trash'] if tag == inbox_tag: self.tags.discard(archive_tag) elif tag == archive_tag: self.tags.discard(inbox_tag) elif tag == sent_tag: self.tags.discard(drafts_tag) elif tag == spam_tag: self.tags.discard(inbox_tag) elif tag == trash_tag: self.tags.discard(inbox_tag) if execute_action: unread_tag = self.namespace.tags['unread'] if tag == unread_tag: for message in self.messages: message.is_read = False