diff options
Diffstat (limited to 'sphinx/websupport/storage')
-rw-r--r-- | sphinx/websupport/storage/sqlalchemy_db.py | 36 | ||||
-rw-r--r-- | sphinx/websupport/storage/sqlalchemystorage.py | 1 |
2 files changed, 20 insertions, 17 deletions
diff --git a/sphinx/websupport/storage/sqlalchemy_db.py b/sphinx/websupport/storage/sqlalchemy_db.py index dd4bf8822..cbecc03e8 100644 --- a/sphinx/websupport/storage/sqlalchemy_db.py +++ b/sphinx/websupport/storage/sqlalchemy_db.py @@ -98,6 +98,22 @@ class Node(Base): self.source = source +class CommentVote(Base): + """A vote a user has made on a Comment.""" + __tablename__ = db_prefix + 'commentvote' + + username = Column(String(64), primary_key=True) + comment_id = Column(Integer, ForeignKey(db_prefix + 'comments.id'), + primary_key=True) + # -1 if downvoted, +1 if upvoted, 0 if voted then unvoted. + value = Column(Integer, nullable=False) + + def __init__(self, comment_id, username, value): + self.comment_id = comment_id + self.username = username + self.value = value + + class Comment(Base): """An individual Comment being stored.""" __tablename__ = db_prefix + 'comments' @@ -115,6 +131,9 @@ class Comment(Base): node_id = Column(String, ForeignKey(db_prefix + 'nodes.id')) node = relation(Node, backref="comments") + votes = relation(CommentVote, backref="comment", + cascade="all, delete-orphan") + def __init__(self, text, displayed, username, rating, time, proposal, proposal_diff): self.text = text @@ -187,20 +206,3 @@ class Comment(Base): dt = (days, 'day') return '%s %s ago' % dt if dt[0] == 1 else '%s %ss ago' % dt - - -class CommentVote(Base): - """A vote a user has made on a Comment.""" - __tablename__ = db_prefix + 'commentvote' - - username = Column(String(64), primary_key=True) - comment_id = Column(Integer, ForeignKey(db_prefix + 'comments.id'), - primary_key=True) - comment = relation(Comment, backref="votes") - # -1 if downvoted, +1 if upvoted, 0 if voted then unvoted. - value = Column(Integer, nullable=False) - - def __init__(self, comment_id, username, value): - self.comment_id = comment_id - self.username = username - self.value = value diff --git a/sphinx/websupport/storage/sqlalchemystorage.py b/sphinx/websupport/storage/sqlalchemystorage.py index a83c7623f..78991639d 100644 --- a/sphinx/websupport/storage/sqlalchemystorage.py +++ b/sphinx/websupport/storage/sqlalchemystorage.py @@ -81,6 +81,7 @@ class SQLAlchemyStorage(StorageBackend): comment.set_path(node_id, parent_id) session.commit() d = comment.serializable() + d['document'] = comment.node.document session.close() return d |