Skip to content

Commit

Permalink
Merge pull request #249 from nephila/feature/force_i18n
Browse files Browse the repository at this point in the history
Force i18n if multiple languages is provided
  • Loading branch information
yakky committed Apr 20, 2016
2 parents e348012 + a3419c3 commit 61ec183
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 15 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ History
++++++++++++++++++

* Force language codes to lowercase
* Force i18n if multiple languages is provided

0.8.7 (2016-02-23)
++++++++++++++++++
Expand Down
6 changes: 5 additions & 1 deletion djangocms_installer/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def parse(args):
help='Database configuration (in URL format)')
parser.add_argument('--i18n', '-i', dest='i18n', action='store',
choices=('yes', 'no'),
default='yes', help='Activate Django I18N / L10N setting')
default='yes', help='Activate Django I18N / L10N setting; this is '
'automatically activated if more than '
'language is provided')
parser.add_argument('--use-tz', '-z', dest='use_timezone', action='store',
choices=('yes', 'no'),
default='yes', help='Activate Django timezone support')
Expand Down Expand Up @@ -217,6 +219,8 @@ def parse(args):
args.languages = args.languages[0].split(',')

args.languages = [lang.strip().lower() for lang in args.languages]
if len(args.languages) > 1:
args.i18n = 'yes'
args.aldryn = False

# Convert version to numeric format for easier checking
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _warn_node(self, msg, node):
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx',
'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.pngmath',
'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.imgmath',
'sphinx.ext.ifconfig', 'sphinx.ext.viewcode']

# Add any paths that contain templates here, relative to this directory.
Expand Down
66 changes: 58 additions & 8 deletions tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_cli_config(self):
else:
self.assertEqual(conf_data.cms_version, 3.2)
self.assertEqual(conf_data.django_version, 1.8)
self.assertEqual(conf_data.i18n, 'no')
self.assertEqual(conf_data.i18n, 'yes')
self.assertEqual(conf_data.reversion, 'no')
self.assertEqual(conf_data.permissions, 'no')
self.assertEqual(conf_data.use_timezone, 'no')
Expand Down Expand Up @@ -106,7 +106,7 @@ def test_cli_config(self):

self.assertEqual(str(conf_data.cms_version), cms_version)
self.assertEqual(str(conf_data.django_version), dj_version)
self.assertEqual(conf_data.i18n, 'no')
self.assertEqual(conf_data.i18n, 'yes')
self.assertEqual(conf_data.reversion, 'no')
self.assertEqual(conf_data.permissions, 'no')
self.assertEqual(conf_data.use_timezone, 'no')
Expand All @@ -116,6 +116,41 @@ def test_cli_config(self):
self.assertEqual(conf_data.db, 'postgres://user:pwd@host/dbname')
self.assertEqual(conf_data.db_driver, 'psycopg2')

if sys.version_info < (3, 0):
dj_version = '1.4'
cms_version = '3.0'
else:
dj_version = '1.8'
cms_version = '3.1'
conf_data = config.parse([
'-q',
'--db=postgres://user:pwd@host/dbname',
'--cms-version=stable',
'--django-version={0}'.format(dj_version),
'--cms-version={0}'.format(cms_version),
'--i18n=no',
'--reversion=no',
'--permissions=no',
'--use-tz=no',
'-tEurope/Rome',
'-len',
'-p' + self.project_dir,
'example_prj'])

self.assertEqual(conf_data.project_name, 'example_prj')

self.assertEqual(str(conf_data.cms_version), cms_version)
self.assertEqual(str(conf_data.django_version), dj_version)
self.assertEqual(conf_data.i18n, 'no')
self.assertEqual(conf_data.reversion, 'no')
self.assertEqual(conf_data.permissions, 'no')
self.assertEqual(conf_data.use_timezone, 'no')
self.assertEqual(conf_data.timezone, 'Europe/Rome')
self.assertEqual(conf_data.languages, ['en'])
self.assertEqual(conf_data.project_directory, self.project_dir)
self.assertEqual(conf_data.db, 'postgres://user:pwd@host/dbname')
self.assertEqual(conf_data.db_driver, 'psycopg2')

def test_version_mismatch(self):
with self.assertRaises(SystemExit):
conf_data = config.parse([
Expand Down Expand Up @@ -603,6 +638,17 @@ def test_starting_page(self):
'example_prj'])
self.assertTrue(conf_data.starting_page)

def test_auto_i18n(self):
"""
Verify setting automatic i18n support if multiple languages
"""
conf_data = config.parse([
'-q', '-len,de'
'--i18n=no',
'-p' + self.project_dir,
'example_prj'])
self.assertTrue(conf_data.i18n)

def test_utc(self):
"""
Verify handling UTC default
Expand Down Expand Up @@ -784,17 +830,16 @@ def test_parse_config_file(self, *args):
self.unused(config_data)
self.assertEqual(self.config_fixture, config_data)

fixture = copy.copy(self.config_fixture)
test_data = [
('config-02.ini', 'db', 'postgres://user:pwd@host:54321/dbname'),
('config-03.ini', 'i18n', 'no'),
('config-04.ini', 'use_timezone', 'no'),
('config-05.ini', 'timezone', 'Europe/London'),
('config-06.ini', 'reversion', 'no'),
('config-07.ini', 'permissions', 'no'),
('config-08.ini', 'languages', ['en', 'ru']),
('config-09.ini', 'django_version', 1.8),
('config-10.ini', 'i18n', 'no'),
('config-08.ini', None, (('i18n', 'no'), ('languages', ['ru']))),
('config-09.ini', None, (('i18n', 'yes'), ('languages', ['en', 'ru']))),
('config-10.ini', 'django_version', 1.8),
('config-11.ini', 'project_directory', '/test/me'),
('config-12.ini', 'bootstrap', True),
('config-13.ini', 'templates', '.'),
Expand All @@ -816,10 +861,15 @@ def test_parse_config_file(self, *args):
('config-29.ini', 'apphooks_reload', True),
('config-30.ini', 'verbose', True),
]
fixture = copy.copy(self.config_fixture)
if sys.version_info < (2, 7):
test_data[7] = ('config-09b.ini', 'django_version', 1.6)
test_data[8] = ('config-10b.ini', 'django_version', 1.6)
for filename, key, val in test_data:
setattr(fixture, key, val) # Change value.
if type(val) == tuple:
for subkey, subval in val:
setattr(fixture, subkey, subval) # Change value.
else:
setattr(fixture, key, val) # Change value.
args = self.args[0:1] + [self.conf(filename)] + self.args[1:] # Load new config.
config_data = config.parse(args)
self.unused(config_data)
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/configs/config-08.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use-tz = no
timezone = Europe/London
reversion = no
permissions = no
languages = en,ru
languages = ru
django-version = stable
cms-version = stable
cms-version = 3.2
parent-dir = .
bootstrap = no
templates = no
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/configs/config-09.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ timezone = Europe/London
reversion = no
permissions = no
languages = en,ru
django-version = 1.8
django-version = stable
cms-version = stable
parent-dir = .
bootstrap = no
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/configs/config-10.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ timezone = Europe/London
reversion = no
permissions = no
languages = en,ru
django-version = stable
cms-version = 3.2
django-version = 1.8
cms-version = stable
parent-dir = .
bootstrap = no
templates = no
Expand Down
File renamed without changes.

0 comments on commit 61ec183

Please sign in to comment.