summaryrefslogtreecommitdiffstats
path: root/kittystore/storm/model.py
diff options
context:
space:
mode:
Diffstat (limited to 'kittystore/storm/model.py')
-rw-r--r--kittystore/storm/model.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/kittystore/storm/model.py b/kittystore/storm/model.py
index 458f2fd..554edfa 100644
--- a/kittystore/storm/model.py
+++ b/kittystore/storm/model.py
@@ -126,13 +126,19 @@ class Thread(object):
self.date_active = date_active
@property
+ def _starting_email_req(self):
+ """ Returns the request to get the starting email.
+ If there are no results with in_reply_to IS NULL, then it's
+ probably a partial import and we don't have the real first email.
+ In this case, use the date.
+ """
+ return self.emails.order_by(Email.in_reply_to != None, Email.date)
+
+ @property
def starting_email(self):
"""Return (and cache) the email starting this thread"""
if self._starting_email is None:
- self._starting_email = self.emails.find(Email.in_reply_to == None).one()
- if self._starting_email is None:
- # probably a partial import, we don't have the real first email
- self._starting_email = self.emails.order_by(Email.date).first()
+ self._starting_email = self._starting_email_req.first()
return self._starting_email
@property
@@ -140,6 +146,16 @@ class Thread(object):
return self.emails.order_by(Desc(Email.date)).first()
@property
+ def subject(self):
+ """Return the subject of this thread"""
+ if self._starting_email is not None:
+ return self.starting_email.subject
+ else:
+ # Don't get the whole message if it's not cached yet (useful for
+ # HyperKitty's thread view).
+ return self._starting_email_req.values(Email.subject).next()
+
+ @property
def participants(self):
"""Set of email senders in this thread"""
p = []