mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-09-03 20:52:55 -05:00
added storage package
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
sphinx.websupport.comments
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
sphinx.websupport.storage
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Comments for the websupport package.
|
||||
Storage for the websupport package.
|
||||
|
||||
:copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
@@ -40,7 +40,7 @@ class StorageBackend(object):
|
||||
"""Called when a comment is being added."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_comments(self, parent_id, user_id, moderator):
|
||||
def get_data(self, parent_id, user_id, moderator):
|
||||
"""Called to retrieve all comments for a node."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
sphinx.websupport.comments.db
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
sphinx.websupport.storage.db
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
SQLAlchemy table and mapper definitions used by the
|
||||
:class:`sphinx.websupport.comments.SQLAlchemyStorage`.
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
sphinx.websupport.comments.differ
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
sphinx.websupport.storage.differ
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
A differ for creating an HTML representations of proposal diffs
|
||||
|
||||
+54
-7
@@ -1,9 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
sphinx.websupport.comments.sqlalchemystorage
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
sphinx.websupport.storage.sqlalchemystorage
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
A SQLAlchemy storage backend.
|
||||
An SQLAlchemy storage backend.
|
||||
|
||||
:copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
@@ -12,10 +12,11 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy.orm import aliased
|
||||
from sphinx.websupport.comments import StorageBackend
|
||||
from sphinx.websupport.comments.db import Base, Node, Comment, CommentVote,\
|
||||
from sphinx.websupport.errors import *
|
||||
from sphinx.websupport.storage import StorageBackend
|
||||
from sphinx.websupport.storage.db import Base, Node, Comment, CommentVote,\
|
||||
Session
|
||||
from sphinx.websupport.comments.differ import CombinedHtmlDiff
|
||||
from sphinx.websupport.storage.differ import CombinedHtmlDiff
|
||||
|
||||
class SQLAlchemyStorage(StorageBackend):
|
||||
def __init__(self, engine):
|
||||
@@ -45,6 +46,13 @@ class SQLAlchemyStorage(StorageBackend):
|
||||
node = session.query(Node).filter(Node.id == node_id).one()
|
||||
differ = CombinedHtmlDiff()
|
||||
proposal_diff = differ.make_html(node.source, proposal)
|
||||
elif parent_id:
|
||||
parent = session.query(Comment.displayed).\
|
||||
filter(Comment.id == parent_id).one()
|
||||
if not parent.displayed:
|
||||
raise CommentNotAllowedError(
|
||||
"Can't add child to a parent that is not displayed")
|
||||
proposal_diff = None
|
||||
else:
|
||||
proposal_diff = None
|
||||
|
||||
@@ -58,6 +66,19 @@ class SQLAlchemyStorage(StorageBackend):
|
||||
session.close()
|
||||
return comment
|
||||
|
||||
def delete_comment(self, comment_id, username, moderator):
|
||||
session = Session()
|
||||
comment = session.query(Comment).\
|
||||
filter(Comment.id == comment_id).one()
|
||||
if moderator or comment.username == username:
|
||||
comment.username = '[deleted]'
|
||||
comment.text = '[deleted]'
|
||||
session.commit()
|
||||
session.close()
|
||||
else:
|
||||
session.close()
|
||||
raise UserNotAuthorizedError()
|
||||
|
||||
def get_data(self, node_id, username, moderator):
|
||||
session = Session()
|
||||
node = session.query(Node).filter(Node.id == node_id).one()
|
||||
@@ -81,7 +102,7 @@ class SQLAlchemyStorage(StorageBackend):
|
||||
q = session.query(Comment)
|
||||
|
||||
# Filter out all comments not descending from this node.
|
||||
q = q.filter(Comment.path.like(node_id + '.%'))
|
||||
q = q.filter(Comment.path.like(str(node_id) + '.%'))
|
||||
# Filter out non-displayed comments if this isn't a moderator.
|
||||
if not moderator:
|
||||
q = q.filter(Comment.displayed == True)
|
||||
@@ -129,3 +150,29 @@ class SQLAlchemyStorage(StorageBackend):
|
||||
session.add(vote)
|
||||
session.commit()
|
||||
session.close()
|
||||
|
||||
def update_username(self, old_username, new_username):
|
||||
session = Session()
|
||||
session.query(Comment).filter(Comment.username == old_username).\
|
||||
update({Comment.username: new_username})
|
||||
session.query(CommentVote).\
|
||||
filter(CommentVote.username == old_username).\
|
||||
update({CommentVote.username: new_username})
|
||||
session.commit()
|
||||
session.close()
|
||||
|
||||
def accept_comment(self, comment_id):
|
||||
session = Session()
|
||||
comment = session.query(Comment).\
|
||||
filter(Comment.id == comment_id).one()
|
||||
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()
|
||||
session.delete(comment)
|
||||
session.commit()
|
||||
session.close()
|
||||
Reference in New Issue
Block a user