diff options
author | Georg Brandl <georg@python.org> | 2010-11-21 13:17:11 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-11-21 13:17:11 +0100 |
commit | bdf27419e46bc005de470207fdecd4a07a1c8e57 (patch) | |
tree | f43e39134f78da338e4874bf7af118de80f43776 /sphinx/websupport/storage/sqlalchemystorage.py | |
parent | 69713fb26d028dcbd43708f9bd156edf8ba705b2 (diff) | |
download | sphinx-git-bdf27419e46bc005de470207fdecd4a07a1c8e57.tar.gz |
Support complete comment deletion.
Diffstat (limited to 'sphinx/websupport/storage/sqlalchemystorage.py')
-rw-r--r-- | sphinx/websupport/storage/sqlalchemystorage.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/sphinx/websupport/storage/sqlalchemystorage.py b/sphinx/websupport/storage/sqlalchemystorage.py index 6f13c91b6..a83c7623f 100644 --- a/sphinx/websupport/storage/sqlalchemystorage.py +++ b/sphinx/websupport/storage/sqlalchemystorage.py @@ -88,12 +88,23 @@ class SQLAlchemyStorage(StorageBackend): session = Session() comment = session.query(Comment).\ filter(Comment.id == comment_id).one() - if moderator or comment.username == username: + if moderator: + # moderator mode: delete the comment and all descendants + # find descendants via path + session.query(Comment).filter( + Comment.path.like(comment.path + '.%')).delete(False) + session.delete(comment) + session.commit() + session.close() + return True + elif comment.username == username: + # user mode: do not really delete, but remove text and proposal comment.username = '[deleted]' comment.text = '[deleted]' comment.proposal = '' session.commit() session.close() + return False else: session.close() raise UserNotAuthorizedError() @@ -154,20 +165,16 @@ class SQLAlchemyStorage(StorageBackend): def accept_comment(self, comment_id): session = Session() - - # XXX assignment to "comment" needed? - comment = session.query(Comment).filter( - Comment.id == comment_id).update( - {Comment.displayed: True}) + session.query(Comment).filter(Comment.id == comment_id).update( + {Comment.displayed: True} + ) session.commit() session.close() def reject_comment(self, comment_id): session = Session() - - comment = session.query(Comment).\ - filter(Comment.id == comment_id).one() + comment = session.query(Comment).filter(Comment.id == comment_id).one() session.delete(comment) session.commit() |