Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit 66cff78

Browse files
committed
Add project metadata api
1 parent b2036f7 commit 66cff78

File tree

2 files changed

+10
-85
lines changed

2 files changed

+10
-85
lines changed

readthedocs_ext/comments/backend.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ def get_comments(self, node):
4040
else:
4141
return False
4242

43+
def get_project_metadata(self, project):
44+
url = self.url.replace('/websupport', '') + "/api/v2/comments/"
45+
data = {'project': project}
46+
r = requests.get(url, params=data)
47+
if r.status_code is 200:
48+
return r.json()
49+
else:
50+
return False
51+
4352
def get_metadata(self, page):
4453
url = self.url + "/_get_metadata"
4554
data = {'page': page}

readthedocs_ext/comments/translator.py

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -41,90 +41,6 @@ def is_commentable(node):
4141

4242
return False
4343

44-
kong_comments = """
45-
{
46-
"count": 2,
47-
"next": null,
48-
"previous": null,
49-
"results": [
50-
{
51-
"date": "2015-02-24T19:03:53.992703",
52-
"user": 1,
53-
"text": "simple comment",
54-
"node": {
55-
"id": 619,
56-
"version": {
57-
"id": 104,
58-
"project": {
59-
"id": 2,
60-
"name": "Kong",
61-
"slug": "woot-kong",
62-
"description": "",
63-
"language": "en",
64-
"repo": "http://github.com/ericholscher/django-kong",
65-
"repo_type": "git",
66-
"default_version": "latest",
67-
"default_branch": null,
68-
"documentation_type": "sphinx",
69-
"users": [
70-
1
71-
]
72-
},
73-
"slug": "latest",
74-
"identifier": "master",
75-
"verbose_name": "latest",
76-
"active": true,
77-
"built": true,
78-
"downloads": "{'htmlzip': '//localhost:8000/projects/woot-kong/downloads/htmlzip/latest/', 'epub': '//localhost:8000/projects/woot-kong/downloads/epub/latest/'}"
79-
},
80-
"current_hash": "nil-45fcb0188968b1be015a13a44508377b140a1639d872fcc7ee09639e7eb5eb71",
81-
"last_commit": "fac9e2868d8fe86c2e7fcc3d4f02a43fe015f9b3",
82-
"snapshots_count": "1",
83-
"page": "index",
84-
"project": 2
85-
}
86-
},
87-
{
88-
"date": "2015-02-24T19:04:00.174457",
89-
"user": 1,
90-
"text": "Another coment",
91-
"node": {
92-
"id": 620,
93-
"version": {
94-
"id": 104,
95-
"project": {
96-
"id": 2,
97-
"name": "Kong",
98-
"slug": "woot-kong",
99-
"description": "",
100-
"language": "en",
101-
"repo": "http://github.com/ericholscher/django-kong",
102-
"repo_type": "git",
103-
"default_version": "latest",
104-
"default_branch": null,
105-
"documentation_type": "sphinx",
106-
"users": [
107-
1
108-
]
109-
},
110-
"slug": "latest",
111-
"identifier": "master",
112-
"verbose_name": "latest",
113-
"active": true,
114-
"built": true,
115-
"downloads": "{'htmlzip': '//localhost:8000/projects/woot-kong/downloads/htmlzip/latest/', 'epub': '//localhost:8000/projects/woot-kong/downloads/epub/latest/'}"
116-
},
117-
"current_hash": "nil-1a8ea4600ed6309a4a13a8b18380606b81485927d07247544270cecaec34c509",
118-
"last_commit": "fac9e2868d8fe86c2e7fcc3d4f02a43fe015f9b3",
119-
"snapshots_count": "1",
120-
"page": "index",
121-
"project": 2
122-
}
123-
}
124-
]
125-
}
126-
"""
127-
12844
class UUIDTranslator(HTMLTranslator):
12945

13046
"""
@@ -135,7 +51,7 @@ class UUIDTranslator(HTMLTranslator):
13551
def __init__(self, builder, *args, **kwargs):
13652
HTMLTranslator.__init__(self, builder, *args, **kwargs)
13753
self.comment_class = 'sphinx-has-comment'
138-
self.metadata = json.loads(kong_comments)['results']
54+
self.metadata = builder.storage.get_project_metadata(builder.config.html_context['slug'])['results']
13955

14056
def dispatch_visit(self, node):
14157
if is_commentable(node):

0 commit comments

Comments
 (0)