Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
a1545b88
Commit
a1545b88
authored
Nov 05, 2014
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for exporting stats as JSONP.
Fixes #577 Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
9acfec4d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
6 deletions
+31
-6
docs/api.rst
docs/api.rst
+5
-1
docs/changes.rst
docs/changes.rst
+1
-0
weblate/trans/tests/test_exports.py
weblate/trans/tests/test_exports.py
+7
-0
weblate/trans/views/api.py
weblate/trans/views/api.py
+18
-5
No files found.
docs/api.rst
View file @
a1545b88
...
...
@@ -70,7 +70,11 @@ Weblate provides various exports to allow you further process the data.
.. http:get:: /exports/stats/(string:project)/(string:component)/
Retrieves statistics for given component in JSON format.
:query integer indent: pretty printed indentation
:query string jsonp: JSONP callback function to wrap the data
Retrieves statistics for given component in JSON format. Optionally as
JSONP when you specify the callback in the ``jsonp`` parameter.
You can get pretty-printed output by appending ``?indent=1`` to the
request.
...
...
docs/changes.rst
View file @
a1545b88
...
...
@@ -23,6 +23,7 @@ Released on ? 2014.
* Compatibility with older Git versions.
* Improved ACL support.
* Added buttons for per language quotes and other special chars.
* Support for exporting stats as JSONP.
weblate 1.9
-----------
...
...
weblate/trans/tests/test_exports.py
View file @
a1545b88
...
...
@@ -59,6 +59,13 @@ class ExportsViewTest(ViewTestCase):
parsed
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
parsed
[
0
][
'name'
],
'Czech'
)
def
test_export_stats_jsonp
(
self
):
response
=
self
.
client
.
get
(
reverse
(
'export_stats'
,
kwargs
=
self
.
kw_subproject
),
{
'jsonp'
:
'test_callback'
}
)
self
.
assertContains
(
response
,
'test_callback('
)
def
test_data
(
self
):
response
=
self
.
client
.
get
(
reverse
(
'data_root'
)
...
...
weblate/trans/views/api.py
View file @
a1545b88
...
...
@@ -269,6 +269,10 @@ def export_stats(request, project, subproject):
except
(
ValueError
,
KeyError
):
indent
=
None
jsonp
=
None
if
'jsonp'
in
request
.
GET
and
request
.
GET
[
'jsonp'
]:
jsonp
=
request
.
GET
[
'jsonp'
]
response
=
[]
for
trans
in
subprj
.
translation_set
.
all
():
response
.
append
({
...
...
@@ -288,11 +292,20 @@ def export_stats(request, project, subproject):
'url'
:
trans
.
get_share_url
(),
'url_translate'
:
get_site_url
(
trans
.
get_absolute_url
()),
})
json_data
=
json
.
dumps
(
response
,
default
=
json_dt_handler
,
indent
=
indent
,
)
if
jsonp
:
return
HttpResponse
(
'{0}({1})'
.
format
(
jsonp
,
json_data
,
),
content_type
=
'application/javascript'
)
return
HttpResponse
(
json
.
dumps
(
response
,
default
=
json_dt_handler
,
indent
=
indent
,
),
json_data
,
content_type
=
'application/json'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment