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
140d8a40
Commit
140d8a40
authored
Mar 24, 2016
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move file dowloading to separate helper function
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
b9e95a3f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
37 deletions
+53
-37
weblate/trans/exporters.py
weblate/trans/exporters.py
+9
-5
weblate/trans/views/files.py
weblate/trans/views/files.py
+5
-32
weblate/trans/views/helper.py
weblate/trans/views/helper.py
+39
-0
No files found.
weblate/trans/exporters.py
View file @
140d8a40
...
@@ -56,15 +56,19 @@ class BaseExporter(object):
...
@@ -56,15 +56,19 @@ class BaseExporter(object):
translation
=
None
):
translation
=
None
):
if
translation
is
not
None
:
if
translation
is
not
None
:
self
.
project
=
translation
.
subproject
.
project
self
.
project
=
translation
.
subproject
.
project
self
.
lang
auge
=
obj
.
language
self
.
lang
uage
=
translation
.
language
self
.
url
=
obj
.
get_absolute_url
()
self
.
url
=
translation
.
get_absolute_url
()
else
:
else
:
self
.
project
=
project
self
.
project
=
project
self
.
language
=
language
self
.
language
=
language
self
.
url
=
url
self
.
url
=
url
self
.
storage
=
self
.
get_storage
()
self
.
storage
=
self
.
get_storage
()
self
.
storage
.
setsourcelanguage
(
project
.
source_language
.
code
)
self
.
storage
.
setsourcelanguage
(
self
.
storage
.
settargetlanguage
(
language
.
code
)
self
.
project
.
source_language
.
code
)
self
.
storage
.
settargetlanguage
(
self
.
language
.
code
)
def
get_storage
(
self
):
def
get_storage
(
self
):
raise
NotImplementedError
()
raise
NotImplementedError
()
...
@@ -79,7 +83,7 @@ class BaseExporter(object):
...
@@ -79,7 +83,7 @@ class BaseExporter(object):
self
.
storage
.
addunit
(
unit
)
self
.
storage
.
addunit
(
unit
)
def
add_units
(
self
,
translation
):
def
add_units
(
self
,
translation
):
for
unit
in
translation
.
unit_set
.
iterator
():
for
unit
in
translation
.
unit_set
.
iterator
():
self
.
add_unit
(
unit
)
self
.
add_unit
(
unit
)
def
add_unit
(
self
,
unit
):
def
add_unit
(
self
,
unit
):
...
...
weblate/trans/views/files.py
View file @
140d8a40
...
@@ -28,10 +28,11 @@ from django.contrib import messages
...
@@ -28,10 +28,11 @@ from django.contrib import messages
from
django.contrib.auth.decorators
import
permission_required
from
django.contrib.auth.decorators
import
permission_required
from
django.views.decorators.http
import
require_POST
from
django.views.decorators.http
import
require_POST
from
weblate.trans.exporters
import
get_exporter
from
weblate.trans.util
import
report_error
from
weblate.trans.util
import
report_error
from
weblate.trans.forms
import
get_upload_form
from
weblate.trans.forms
import
get_upload_form
from
weblate.trans.views.helper
import
get_translation
,
import_message
from
weblate.trans.views.helper
import
(
get_translation
,
import_message
,
download_translation_file
)
from
weblate.trans.permissions
import
(
from
weblate.trans.permissions
import
(
can_author_translation
,
can_overwrite_translation
can_author_translation
,
can_overwrite_translation
)
)
...
@@ -40,41 +41,13 @@ from weblate.trans.permissions import (
...
@@ -40,41 +41,13 @@ from weblate.trans.permissions import (
def
download_translation_format
(
request
,
project
,
subproject
,
lang
,
fmt
):
def
download_translation_format
(
request
,
project
,
subproject
,
lang
,
fmt
):
obj
=
get_translation
(
request
,
project
,
subproject
,
lang
)
obj
=
get_translation
(
request
,
project
,
subproject
,
lang
)
try
:
return
download_translation_file
(
obj
,
fmt
)
exporter
=
get_exporter
(
fmt
)(
translation
=
obj
)
except
KeyError
:
raise
Http404
(
'File format not supported'
)
exporter
.
add_units
(
obj
)
# Save to response
return
exporter
.
get_response
(
'{{project}}-{0}-{{language}}.{{extension}}'
.
format
(
subproject
)
)
def
download_translation
(
request
,
project
,
subproject
,
lang
):
def
download_translation
(
request
,
project
,
subproject
,
lang
):
obj
=
get_translation
(
request
,
project
,
subproject
,
lang
)
obj
=
get_translation
(
request
,
project
,
subproject
,
lang
)
srcfilename
=
obj
.
get_filename
()
return
download_translation_file
(
obj
)
# Construct file name (do not use real filename as it is usually not
# that useful)
filename
=
'%s-%s-%s.%s'
%
(
project
,
subproject
,
lang
,
obj
.
store
.
extension
)
# Create response
with
open
(
srcfilename
)
as
handle
:
response
=
HttpResponse
(
handle
.
read
(),
content_type
=
obj
.
store
.
mimetype
)
# Fill in response headers
response
[
'Content-Disposition'
]
=
'attachment; filename=%s'
%
filename
return
response
def
download_language_pack
(
request
,
project
,
subproject
,
lang
):
def
download_language_pack
(
request
,
project
,
subproject
,
lang
):
...
...
weblate/trans/views/helper.py
View file @
140d8a40
...
@@ -22,10 +22,12 @@ Helper methods for views.
...
@@ -22,10 +22,12 @@ Helper methods for views.
'''
'''
from
django.contrib
import
messages
from
django.contrib
import
messages
from
django.http
import
HttpResponse
,
Http404
from
django.shortcuts
import
get_object_or_404
from
django.shortcuts
import
get_object_or_404
import
django.utils.translation
import
django.utils.translation
from
django.utils.translation
import
trans_real
from
django.utils.translation
import
trans_real
from
weblate.trans.exporters
import
get_exporter
from
weblate.trans.models
import
Project
,
SubProject
,
Translation
from
weblate.trans.models
import
Project
,
SubProject
,
Translation
from
weblate.lang.models
import
Language
from
weblate.lang.models
import
Language
...
@@ -122,3 +124,40 @@ def import_message(request, count, message_none, message_ok):
...
@@ -122,3 +124,40 @@ def import_message(request, count, message_none, message_ok):
messages
.
warning
(
request
,
message_none
)
messages
.
warning
(
request
,
message_none
)
else
:
else
:
messages
.
success
(
request
,
message_ok
%
count
)
messages
.
success
(
request
,
message_ok
%
count
)
def
download_translation_file
(
translation
,
fmt
=
None
):
if
fmt
is
not
None
:
try
:
exporter
=
get_exporter
(
fmt
)(
translation
=
translation
)
except
KeyError
:
raise
Http404
(
'File format not supported'
)
exporter
.
add_units
(
translation
)
return
exporter
.
get_response
(
'{{project}}-{0}-{{language}}.{{extension}}'
.
format
(
translation
.
subproject
.
slug
)
)
srcfilename
=
translation
.
get_filename
()
# Construct file name (do not use real filename as it is usually not
# that useful)
filename
=
'{0}-{1}-{2}.{3}'
.
format
(
translation
.
subproject
.
project
.
slug
,
translation
.
subproject
.
slug
,
translation
.
language
.
code
,
translation
.
store
.
extension
)
# Create response
with
open
(
srcfilename
)
as
handle
:
response
=
HttpResponse
(
handle
.
read
(),
content_type
=
translation
.
store
.
mimetype
)
# Fill in response headers
response
[
'Content-Disposition'
]
=
'attachment; filename=%s'
%
filename
return
response
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