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
8fafc294
Commit
8fafc294
authored
Oct 18, 2012
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add CSV export for dictionary (issue #124)
parent
50005cc5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
0 deletions
+36
-0
weblate/html/dictionary.html
weblate/html/dictionary.html
+9
-0
weblate/trans/views.py
weblate/trans/views.py
+26
-0
weblate/urls.py
weblate/urls.py
+1
-0
No files found.
weblate/html/dictionary.html
View file @
8fafc294
...
...
@@ -76,6 +76,7 @@
{% if perms.trans.upload_dictionary %}
<li><a
href=
"#import"
>
{% trans "Import dictionary" %}
</a></li>
{% endif %}
<li><a
href=
"#export"
>
{% trans "Export dictionary" %}
</a></li>
</ul>
{% if perms.trans.add_dictionary %}
...
...
@@ -108,4 +109,12 @@
</div>
{% endif %}
<div
id=
"export"
>
<p>
{% trans "You can download dictionary in following formats:" %}
</p>
<ul>
<li><a
href=
"{% url 'weblate.trans.views.download_dictionary' project=project.slug lang=language.code %}?format=csv"
>
{% trans "Comma separated values (CSV)" %}
</a></li>
</ul>
{% endblock %}
weblate/trans/views.py
View file @
8fafc294
...
...
@@ -46,6 +46,7 @@ import datetime
import
logging
import
os.path
import
json
import
csv
from
xml.etree
import
ElementTree
import
urllib2
...
...
@@ -237,6 +238,31 @@ def upload_dictionary(request, project, lang):
messages
.
error
(
request
,
_
(
'Failed to process form!'
))
return
HttpResponseRedirect
(
reverse
(
'weblate.trans.views.show_dictionary'
,
kwargs
=
{
'project'
:
prj
.
slug
,
'lang'
:
lang
.
code
}))
def
download_dictionary
(
request
,
project
,
lang
):
'''
Exports dictionary.
'''
prj
=
get_object_or_404
(
Project
,
slug
=
project
)
lang
=
get_object_or_404
(
Language
,
code
=
lang
)
# Parse parameters
export_format
=
None
if
'format'
in
request
.
GET
:
export_format
=
request
.
GET
[
'format'
]
if
not
export_format
in
[
'csv'
]:
export_format
=
'csv'
if
export_format
==
'csv'
:
response
=
HttpResponse
(
mimetype
=
'text/csv'
)
response
[
'Content-Disposition'
]
=
'attachment; filename=dictionary-%s-%s.csv'
%
(
prj
.
slug
,
lang
.
code
)
writer
=
csv
.
writer
(
response
)
words
=
Dictionary
.
objects
.
filter
(
project
=
prj
,
language
=
lang
).
order_by
(
'source'
)
for
word
in
words
.
iterator
():
writer
.
writerow
((
word
.
source
.
encode
(
'utf8'
),
word
.
target
.
encode
(
'utf8'
)))
return
response
def
show_dictionary
(
request
,
project
,
lang
):
prj
=
get_object_or_404
(
Project
,
slug
=
project
)
lang
=
get_object_or_404
(
Language
,
code
=
lang
)
...
...
weblate/urls.py
View file @
8fafc294
...
...
@@ -51,6 +51,7 @@ urlpatterns = patterns('',
url
(
r'^dictionaries/(?P<project>[^/]*)/(?P<lang>[^/]*)/upload/$'
,
'weblate.trans.views.upload_dictionary'
),
url
(
r'^dictionaries/(?P<project>[^/]*)/(?P<lang>[^/]*)/delete/$'
,
'weblate.trans.views.delete_dictionary'
),
url
(
r'^dictionaries/(?P<project>[^/]*)/(?P<lang>[^/]*)/edit/$'
,
'weblate.trans.views.edit_dictionary'
),
url
(
r'^dictionaries/(?P<project>[^/]*)/(?P<lang>[^/]*)/download/$'
,
'weblate.trans.views.download_dictionary'
),
url
(
r'^projects/(?P<project>[^/]*)/(?P<subproject>[^/]*)/$'
,
'weblate.trans.views.show_subproject'
),
url
(
r'^projects/(?P<project>[^/]*)/(?P<subproject>[^/]*)/(?P<lang>[^/]*)/$'
,
'weblate.trans.views.show_translation'
),
...
...
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