add path to comment class

This commit is contained in:
posativ 2012-10-24 20:38:07 +02:00
parent 05b77f99fe
commit 7420e6a130
3 changed files with 8 additions and 6 deletions

View File

@ -75,7 +75,7 @@ class SQLite(Abstract):
post) are ordered by that id.""" post) are ordered by that id."""
fields = [ fields = [
'id', 'path', 'created', 'modified', 'path', 'id', 'created', 'modified',
'text', 'author', 'email', 'website', 'parent', 'mode' 'text', 'author', 'email', 'website', 'parent', 'mode'
] ]
@ -85,7 +85,7 @@ class SQLite(Abstract):
self.mode = 2 if app.MODERATION else 1 self.mode = 2 if app.MODERATION else 1
with sqlite3.connect(self.dbpath) as con: 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,' 'created FLOAT NOT NULL, modified FLOAT, text VARCHAR,'
'author VARCHAR(64), email VARCHAR(64), website VARCHAR(64),' 'author VARCHAR(64), email VARCHAR(64), website VARCHAR(64),'
'parent INTEGER, mode INTEGER, PRIMARY KEY (id, path))') 'parent INTEGER, mode INTEGER, PRIMARY KEY (id, path))')
@ -105,8 +105,8 @@ class SQLite(Abstract):
return None return None
return Comment( return Comment(
text=query[4], author=query[5], email=query[6], website=query[7], text=query[4], author=query[5], email=query[6], website=query[7], parent=query[8],
parent=query[8], mode=query[9], id=query[0], created=query[2], modified=query[3] path=query[0], id=query[1], created=query[2], modified=query[3], mode=query[9],
) )
def add(self, path, c): def add(self, path, c):
@ -114,7 +114,7 @@ class SQLite(Abstract):
keys = ','.join(self.fields) keys = ','.join(self.fields)
values = ','.join('?' * len(self.fields)) values = ','.join('?' * len(self.fields))
con.execute('INSERT INTO comments (%s) VALUES (%s);' % (keys, values), ( 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) c.parent, self.mode)
) )

View File

@ -22,7 +22,7 @@ class Comment(object):
normal and queued using MODE=3. normal and queued using MODE=3.
""" """
protected = ['id', 'mode', 'created', 'modified'] protected = ['path', 'id', 'mode', 'created', 'modified']
fields = ['text', 'author', 'email', 'website', 'parent'] fields = ['text', 'author', 'email', 'website', 'parent']
def __init__(self, **kw): def __init__(self, **kw):

View File

@ -37,6 +37,7 @@ class TestSQLite(unittest.TestCase):
rv = list(self.db.retrieve('/')) rv = list(self.db.retrieve('/'))
assert rv[0].id == 1 assert rv[0].id == 1
assert rv[0].path == '/'
assert rv[0].text == 'Foo' assert rv[0].text == 'Foo'
assert rv[1].id == 2 assert rv[1].id == 2
@ -44,6 +45,7 @@ class TestSQLite(unittest.TestCase):
rv = list(self.db.retrieve('/path/')) rv = list(self.db.retrieve('/path/'))
assert rv[0].id == 1 assert rv[0].id == 1
assert rv[0].path == '/path/'
assert rv[0].text == 'Baz' assert rv[0].text == 'Baz'
def test_add_return(self): def test_add_return(self):