summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurélien Bompard <aurelien@bompard.org>2012-10-05 15:02:31 +0200
committerAurélien Bompard <aurelien@bompard.org>2012-10-05 15:02:31 +0200
commitf231e1c86cea3ede1eceaa873d1a41e4e35277f9 (patch)
treeedfbb822b39f9ee2f8f5b207ebc76cad79689d77
parent7dd3941e8551d0013c9229e8a74ec64578eeb7b7 (diff)
downloadkittystore-f231e1c86cea3ede1eceaa873d1a41e4e35277f9.tar.gz
kittystore-f231e1c86cea3ede1eceaa873d1a41e4e35277f9.tar.xz
kittystore-f231e1c86cea3ede1eceaa873d1a41e4e35277f9.zip
Store the list display name in the DB
-rw-r--r--kittystore/storm/model.py1
-rw-r--r--kittystore/storm/schema/__init__.py2
-rw-r--r--kittystore/storm/store.py16
-rw-r--r--kittystore/test/test_storm_store.py11
4 files changed, 25 insertions, 5 deletions
diff --git a/kittystore/storm/model.py b/kittystore/storm/model.py
index 00f3962..fc89e93 100644
--- a/kittystore/storm/model.py
+++ b/kittystore/storm/model.py
@@ -37,6 +37,7 @@ class List(object):
__storm_table__ = "list"
name = Unicode(primary=True)
+ display_name = Unicode()
def __init__(self, name):
self.name = unicode(name)
diff --git a/kittystore/storm/schema/__init__.py b/kittystore/storm/schema/__init__.py
index c7d3f75..e32085e 100644
--- a/kittystore/storm/schema/__init__.py
+++ b/kittystore/storm/schema/__init__.py
@@ -6,6 +6,7 @@ CREATES = {
"sqlite": [ """
CREATE TABLE "list" (
name VARCHAR(255) NOT NULL,
+ display_name TEXT,
PRIMARY KEY (name)
);""", """
CREATE TABLE "email" (
@@ -44,6 +45,7 @@ CREATES = {
"postgres": [ """
CREATE TABLE "list" (
name VARCHAR(255) NOT NULL,
+ display_name TEXT,
PRIMARY KEY (name)
);""", """
CREATE TABLE "email" (
diff --git a/kittystore/storm/store.py b/kittystore/storm/store.py
index c5cad84..b1d584e 100644
--- a/kittystore/storm/store.py
+++ b/kittystore/storm/store.py
@@ -65,7 +65,7 @@ class StormStore(object):
# Not sure this is useful: a message should always be in a list
raise NotImplementedError
- def add_to_list(self, list_name, message):
+ def add_to_list(self, mlist, message):
"""Add the message to a specific list of the store.
:param list_name: The fully qualified list name to which the
@@ -80,12 +80,14 @@ class StormStore(object):
The storage service is also allowed to raise this exception
if it find, but disallows collisions.
"""
- list_name = unicode(list_name)
+ list_name = unicode(mlist.fqdn_listname)
# Create the list if it does not exist
list_is_in_db = self.db.find(List,
List.name == list_name).count()
if not list_is_in_db:
- self.db.add(List(list_name))
+ l = List(list_name)
+ l.display_name = mlist.display_name
+ self.db.add(l)
if not message.has_key("Message-Id"):
raise ValueError("No 'Message-Id' header in email", message)
msg_id = unicode(unquote(message['Message-Id']))
@@ -375,6 +377,14 @@ class StormStore(object):
)).config(distinct=True)
return list(participants)
+ def get_list(self, list_name):
+ """ Return the list object for a mailing list name.
+
+ :arg list_name, name of the mailing list to retrieve.
+ """
+ return self.db.find(List, List.name == unicode(list_name)).one()
+
+
# Attachments
def add_attachment(self, mlist, msg_id, counter, name, content_type,
diff --git a/kittystore/test/test_storm_store.py b/kittystore/test/test_storm_store.py
index b917afc..863928b 100644
--- a/kittystore/test/test_storm_store.py
+++ b/kittystore/test/test_storm_store.py
@@ -10,6 +10,12 @@ from kittystore.storm import get_storm_store
from kittystore.storm.model import Email
from kittystore.test import get_test_file
+
+class FakeList(object):
+ def __init__(self, name):
+ self.fqdn_listname = name
+
+
class TestSAStore(unittest.TestCase):
def setUp(self):
@@ -20,7 +26,8 @@ class TestSAStore(unittest.TestCase):
def test_no_message_id(self):
msg = email.message.Message()
- self.assertRaises(ValueError, self.store.add_to_list, "example-list", msg)
+ self.assertRaises(ValueError, self.store.add_to_list,
+ FakeList("example-list"), msg)
def test_no_date(self):
msg = email.message.Message()
@@ -29,7 +36,7 @@ class TestSAStore(unittest.TestCase):
msg.set_payload("Dummy message")
now = datetime.datetime.now()
try:
- self.store.add_to_list("example-list", msg)
+ self.store.add_to_list(FakeList("example-list"), msg)
except IntegrityError, e:
self.fail(e)
stored_msg = self.store.db.find(Email).one()