mirror of
https://github.com/Hopiu/django-modeltranslation.git
synced 2026-04-17 11:41:01 +00:00
Further work towards Python 3 support.
This commit is contained in:
parent
69f6bfc75f
commit
b7ea1fac4c
5 changed files with 18 additions and 16 deletions
|
|
@ -90,7 +90,7 @@ class TranslationBaseModelAdmin(BaseModelAdmin):
|
|||
Returns a new list with replaced fields. If `option` contains no
|
||||
registered fields, it is returned unmodified.
|
||||
|
||||
>>> print self.trans_opts.fields.keys()
|
||||
>>> print(self.trans_opts.fields.keys())
|
||||
['title',]
|
||||
>>> get_translation_fields(self.trans_opts.fields.keys()[0])
|
||||
['title_de', 'title_en']
|
||||
|
|
|
|||
|
|
@ -13,22 +13,23 @@ from django.conf import settings
|
|||
from django.core.management.base import NoArgsCommand
|
||||
from django.core.management.color import no_style
|
||||
from django.db import connection, transaction
|
||||
from django.utils.six import moves
|
||||
|
||||
from modeltranslation.translator import translator
|
||||
from modeltranslation.utils import build_localized_fieldname
|
||||
|
||||
|
||||
def ask_for_confirmation(sql_sentences, model_full_name):
|
||||
print '\nSQL to synchronize "%s" schema:' % model_full_name
|
||||
print('\nSQL to synchronize "%s" schema:' % model_full_name)
|
||||
for sentence in sql_sentences:
|
||||
print ' %s' % sentence
|
||||
print(' %s' % sentence)
|
||||
while True:
|
||||
prompt = '\nAre you sure that you want to execute the previous SQL: (y/n) [n]: '
|
||||
answer = raw_input(prompt).strip()
|
||||
answer = moves.input(prompt).strip()
|
||||
if answer == '':
|
||||
return False
|
||||
elif answer not in ('y', 'n', 'yes', 'no'):
|
||||
print 'Please answer yes or no'
|
||||
print('Please answer yes or no')
|
||||
elif answer == 'y' or answer == 'yes':
|
||||
return True
|
||||
else:
|
||||
|
|
@ -36,8 +37,8 @@ def ask_for_confirmation(sql_sentences, model_full_name):
|
|||
|
||||
|
||||
def print_missing_langs(missing_langs, field_name, model_name):
|
||||
print 'Missing languages in "%s" field from "%s" model: %s' % (
|
||||
field_name, model_name, ", ".join(missing_langs))
|
||||
print('Missing languages in "%s" field from "%s" model: %s' % (
|
||||
field_name, model_name, ", ".join(missing_langs)))
|
||||
|
||||
|
||||
class Command(NoArgsCommand):
|
||||
|
|
@ -66,17 +67,17 @@ class Command(NoArgsCommand):
|
|||
sql_sentences = self.get_sync_sql(field_name, missing_langs, model)
|
||||
execute_sql = ask_for_confirmation(sql_sentences, model_full_name)
|
||||
if execute_sql:
|
||||
print 'Executing SQL...',
|
||||
print('Executing SQL...')
|
||||
for sentence in sql_sentences:
|
||||
self.cursor.execute(sentence)
|
||||
print 'Done'
|
||||
print('Done')
|
||||
else:
|
||||
print 'SQL not executed'
|
||||
print('SQL not executed')
|
||||
|
||||
transaction.commit_unless_managed()
|
||||
|
||||
if not found_missing_fields:
|
||||
print 'No new translatable fields detected'
|
||||
print('No new translatable fields detected')
|
||||
|
||||
def get_table_fields(self, db_table):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -127,7 +127,8 @@ class MultilingualQuerySet(models.query.QuerySet):
|
|||
c.field = self.model._meta.get_field(new_name)
|
||||
c.col = c.field.column
|
||||
if isinstance(q, Node):
|
||||
map(self._rewrite_where, q.children)
|
||||
for child in q.children:
|
||||
self._rewrite_where(child)
|
||||
|
||||
def _rewrite_order(self):
|
||||
self.query.order_by = [rewrite_order_lookup_key(self.model, field_name)
|
||||
|
|
@ -139,7 +140,7 @@ class MultilingualQuerySet(models.query.QuerySet):
|
|||
if isinstance(q, tuple) and len(q) == 2:
|
||||
return rewrite_lookup_key(self.model, q[0]), q[1]
|
||||
if isinstance(q, Node):
|
||||
q.children = map(self._rewrite_q, q.children)
|
||||
q.children = list(map(self._rewrite_q, q.children))
|
||||
return q
|
||||
|
||||
# This method was not present in django-linguo
|
||||
|
|
@ -151,7 +152,7 @@ class MultilingualQuerySet(models.query.QuerySet):
|
|||
q.name = rewrite_lookup_key(self.model, q.name)
|
||||
return q
|
||||
if isinstance(q, Node):
|
||||
q.children = map(self._rewrite_f, q.children)
|
||||
q.children = list(map(self._rewrite_f, q.children))
|
||||
return q
|
||||
|
||||
def _filter_or_exclude(self, negate, *args, **kwargs):
|
||||
|
|
|
|||
|
|
@ -256,7 +256,7 @@ class ModeltranslationTest(ModeltranslationTestBase):
|
|||
|
||||
def test_verbose_name(self):
|
||||
verbose_name = models.TestModel._meta.get_field('title_de').verbose_name
|
||||
self.assertEquals(six.text_type(verbose_name), u'title [de]')
|
||||
self.assertEqual(six.text_type(verbose_name), 'title [de]')
|
||||
|
||||
def test_descriptor_introspection(self):
|
||||
# See Django #8248
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ def build_localized_fieldname(field_name, lang):
|
|||
|
||||
|
||||
def _build_localized_verbose_name(verbose_name, lang):
|
||||
return u'%s [%s]' % (force_text(verbose_name), lang)
|
||||
return force_text('%s [%s]') % (force_text(verbose_name), lang)
|
||||
build_localized_verbose_name = lazy(_build_localized_verbose_name, six.text_type)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue