From 3b96d9f431cff58dbcf6dad403a3edb298d48713 Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Thu, 18 Jul 2013 13:49:50 +0200 Subject: Add methods to attach an email to a thread and to delete a thread --- kittystore/storm/model.py | 1 + kittystore/storm/store.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/kittystore/storm/model.py b/kittystore/storm/model.py index 329488c..90cbe18 100644 --- a/kittystore/storm/model.py +++ b/kittystore/storm/model.py @@ -232,6 +232,7 @@ class Thread(Storm): if category is None: category = Category(name) store.add(category) + store.flush() self.category_id = category.id category = property(_get_category, _set_category) diff --git a/kittystore/storm/store.py b/kittystore/storm/store.py index 542fd5e..99d303b 100644 --- a/kittystore/storm/store.py +++ b/kittystore/storm/store.py @@ -165,6 +165,18 @@ class StormStore(object): self.search_index.add(email) return email.message_id_hash + def attach_to_thread(self, email, thread): + """Attach an email to an existing thread""" + if email.date <= thread.starting_email.date: + raise ValueError("Can't attach emails older than the first " + "email in a thread") + email.thread_id = thread.thread_id + email.in_reply_to = thread.starting_email.message_id + if email.date > thread.date_active: + thread.date_active = email.date + compute_thread_order_and_depth(thread) + self.flush() + def delete_message(self, message_id): """Remove the given message from the store. @@ -467,6 +479,18 @@ class StormStore(object): prev_thread = None return (prev_thread, next_thread) + def delete_thread(self, list_name, thread_id): + """ Delete the specified thread. + + :param list_name: The name of the mailing list containing this thread + :param thread_id: The thread_id as used in the web-pages. Used here to + uniquely identify the thread in the database. + """ + self.db.find(Thread, And( + Thread.list_name == unicode(list_name), + Thread.thread_id == unicode(thread_id) + )).remove() + def get_list(self, list_name): """ Return the list object for a mailing list name. -- cgit