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
70748600
Commit
70748600
authored
Jan 08, 2016
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use force_text instead of force_unicode and unicode
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
114e54e1
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
45 additions
and
34 deletions
+45
-34
weblate/accounts/forms.py
weblate/accounts/forms.py
+4
-4
weblate/lang/models.py
weblate/lang/models.py
+2
-1
weblate/lang/tests.py
weblate/lang/tests.py
+2
-1
weblate/trans/forms.py
weblate/trans/forms.py
+2
-2
weblate/trans/machine/weblatetm.py
weblate/trans/machine/weblatetm.py
+2
-1
weblate/trans/management/commands/import_project.py
weblate/trans/management/commands/import_project.py
+2
-2
weblate/trans/models/changes.py
weblate/trans/models/changes.py
+3
-2
weblate/trans/models/dictionary.py
weblate/trans/models/dictionary.py
+2
-2
weblate/trans/search.py
weblate/trans/search.py
+8
-7
weblate/trans/templatetags/translations.py
weblate/trans/templatetags/translations.py
+3
-3
weblate/trans/tests/test_autofix.py
weblate/trans/tests/test_autofix.py
+2
-1
weblate/trans/tests/test_unitdata.py
weblate/trans/tests/test_unitdata.py
+3
-2
weblate/trans/util.py
weblate/trans/util.py
+2
-1
weblate/trans/views/dictionary.py
weblate/trans/views/dictionary.py
+2
-1
weblate/trans/views/edit.py
weblate/trans/views/edit.py
+4
-3
weblate/trans/views/files.py
weblate/trans/views/files.py
+2
-1
No files found.
weblate/accounts/forms.py
View file @
70748600
...
...
@@ -26,7 +26,7 @@ from django import forms
from
django.utils.translation
import
ugettext_lazy
as
_
,
pgettext
from
django.contrib.auth
import
authenticate
from
django.contrib.auth.models
import
User
from
django.utils.encoding
import
force_
unicode
from
django.utils.encoding
import
force_
text
from
crispy_forms.helper
import
FormHelper
from
weblate.accounts.models
import
Profile
,
VerifiedEmail
...
...
@@ -46,7 +46,7 @@ def remove_accents(input_str):
"""
Removes accents from a string.
"""
nkfd_form
=
unicodedata
.
normalize
(
'NFKD'
,
force_
unicode
(
input_str
))
nkfd_form
=
unicodedata
.
normalize
(
'NFKD'
,
force_
text
(
input_str
))
only_ascii
=
nkfd_form
.
encode
(
'ASCII'
,
'ignore'
)
return
only_ascii
...
...
@@ -66,7 +66,7 @@ def sort_choices(choices):
collator
=
pyuca
.
Collator
()
return
sorted
(
choices
,
key
=
lambda
tup
:
collator
.
sort_key
(
force_
unicode
(
tup
[
1
]))
key
=
lambda
tup
:
collator
.
sort_key
(
force_
text
(
tup
[
1
]))
)
...
...
@@ -127,7 +127,7 @@ class SortedSelectMixin(object):
Renders sorted options.
'''
# Normalize to strings.
selected_choices = set(force_
unicode
(v) for v in selected_choices)
selected_choices = set(force_
text
(v) for v in selected_choices)
output = []
# Actually sort values
...
...
weblate/lang/models.py
View file @
70748600
...
...
@@ -21,6 +21,7 @@
from
__future__
import
unicode_literals
from
django.db
import
models
,
transaction
from
django.db.utils
import
OperationalError
from
django.utils.encoding
import
force_text
from
django.utils.translation
import
ugettext
as
_
,
ugettext_lazy
from
django.utils.safestring
import
mark_safe
from
django.dispatch
import
receiver
...
...
@@ -414,7 +415,7 @@ class Language(models.Model, PercentMixin):
Returns label for plural form.
'''
try
:
return
unicode
(
data
.
PLURAL_NAMES
[
self
.
plural_type
][
idx
])
return
force_text
(
data
.
PLURAL_NAMES
[
self
.
plural_type
][
idx
])
except
(
IndexError
,
KeyError
):
if
idx
==
0
:
return
_
(
'Singular'
)
...
...
weblate/lang/tests.py
View file @
70748600
...
...
@@ -27,6 +27,7 @@ import gettext
from
django.test
import
TestCase
from
django.core.urlresolvers
import
reverse
from
django.core.management
import
call_command
from
django.utils.encoding
import
force_text
from
weblate.lang.models
import
Language
,
get_plural_type
from
weblate.lang
import
data
from
weblate.trans.tests.test_views
import
ViewTestCase
...
...
@@ -227,7 +228,7 @@ class LanguagesTest(TestCase):
self
.
assertIn
(
direction
,
lang
.
get_html
())
self
.
assertIn
(
expected
,
lang
.
get_html
())
# Check name
self
.
assertEqual
(
unicode
(
lang
),
name
)
self
.
assertEqual
(
force_text
(
lang
),
name
)
def
test_plurals
(
self
):
'''
...
...
weblate/trans/forms.py
View file @
70748600
...
...
@@ -24,7 +24,7 @@ from django.utils.translation import (
ugettext_lazy
as
_
,
ugettext
,
pgettext_lazy
,
pgettext
)
from
django.utils.safestring
import
mark_safe
from
django.utils.encoding
import
smart_
unicode
from
django.utils.encoding
import
smart_
text
from
django.forms
import
ValidationError
from
django.core.urlresolvers
import
reverse
from
django.db.models
import
Q
...
...
@@ -232,7 +232,7 @@ class PluralTextarea(forms.Textarea):
if
fieldname
not
in
data
:
break
ret
.
append
(
data
.
get
(
fieldname
,
''
))
ret
=
[
smart_
unicode
(
r
.
replace
(
'
\
r
'
,
''
))
for
r
in
ret
]
ret
=
[
smart_
text
(
r
.
replace
(
'
\
r
'
,
''
))
for
r
in
ret
]
return
ret
...
...
weblate/trans/machine/weblatetm.py
View file @
70748600
...
...
@@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from
django.utils.encoding
import
force_text
from
weblate.trans.machine.base
import
MachineTranslation
from
weblate.trans.models.unit
import
Unit
...
...
@@ -29,7 +30,7 @@ def format_unit_match(unit, quality):
return
(
unit
.
get_target_plurals
()[
0
],
quality
,
'Weblate (%s)'
%
unicode
(
unit
.
translation
.
subproject
),
'Weblate (%s)'
%
force_text
(
unit
.
translation
.
subproject
),
unit
.
get_source_plurals
()[
0
],
)
...
...
weblate/trans/management/commands/import_project.py
View file @
70748600
...
...
@@ -19,7 +19,7 @@
#
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.utils.encoding
import
force_
unicode
from
django.utils.encoding
import
force_
text
from
django.db.models
import
Q
from
django.utils.text
import
slugify
from
weblate.trans.models
import
SubProject
,
Project
...
...
@@ -326,7 +326,7 @@ class Command(BaseCommand):
raise
CommandError
(
'Specified --main-component was not found in matches!'
)
match
=
force_
unicode
(
self
.
main_component
)
match
=
force_
text
(
self
.
main_component
)
matches
.
remove
(
self
.
main_component
)
else
:
match
=
matches
.
pop
()
...
...
weblate/trans/models/changes.py
View file @
70748600
...
...
@@ -23,6 +23,7 @@ from django.contrib.auth.models import User
from
django.db.models
import
Count
,
Q
from
django.utils.translation
import
ugettext
as
_
,
ugettext_lazy
from
django.utils
import
timezone
from
django.utils.encoding
import
force_text
from
weblate.trans.models.project
import
Project
from
weblate.accounts.avatar
import
get_user_display
...
...
@@ -282,9 +283,9 @@ class Change(models.Model):
Returns display name for translation.
'''
if
self
.
translation
is
not
None
:
return
unicode
(
self
.
translation
)
return
force_text
(
self
.
translation
)
elif
self
.
subproject
is
not
None
:
return
unicode
(
self
.
subproject
)
return
force_text
(
self
.
subproject
)
elif
self
.
dictionary
is
not
None
:
return
'%s/%s'
%
(
self
.
dictionary
.
project
,
...
...
weblate/trans/models/dictionary.py
View file @
70748600
...
...
@@ -21,7 +21,7 @@
import
sys
from
django.db
import
models
from
django.db.models
import
Q
from
django.utils.encoding
import
force_
unicode
from
django.utils.encoding
import
force_
text
from
weblate.lang.models
import
Language
from
weblate.trans.formats
import
AutoFormat
from
weblate.trans.models.project
import
Project
...
...
@@ -131,7 +131,7 @@ class DictionaryManager(models.Manager):
# Some Whoosh analyzers break on unicode
try
:
words
.
update
(
[
token
.
text
for
token
in
analyzer
(
force_
unicode
(
text
))]
[
token
.
text
for
token
in
analyzer
(
force_
text
(
text
))]
)
except
(
UnicodeDecodeError
,
IndexError
)
as
error
:
report_error
(
error
,
sys
.
exc_info
())
...
...
weblate/trans/search.py
View file @
70748600
...
...
@@ -30,6 +30,7 @@ from whoosh import qparser
from
django.dispatch
import
receiver
from
django.db.models.signals
import
post_migrate
from
django.db.utils
import
IntegrityError
from
django.utils.encoding
import
force_text
from
django.db
import
transaction
from
weblate
import
appsettings
from
weblate.lang.models
import
Language
...
...
@@ -92,10 +93,10 @@ def update_source_unit_index(writer, unit):
Updates source index for given unit.
'''
writer
.
update_document
(
checksum
=
unicode
(
unit
.
checksum
),
source
=
unicode
(
unit
.
source
),
context
=
unicode
(
unit
.
context
),
location
=
unicode
(
unit
.
location
),
checksum
=
force_text
(
unit
.
checksum
),
source
=
force_text
(
unit
.
source
),
context
=
force_text
(
unit
.
context
),
location
=
force_text
(
unit
.
location
),
)
...
...
@@ -104,9 +105,9 @@ def update_target_unit_index(writer, unit):
Updates target index for given unit.
'''
writer
.
update_document
(
checksum
=
unicode
(
unit
.
checksum
),
target
=
unicode
(
unit
.
target
),
comment
=
unicode
(
unit
.
comment
),
checksum
=
force_text
(
unit
.
checksum
),
target
=
force_text
(
unit
.
target
),
comment
=
force_text
(
unit
.
comment
),
)
...
...
weblate/trans/templatetags/translations.py
View file @
70748600
...
...
@@ -23,7 +23,7 @@ from django.utils.html import escape, urlize
from
django.contrib.admin.templatetags.admin_static
import
static
from
django.template.loader
import
render_to_string
from
django.utils.safestring
import
mark_safe
from
django.utils.encoding
import
force_
unicode
from
django.utils.encoding
import
force_
text
from
django.utils.translation
import
ugettext
as
_
,
ungettext
,
ugettext_lazy
from
django.utils
import
timezone
from
django
import
template
...
...
@@ -111,11 +111,11 @@ def format_translation(value, language, diff=None, search_match=None,
for
idx
,
value
in
enumerate
(
plurals
):
# HTML escape
value
=
escape
(
force_
unicode
(
value
))
value
=
escape
(
force_
text
(
value
))
# Format diff if there is any
if
diff
is
not
None
:
diffvalue
=
escape
(
force_
unicode
(
diff
[
idx
]))
diffvalue
=
escape
(
force_
text
(
diff
[
idx
]))
value
=
html_diff
(
diffvalue
,
value
)
# Format search term
...
...
weblate/trans/tests/test_autofix.py
View file @
70748600
...
...
@@ -24,6 +24,7 @@ Tests for automatix fixups.
from
__future__
import
unicode_literals
from
django.test
import
TestCase
from
django.utils.encoding
import
force_text
from
weblate.trans.tests.test_checks
import
MockUnit
from
weblate.trans.autofixes
import
fix_target
from
weblate.trans.autofixes.chars
import
(
...
...
@@ -115,4 +116,4 @@ class AutoFixTest(TestCase):
fixed
,
fixups
=
fix_target
([
'Bar...'
],
unit
)
self
.
assertEqual
(
fixed
,
[
'Bar…'
])
self
.
assertEqual
(
len
(
fixups
),
1
)
self
.
assertEqual
(
unicode
(
fixups
[
0
]),
'Trailing ellipsis'
)
self
.
assertEqual
(
force_text
(
fixups
[
0
]),
'Trailing ellipsis'
)
weblate/trans/tests/test_unitdata.py
View file @
70748600
...
...
@@ -24,6 +24,7 @@ Tests for unitdata models.
from
__future__
import
unicode_literals
from
django.test
import
TestCase
from
django.utils.encoding
import
force_text
from
weblate.lang.models
import
Language
from
weblate.trans.models
import
Check
,
Project
...
...
@@ -45,14 +46,14 @@ class UnitdataTestCase(TestCase):
def
test_check
(
self
):
check
=
self
.
create_check
(
'same'
)
self
.
assertEqual
(
unicode
(
check
.
get_description
()),
force_text
(
check
.
get_description
()),
'Source and translated strings are same'
)
self
.
assertEqual
(
check
.
get_severity
(),
'warning'
)
self
.
assertTrue
(
check
.
get_doc_url
().
endswith
(
'user/checks.html#check-same'
)
)
self
.
assertEqual
(
unicode
(
check
),
'test/Acholi: same'
)
self
.
assertEqual
(
force_text
(
check
),
'test/Acholi: same'
)
def
test_check_nonexisting
(
self
):
check
=
self
.
create_check
(
'-invalid-'
)
...
...
weblate/trans/util.py
View file @
70748600
...
...
@@ -23,6 +23,7 @@ from django.core.cache import cache
from
django.http
import
HttpResponseRedirect
from
django.shortcuts
import
resolve_url
from
django.conf
import
settings
from
django.utils.encoding
import
force_text
from
importlib
import
import_module
import
os
import
sys
...
...
@@ -226,7 +227,7 @@ def report_error(error, exc_info, request=None, extra_data=None):
LOGGER
.
error
(
'Handled exception %s: %s'
,
error
.
__class__
.
__name__
,
unicode
(
error
).
encode
(
'utf-8'
)
force_text
(
error
).
encode
(
'utf-8'
)
)
# Print error when running testsuite
...
...
weblate/trans/views/dictionary.py
View file @
70748600
...
...
@@ -19,6 +19,7 @@
#
from
django.shortcuts
import
render
,
get_object_or_404
,
redirect
from
django.utils.encoding
import
force_text
from
django.utils.translation
import
ugettext
as
_
,
ungettext
from
django.http
import
HttpResponse
,
HttpResponseRedirect
from
django.contrib
import
messages
...
...
@@ -169,7 +170,7 @@ def upload_dictionary(request, project, lang):
except
Exception
as
error
:
report_error
(
error
,
sys
.
exc_info
(),
request
)
messages
.
error
(
request
,
_
(
'File upload has failed: %s'
)
%
unicode
(
error
)
request
,
_
(
'File upload has failed: %s'
)
%
force_text
(
error
)
)
else
:
messages
.
error
(
request
,
_
(
'Failed to process form!'
))
...
...
weblate/trans/views/edit.py
View file @
70748600
...
...
@@ -21,6 +21,7 @@
from
django.shortcuts
import
render
,
get_object_or_404
,
redirect
from
django.views.decorators.http
import
require_POST
from
django.utils.translation
import
ugettext
as
_
from
django.utils.encoding
import
force_text
from
django.http
import
HttpResponseRedirect
,
HttpResponse
from
django.contrib
import
messages
from
django.contrib.auth.decorators
import
login_required
...
...
@@ -161,7 +162,7 @@ def search(translation, request):
search_id
=
str
(
uuid
.
uuid1
())
search_result
=
{
'query'
:
search_query
,
'name'
:
unicode
(
name
)
if
name
else
None
,
'name'
:
force_text
(
name
)
if
name
else
None
,
'ids'
:
unit_ids
,
'search_id'
:
search_id
,
'ttl'
:
int
(
time
.
time
())
+
86400
,
...
...
@@ -238,7 +239,7 @@ def perform_translation(unit, form, request):
messages
.
info
(
request
,
_
(
'Following fixups were applied to translation: %s'
)
%
', '
.
join
([
unicode
(
f
)
for
f
in
fixups
])
', '
.
join
([
force_text
(
f
)
for
f
in
fixups
])
)
# Get new set of checks
...
...
@@ -255,7 +256,7 @@ def perform_translation(unit, form, request):
'Some checks have failed on your translation: {0}'
).
format
(
', '
.
join
(
[
unicode
(
CHECKS
[
check
].
name
)
for
check
in
newchecks
]
[
force_text
(
CHECKS
[
check
].
name
)
for
check
in
newchecks
]
)
)
)
...
...
weblate/trans/views/files.py
View file @
70748600
...
...
@@ -19,6 +19,7 @@
#
from
django.utils.translation
import
ugettext
as
_
,
ungettext
from
django.utils.encoding
import
force_text
from
django.shortcuts
import
redirect
from
django.http
import
HttpResponse
from
django.contrib
import
messages
...
...
@@ -141,7 +142,7 @@ def upload_translation(request, project, subproject, lang):
)
except
Exception
as
error
:
messages
.
error
(
request
,
_
(
'File content merge failed: %s'
)
%
unicode
(
error
)
request
,
_
(
'File content merge failed: %s'
)
%
force_text
(
error
)
)
report_error
(
error
,
sys
.
exc_info
(),
request
)
...
...
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