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
3b84b41f
Commit
3b84b41f
authored
Oct 13, 2015
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add contributor stats
Issue #835 Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
71291d33
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
162 additions
and
1 deletion
+162
-1
docs/changes.rst
docs/changes.rst
+1
-0
weblate/trans/tests/test_reports.py
weblate/trans/tests/test_reports.py
+57
-1
weblate/trans/views/reports.py
weblate/trans/views/reports.py
+99
-0
weblate/urls.py
weblate/urls.py
+5
-0
No files found.
docs/changes.rst
View file @
3b84b41f
...
...
@@ -13,6 +13,7 @@ Released on ? 2015.
* Added support for some GNU extensions to C printf format.
* Documentation improvements.
* Added support for generating translator credits.
* Added support for generating contributor stats.
weblate 2.4
-----------
...
...
weblate/trans/tests/test_reports.py
View file @
3b84b41f
...
...
@@ -20,7 +20,7 @@
from
weblate.trans.tests.test_views
import
ViewTestCase
from
weblate.trans.views.reports
import
generate_credits
from
weblate.trans.views.reports
import
generate_credits
,
generate_counts
from
django.core.urlresolvers
import
reverse
from
django.utils
import
timezone
from
datetime
import
timedelta
...
...
@@ -102,3 +102,59 @@ class ReportsTest(ViewTestCase):
'Weblate Test</a></li></ul></td>
\
n
</tr>
\
n
'
'</table>'
)
def
test_counts_one
(
self
):
self
.
add_change
()
data
=
generate_counts
(
self
.
subproject
,
timezone
.
now
()
-
timedelta
(
days
=
1
),
timezone
.
now
()
+
timedelta
(
days
=
1
)
)
self
.
assertEqual
(
data
,
[{
'count'
:
1
,
'name'
:
'Weblate Test'
,
'words'
:
2
,
'email'
:
u'noreply@weblate.org'
}]
)
def
get_counts
(
self
,
style
):
self
.
add_change
()
return
self
.
client
.
post
(
reverse
(
'counts'
,
kwargs
=
self
.
kw_subproject
),
{
'style'
:
style
,
'start_date'
:
'2000-01-01'
,
'end_date'
:
'2100-01-01'
},
)
def
test_counts_view_json
(
self
):
response
=
self
.
get_counts
(
'json'
)
data
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
data
,
[{
'count'
:
1
,
'email'
:
'noreply@weblate.org'
,
'name'
:
'Weblate Test'
,
'words'
:
2
}]
)
def
test_counts_view_rst
(
self
):
response
=
self
.
get_counts
(
'rst'
)
self
.
assertContains
(
response
,
'noreply@weblate.org'
)
def
test_counts_view_html
(
self
):
response
=
self
.
get_counts
(
'html'
)
self
.
assertEqual
(
response
.
content
,
'<table>
\
n
'
'<tr>
\
n
<td>Weblate Test</td>
\
n
'
'<td>noreply@weblate.org</td>
\
n
'
'<td>2</td>
\
n
<td>1</td>
\
n
'
'
\
n
</tr>
\
n
</table>'
)
weblate/trans/views/reports.py
View file @
3b84b41f
...
...
@@ -121,3 +121,102 @@ def get_credits(request, project, subproject):
'
\
n
'
.
join
(
result
),
content_type
=
'{0}; charset=utf-8'
.
format
(
mime
),
)
def
generate_counts
(
component
,
start_date
,
end_date
):
"""Generates credits data for given component."""
result
=
{}
for
translation
in
component
.
translation_set
.
all
():
authors
=
Change
.
objects
.
content
().
filter
(
translation
=
translation
,
timestamp__range
=
(
start_date
,
end_date
),
).
values_list
(
'author__email'
,
'author__first_name'
,
'unit__num_words'
,
)
for
email
,
name
,
words
in
authors
:
if
email
not
in
result
:
result
[
email
]
=
{
'name'
:
name
,
'email'
:
email
,
'words'
:
words
,
'count'
:
1
,
}
else
:
result
[
email
][
'words'
]
+=
words
result
[
email
][
'count'
]
+=
1
return
result
.
values
()
@
login_required
@
require_POST
def
get_counts
(
request
,
project
,
subproject
):
"""View for work counts"""
obj
=
get_subproject
(
request
,
project
,
subproject
)
if
not
can_view_reports
(
request
.
user
,
obj
.
project
):
raise
PermissionDenied
()
form
=
CreditsForm
(
request
.
POST
)
if
not
form
.
is_valid
():
return
redirect
(
obj
)
data
=
generate_counts
(
obj
,
form
.
cleaned_data
[
'start_date'
],
form
.
cleaned_data
[
'end_date'
],
)
if
form
.
cleaned_data
[
'style'
]
==
'json'
:
return
HttpResponse
(
json
.
dumps
(
data
),
content_type
=
'application/json'
)
if
form
.
cleaned_data
[
'style'
]
==
'html'
:
start
=
'<table>'
row_start
=
'<tr>'
cell_format
=
u'<td>{0}</td>
\
n
'
row_end
=
'</tr>'
mime
=
'text/html'
end
=
'</table>'
else
:
heading
=
' '
.
join
([
'='
*
25
]
*
4
)
start
=
'{0}
\
n
{1:25} {2:25} {3:25} {4:25}
\
n
{0}'
.
format
(
heading
,
'Email'
,
'Name'
,
'Words'
,
'Count'
)
row_start
=
''
cell_format
=
u'{0:25} '
row_end
=
''
mime
=
'text/plain'
end
=
heading
result
=
[]
result
.
append
(
start
)
for
item
in
data
:
result
.
append
(
row_start
)
result
.
append
(
u'{0}{1}{2}{3}'
.
format
(
cell_format
.
format
(
item
[
'name'
]),
cell_format
.
format
(
item
[
'email'
]),
cell_format
.
format
(
item
[
'words'
]),
cell_format
.
format
(
item
[
'count'
]),
)
)
result
.
append
(
row_end
)
result
.
append
(
end
)
return
HttpResponse
(
'
\
n
'
.
join
(
result
),
content_type
=
'{0}; charset=utf-8'
.
format
(
mime
),
)
weblate/urls.py
View file @
3b84b41f
...
...
@@ -190,6 +190,11 @@ urlpatterns = patterns(
'weblate.trans.views.reports.get_credits'
,
name
=
'credits'
,
),
url
(
r'^counts/'
+
SUBPROJECT
+
'$'
,
'weblate.trans.views.reports.get_counts'
,
name
=
'counts'
,
),
url
(
r'^new-lang/'
+
SUBPROJECT
+
'$'
,
'weblate.trans.views.basic.new_language'
,
...
...
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