Save proposed changes

This commit is contained in:
Jacob Mason 2010-07-25 22:37:53 -05:00
parent 022b229c36
commit 3a32d12bf8
4 changed files with 17 additions and 47 deletions

View File

@ -146,10 +146,11 @@ class WebSupport(object):
return document
def get_comments(self, node_id, user_id=None):
"""Get the comments associated with `node_id`. If `user_id` is
given vote information will be included with the returned comments.
The default CommentBackend returns a list of dicts. Each dict
represents a comment, and has the following items:
"""Get the comments and source associated with `node_id`. If
`user_id` is given vote information will be included with the
returned comments. The default CommentBackend returns dict with
two keys, *source*, and *comments*. *comments* is a list of
dicts that represent a comment, each having the following items:
============ ======================================================
Key Contents
@ -181,7 +182,7 @@ class WebSupport(object):
return self.storage.get_comments(node_id, user_id)
def add_comment(self, parent_id, text, displayed=True, username=None,
rating=0, time=None):
rating=0, time=None, proposal=None):
"""Add a comment to a node or another comment. `parent_id` will have
a one letter prefix, distinguishing between node parents and
comment parents, 'c' and 's' respectively. This function will
@ -203,7 +204,7 @@ class WebSupport(object):
:param time: the time the comment was created, defaults to now.
"""
return self.storage.add_comment(parent_id, text, displayed,
username, rating, time)
username, rating, time, proposal)
def get_proposals(self, node_id, user_id=None):
return self.storage.get_proposals(node_id, user_id)

View File

@ -25,8 +25,8 @@ class StorageBackend(object):
"""
pass
def add_comment(self, parent_id, text, displayed, username,
rating, time):
def add_comment(self, parent_id, text, displayed,
username, rating, time, proposal):
"""Called when a comment is being added."""
raise NotImplementedError()
@ -34,12 +34,5 @@ class StorageBackend(object):
"""Called to retrieve all comments for a node."""
raise NotImplementedError()
def add_proposal(self, parent_id, text, displayed, username,
rating, time):
raise NotImplementedError()
def get_proposals(self, parent_id):
raise NotImplementedError()
def process_vote(self, comment_id, user_id, value):
raise NotImplementedError()

View File

@ -46,7 +46,7 @@ class Comment(Base):
parent = relation('Comment', backref='children', remote_side=[id])
def __init__(self, text, displayed, username, rating, time,
node=None, parent=None, proposal=None):
proposal, node=None, parent=None):
self.text = text
self.displayed = displayed
self.username = username

View File

@ -24,7 +24,7 @@ class SQLAlchemyStorage(StorageBackend):
self.build_session.close()
def add_comment(self, parent_id, text, displayed,
username, rating, time):
username, rating, time, proposal):
time = time or datetime.now()
session = Session()
@ -33,11 +33,11 @@ class SQLAlchemyStorage(StorageBackend):
if parent_id[0] == 's':
node = session.query(Node).filter(Node.id == id).first()
comment = Comment(text, displayed, username, rating,
time, node=node)
time, proposal, node=node)
elif parent_id[0] == 'c':
parent = session.query(Comment).filter(Comment.id == id).first()
comment = Comment(text, displayed, username, rating,
time, parent=parent)
time,proposal, parent=parent)
session.add(comment)
session.commit()
@ -49,35 +49,11 @@ class SQLAlchemyStorage(StorageBackend):
parent_id = parent_id[1:]
session = Session()
node = session.query(Node).filter(Node.id == parent_id).first()
comments = []
for comment in node.comments:
comments.append(comment.serializable(user_id))
data = {'source': node.source,
'comments': [comment.serializable(user_id)
for comment in node.comments]}
session.close()
return comments
def add_proposal(self, parent_id, text, displayed, username,
rating, time):
time = time or datetime.now()
session = Session()
node = session.query(Node).filter(Node.id == parent_id).first()
proposal= Proposal(text, displayed, username, rating, time, node)
session.add(proposal)
session.commit()
session.close()
return proposal
def get_proposals(self, parent_id):
session = Session()
node = session.query(Node).filter(Node.id == parent_id).first()
proposals = []
# TODO
return proposals
return data
def process_vote(self, comment_id, user_id, value):
session = Session()