From 7420e6a130a27b54fe2623ae9c05dcd34e76bad6 Mon Sep 17 00:00:00 2001 From: posativ Date: Wed, 24 Oct 2012 20:38:07 +0200 Subject: [PATCH] add path to comment class --- isso/db.py | 10 +++++----- isso/models.py | 2 +- specs/test_db.py | 2 ++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/isso/db.py b/isso/db.py index e42e1b5..fe7cac8 100644 --- a/isso/db.py +++ b/isso/db.py @@ -75,7 +75,7 @@ class SQLite(Abstract): post) are ordered by that id.""" fields = [ - 'id', 'path', 'created', 'modified', + 'path', 'id', 'created', 'modified', 'text', 'author', 'email', 'website', 'parent', 'mode' ] @@ -85,7 +85,7 @@ class SQLite(Abstract): self.mode = 2 if app.MODERATION else 1 with sqlite3.connect(self.dbpath) as con: - sql = ('main.comments (id INTEGER NOT NULL, path VARCHAR(255) NOT NULL,' + sql = ('main.comments (path VARCHAR(255) NOT NULL, id INTEGER NOT NULL,' 'created FLOAT NOT NULL, modified FLOAT, text VARCHAR,' 'author VARCHAR(64), email VARCHAR(64), website VARCHAR(64),' 'parent INTEGER, mode INTEGER, PRIMARY KEY (id, path))') @@ -105,8 +105,8 @@ class SQLite(Abstract): return None return Comment( - text=query[4], author=query[5], email=query[6], website=query[7], - parent=query[8], mode=query[9], id=query[0], created=query[2], modified=query[3] + text=query[4], author=query[5], email=query[6], website=query[7], parent=query[8], + path=query[0], id=query[1], created=query[2], modified=query[3], mode=query[9], ) def add(self, path, c): @@ -114,7 +114,7 @@ class SQLite(Abstract): keys = ','.join(self.fields) values = ','.join('?' * len(self.fields)) con.execute('INSERT INTO comments (%s) VALUES (%s);' % (keys, values), ( - 0, path, c.created, c.modified, c.text, c.author, c.email, c.website, + path, 0, c.created, c.modified, c.text, c.author, c.email, c.website, c.parent, self.mode) ) diff --git a/isso/models.py b/isso/models.py index e8d10a4..457b7ef 100644 --- a/isso/models.py +++ b/isso/models.py @@ -22,7 +22,7 @@ class Comment(object): normal and queued using MODE=3. """ - protected = ['id', 'mode', 'created', 'modified'] + protected = ['path', 'id', 'mode', 'created', 'modified'] fields = ['text', 'author', 'email', 'website', 'parent'] def __init__(self, **kw): diff --git a/specs/test_db.py b/specs/test_db.py index dc21920..c539713 100644 --- a/specs/test_db.py +++ b/specs/test_db.py @@ -37,6 +37,7 @@ class TestSQLite(unittest.TestCase): rv = list(self.db.retrieve('/')) assert rv[0].id == 1 + assert rv[0].path == '/' assert rv[0].text == 'Foo' assert rv[1].id == 2 @@ -44,6 +45,7 @@ class TestSQLite(unittest.TestCase): rv = list(self.db.retrieve('/path/')) assert rv[0].id == 1 + assert rv[0].path == '/path/' assert rv[0].text == 'Baz' def test_add_return(self):