summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/web/quickstart.rst2
-rw-r--r--sphinx/websupport/storage/__init__.py7
-rw-r--r--sphinx/websupport/storage/sqlalchemystorage.py7
-rw-r--r--sphinx/writers/websupport.py12
4 files changed, 21 insertions, 7 deletions
diff --git a/doc/web/quickstart.rst b/doc/web/quickstart.rst
index 61a432a86..fa93c6d90 100644
--- a/doc/web/quickstart.rst
+++ b/doc/web/quickstart.rst
@@ -6,6 +6,8 @@ Web Support Quick Start
Building Documentation Data
~~~~~~~~~~~~~~~~~~~~~~~~~~~
+New Test p
+
To make use of the web support package in your application you'll
need to build the data it uses. This data includes pickle files representing
documents, search indices, and node data that is used to track where
diff --git a/sphinx/websupport/storage/__init__.py b/sphinx/websupport/storage/__init__.py
index 6a5ff49b1..3d8a9ab58 100644
--- a/sphinx/websupport/storage/__init__.py
+++ b/sphinx/websupport/storage/__init__.py
@@ -16,6 +16,13 @@ class StorageBackend(object):
"""
pass
+ def has_node(self, id):
+ """Check to see if a node exists.
+
+ :param id: the id to check for.
+ """
+ raise NotImplementedError()
+
def add_node(self, id, document, source):
"""Add a node to the StorageBackend.
diff --git a/sphinx/websupport/storage/sqlalchemystorage.py b/sphinx/websupport/storage/sqlalchemystorage.py
index 174bef6e5..c775f3bb4 100644
--- a/sphinx/websupport/storage/sqlalchemystorage.py
+++ b/sphinx/websupport/storage/sqlalchemystorage.py
@@ -33,11 +33,16 @@ class SQLAlchemyStorage(StorageBackend):
def pre_build(self):
self.build_session = Session()
+ def has_node(self, id):
+ session = Session()
+ node = session.query(Node).filter(Node.id == id).first()
+ session.close()
+ return True if node else False
+
def add_node(self, id, document, source):
node = Node(id, document, source)
self.build_session.add(node)
self.build_session.flush()
- return node
def post_build(self):
self.build_session.commit()
diff --git a/sphinx/writers/websupport.py b/sphinx/writers/websupport.py
index 6beb4b987..30e8c4dc8 100644
--- a/sphinx/writers/websupport.py
+++ b/sphinx/writers/websupport.py
@@ -27,19 +27,19 @@ class WebSupportTranslator(HTMLTranslator):
HTMLTranslator.dispatch_visit(self, node)
def handle_visit_commentable(self, node):
- db_node = self.add_db_node(node)
# We will place the node in the HTML id attribute. If the node
# already has an id (for indexing purposes) put an empty
# span with the existing id directly before this node's HTML.
+ self.add_db_node(node)
if node.attributes['ids']:
self.body.append('<span id="%s"></span>'
% node.attributes['ids'][0])
- node.attributes['ids'] = ['s%s' % db_node.id]
+ node.attributes['ids'] = ['s%s' % node.uid]
node.attributes['classes'].append(self.comment_class)
def add_db_node(self, node):
storage = self.builder.app.storage
- db_node_id = storage.add_node(id=node.uid,
- document=self.builder.cur_docname,
- source=node.rawsource or node.astext())
- return db_node_id
+ if not storage.has_node(node.uid):
+ storage.add_node(id=node.uid,
+ document=self.builder.cur_docname,
+ source=node.rawsource or node.astext())