Remove trailing whitespace

This commit is contained in:
Daniel Neuhäuser 2010-07-25 19:50:20 +02:00
parent 19042aaf94
commit d718363908
6 changed files with 30 additions and 31 deletions

View File

@ -44,7 +44,7 @@ class WebSupport(object):
self._init_search(search)
self._init_storage(storage)
def _init_storage(self, storage):
if isinstance(storage, StorageBackend):
self.storage = storage
@ -58,7 +58,7 @@ class WebSupport(object):
ensuredir(path.dirname(db_path))
engine = create_engine('sqlite:///%s' % db_path)
self.storage = SQLAlchemyStorage(engine)
def _init_templating(self):
import sphinx
template_path = path.join(path.dirname(sphinx.__file__),
@ -71,7 +71,7 @@ class WebSupport(object):
self.search = search
else:
mod, cls = search_adapters[search]
search_class = getattr(__import__('sphinx.websupport.search.' + mod,
search_class = getattr(__import__('sphinx.websupport.search.' + mod,
None, None, [cls]), cls)
search_path = path.join(self.outdir, 'search')
self.search = search_class(search_path)
@ -202,15 +202,15 @@ class WebSupport(object):
:param rating: the starting rating of the comment, defaults to 0.
:param time: the time the comment was created, defaults to now.
"""
return self.storage.add_comment(parent_id, text, displayed,
return self.storage.add_comment(parent_id, text, displayed,
username, rating, time)
def get_proposals(self, node_id, user_id=None):
return self.storage.get_proposals(node_id, user_id)
def add_proposal(self, parent_id, text, displayed=True, username=None,
rating=0, time=None):
return self.storage.add_proposal(parent_id, text, displayed,
return self.storage.add_proposal(parent_id, text, displayed,
username, rating, time)
def process_vote(self, comment_id, user_id, value):

View File

@ -18,14 +18,14 @@ class StorageBackend(object):
`treeloc` is for future use.
"""
raise NotImplementedError()
def post_build(self):
"""Called after a build has completed. Use this to finalize the
addition of nodes if needed.
"""
pass
def add_comment(self, parent_id, text, displayed, username,
def add_comment(self, parent_id, text, displayed, username,
rating, time):
"""Called when a comment is being added."""
raise NotImplementedError()
@ -34,7 +34,7 @@ class StorageBackend(object):
"""Called to retrieve all comments for a node."""
raise NotImplementedError()
def add_proposal(self, parent_id, text, displayed, username,
def add_proposal(self, parent_id, text, displayed, username,
rating, time):
raise NotImplementedError()

View File

@ -15,13 +15,13 @@ db_prefix = 'sphinx_'
class Node(Base):
"""Data about a Node in a doctree."""
__tablename__ = db_prefix + 'nodes'
id = Column(Integer, primary_key=True)
document = Column(String(256), nullable=False)
line = Column(Integer)
source = Column(Text, nullable=False)
treeloc = Column(String(32), nullable=False)
def __init__(self, document, line, source, treeloc):
self.document = document
self.line = line
@ -44,7 +44,7 @@ class Comment(Base):
parent_id = Column(Integer, ForeignKey(db_prefix + 'comments.id'))
parent = relation('Comment', backref='children', remote_side=[id])
def __init__(self, text, displayed, username, rating, time,
def __init__(self, text, displayed, username, rating, time,
node=None, parent=None):
self.text = text
self.displayed = displayed
@ -84,7 +84,7 @@ class Comment(Base):
'vote': vote or 0,
'node': self.node.id if self.node else None,
'parent': self.parent.id if self.parent else None,
'children': [child.serializable(user_id)
'children': [child.serializable(user_id)
for child in self.children]}
def pretty_delta(self, delta):
@ -99,7 +99,7 @@ class Comment(Base):
dt = (days, 'day')
return '%s %s ago' % dt if dt[0] == 1 else '%s %ss ago' % dt
class CommentVote(Base):
__tablename__ = db_prefix + 'commentvote'
@ -136,7 +136,7 @@ class Proposal(Base):
self.rating = rating
self.time = time
self.node = node
class ProposalVote(Base):
__tablename__ = db_prefix + 'proposalvote'

View File

@ -23,28 +23,28 @@ class SQLAlchemyStorage(StorageBackend):
self.build_session.commit()
self.build_session.close()
def add_comment(self, parent_id, text, displayed,
def add_comment(self, parent_id, text, displayed,
username, rating, time):
time = time or datetime.now()
session = Session()
id = parent_id[1:]
if parent_id[0] == 's':
node = session.query(Node).filter(Node.id == id).first()
comment = Comment(text, displayed, username, rating,
comment = Comment(text, displayed, username, rating,
time, node=node)
elif parent_id[0] == 'c':
parent = session.query(Comment).filter(Comment.id == id).first()
comment = Comment(text, displayed, username, rating,
comment = Comment(text, displayed, username, rating,
time, parent=parent)
session.add(comment)
session.commit()
comment = comment.serializable()
session.close()
return comment
def get_comments(self, parent_id, user_id):
parent_id = parent_id[1:]
session = Session()
@ -56,15 +56,15 @@ class SQLAlchemyStorage(StorageBackend):
session.close()
return comments
def add_proposal(self, parent_id, text, displayed, username,
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()
@ -84,7 +84,7 @@ class SQLAlchemyStorage(StorageBackend):
vote = session.query(CommentVote).filter(
CommentVote.comment_id == comment_id).filter(
CommentVote.user_id == user_id).first()
comment = session.query(Comment).filter(
Comment.id == comment_id).first()
@ -97,4 +97,3 @@ class SQLAlchemyStorage(StorageBackend):
session.add(vote)
session.commit()
session.close()

View File

@ -40,10 +40,10 @@ class WhooshSearch(BaseSearch):
def finish_indexing(self):
self.index_writer.commit()
def add_document(self, pagename, title, text):
self.index_writer.add_document(path=unicode(pagename),
title=title,
title=title,
text=text)
def handle_query(self, q):

View File

@ -37,7 +37,7 @@ class XapianSearch(BaseSearch):
def finish_indexing(self):
# Ensure the db lock is removed.
del self.database
def add_document(self, path, title, text):
self.database.begin_transaction()
# sphinx_page_path is used to easily retrieve documents by path.