From 3bb830e86c12f8198e0c57026716c4eff1f8e2c6 Mon Sep 17 00:00:00 2001 From: posativ Date: Tue, 16 Oct 2012 19:42:51 +0200 Subject: [PATCH] add mode for comments (normal, pending, deleted) --- isso/comments.py | 21 ++++++++++++++++++++- isso/db.py | 14 +++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/isso/comments.py b/isso/comments.py index 368ce23..481a7f9 100644 --- a/isso/comments.py +++ b/isso/comments.py @@ -3,8 +3,18 @@ from werkzeug.wrappers import Response class Comment(object): + """This class represents a regular comment. It needs at least a text + field, all other fields are optional (or automatically set by the + database driver. - fields = ['text', 'author', 'email', 'website', 'id', 'parent', 'timestamp'] + The field `mode` has a special meaning: + + 0: normal + 1: in moderation queue + 2: deleted + """ + + fields = ['text', 'author', 'email', 'website', 'id', 'parent', 'timestamp', 'mode'] def __init__(self, **kw): @@ -18,6 +28,15 @@ class Comment(object): def json(self): return '' + @property + def pending(self): + return self.mode == 1 + + @property + def deleted(self): + return self.mode == 2 + + def comment(app, environ, request, path, id=None): return Response('', 200) diff --git a/isso/db.py b/isso/db.py index da5cd4c..3faa7f4 100644 --- a/isso/db.py +++ b/isso/db.py @@ -45,16 +45,18 @@ class SQLite(Abstract): fields = [ 'id', 'path', 'timestamp', - 'text', 'author', 'email', 'website', 'parent' + 'text', 'author', 'email', 'website', 'parent', 'mode' ] def initialize(self, conf): + self.dbpath = conf['SQLITE'] + self.mode = 1 if conf.get('MODERATION') else 0 with sqlite3.connect(self.dbpath) as con: sql = ('main.comments (id INTEGER NOT NULL, path VARCHAR(255) NOT NULL,' 'timestamp FLOAT NOT NULL, text VARCHAR, author VARCHAR(64),' - 'email VARCHAR(64), website VARCHAR(64), parent INTEGER,' + 'email VARCHAR(64), website VARCHAR(64), parent INTEGER, mode INTEGER,' 'PRIMARY KEY (id, path))') con.execute("CREATE TABLE IF NOT EXISTS %s;" % sql) @@ -73,15 +75,17 @@ class SQLite(Abstract): def query2comment(self, query): return Comment( text=query[3], author=query[4], email=query[5], website=query[6], - parent=query[7], timestamp=query[2], id=query[0] + parent=query[7], timestamp=query[2], id=query[0], mode=query[8] ) def add(self, path, c): with sqlite3.connect(self.dbpath) as con: keys = ','.join(self.fields) values = ','.join('?'*len(self.fields)) - con.execute('INSERT INTO comments (%s) VALUES (%s);' % (keys, values), - (0, path, time.time(), c.text, c.author, c.email, c.website, c.parent)) + con.execute('INSERT INTO comments (%s) VALUES (%s);' % (keys, values), ( + 0, path, time.time(), c.text, c.author, c.email, c.website, + c.parent, self.mode) + ) def update(self, path, comment): return