Commits

Georg Brandl committed d7d60c7

Fix deletion of comments with votes.

Comments (0)

Files changed (2)

sphinx/websupport/storage/sqlalchemy_db.py

         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'
     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
             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

sphinx/websupport/storage/sqlalchemystorage.py

         comment.set_path(node_id, parent_id)
         session.commit()
         d = comment.serializable()
+        d['document'] = comment.node.document
         session.close()
         return d
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.