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
c2603381
Commit
c2603381
authored
Oct 13, 2015
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add JSON view for credits
Issue #798 Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
029fec1e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
1 deletion
+72
-1
weblate/trans/forms.py
weblate/trans/forms.py
+27
-0
weblate/trans/tests/test_reports.py
weblate/trans/tests/test_reports.py
+14
-0
weblate/trans/views/basic.py
weblate/trans/views/basic.py
+2
-1
weblate/trans/views/reports.py
weblate/trans/views/reports.py
+24
-0
weblate/urls.py
weblate/urls.py
+5
-0
No files found.
weblate/trans/forms.py
View file @
c2603381
...
...
@@ -37,6 +37,7 @@ from weblate.trans.specialchars import get_special_chars
from
weblate.trans.validators
import
validate_check_flags
from
weblate.accounts.forms
import
sort_choices
from
urllib
import
urlencode
from
datetime
import
date
from
weblate.logger
import
LOGGER
from
weblate
import
get_doc_url
...
...
@@ -809,3 +810,29 @@ class UserManageForm(forms.Form):
raise
ValidationError
(
_
(
'No matching user found!'
))
except
User
.
MultipleObjectsReturned
:
raise
ValidationError
(
_
(
'More users matched!'
))
class
ReportDownloadForm
(
forms
.
Form
):
style
=
forms
.
ChoiceField
(
label
=
_
(
'Report format'
),
help_text
=
_
(
'Choose file format for the report'
),
choices
=
(
(
'rst'
,
_
(
'reStructuredText'
)),
(
'json'
,
_
(
'JSON'
))
),
)
class
CreditsForm
(
ReportDownloadForm
):
start_date
=
forms
.
DateField
(
label
=
_
(
'Starting date'
),
initial
=
date
(
2000
,
1
,
1
),
widget
=
forms
.
DateInput
(
attrs
=
{
'type'
:
'date'
,
'data-provide'
:
'datepicker'
,
'data-date-format'
:
'yyyy-mm-dd'
,
},
format
=
'%Y-%m-%d'
)
)
weblate/trans/tests/test_reports.py
View file @
c2603381
...
...
@@ -21,8 +21,10 @@
from
weblate.trans.tests.test_views
import
ViewTestCase
from
weblate.trans.views.reports
import
generate_credits
from
django.core.urlresolvers
import
reverse
from
django.utils
import
timezone
from
datetime
import
timedelta
import
json
class
ReportsTest
(
ViewTestCase
):
...
...
@@ -59,3 +61,15 @@ class ReportsTest(ViewTestCase):
'Nazdar svete2!
\
n
'
)
self
.
test_credits_one
()
def
test_credits_view_json
(
self
):
self
.
add_change
()
response
=
self
.
client
.
post
(
reverse
(
'credits'
,
kwargs
=
self
.
kw_subproject
),
{
'style'
:
'json'
,
'start_date'
:
'2000-01-01'
},
)
credits
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
credits
,
[{
'Czech'
:
[[
'noreply@weblate.org'
,
'Weblate Test'
]]}]
)
weblate/trans/views/basic.py
View file @
c2603381
...
...
@@ -36,7 +36,7 @@ from weblate.lang.models import Language
from
weblate.trans.forms
import
(
get_upload_form
,
SearchForm
,
AutoForm
,
ReviewForm
,
NewLanguageForm
,
UserManageForm
,
UserManageForm
,
CreditsForm
,
)
from
weblate.trans.permissions
import
can_automatic_translation
from
weblate.accounts.models
import
Profile
,
notify_new_language
...
...
@@ -314,6 +314,7 @@ def show_translation(request, project, subproject, lang):
'search_form'
:
search_form
,
'review_form'
:
review_form
,
'last_changes'
:
last_changes
,
'credits_form'
:
CreditsForm
(),
'last_changes_url'
:
urlencode
(
obj
.
get_kwargs
()),
'show_only_component'
:
True
,
'other_translations'
:
Translation
.
objects
.
filter
(
...
...
weblate/trans/views/reports.py
View file @
c2603381
...
...
@@ -19,6 +19,12 @@
#
from
weblate.trans.models.changes
import
Change
from
weblate.trans.forms
import
CreditsForm
from
weblate.trans.views.helper
import
get_subproject
from
django.http
import
HttpResponse
from
django.views.decorators.http
import
require_POST
from
django.shortcuts
import
redirect
import
json
def
generate_credits
(
component
,
start_date
):
...
...
@@ -37,3 +43,21 @@ def generate_credits(component, start_date):
result
.
append
({
translation
.
language
.
name
:
sorted
(
set
(
authors
))})
return
result
@
require_POST
def
get_credits
(
request
,
project
,
subproject
):
"""View for credits"""
obj
=
get_subproject
(
request
,
project
,
subproject
)
form
=
CreditsForm
(
request
.
POST
)
if
not
form
.
is_valid
():
return
redirect
(
obj
)
credits
=
generate_credits
(
obj
,
form
.
cleaned_data
[
'start_date'
])
if
form
.
cleaned_data
[
'style'
]
==
'json'
:
return
HttpResponse
(
json
.
dumps
(
credits
),
content_type
=
'application/json'
)
weblate/urls.py
View file @
c2603381
...
...
@@ -185,6 +185,11 @@ urlpatterns = patterns(
'weblate.trans.views.edit.auto_translation'
,
name
=
'auto_translation'
,
),
url
(
r'^credits/'
+
SUBPROJECT
+
'$'
,
'weblate.trans.views.reports.get_credits'
,
name
=
'credits'
,
),
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