Commit 8f00401c authored by Michal Čihař's avatar Michal Čihař

Fix and test changing file format for existing components

We need to rescan files in case we change loader and also the file
format cache needs to be reset in this case.

Fixes #647
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent a229a8ca
......@@ -1143,6 +1143,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
'''
# Detect if VCS config has changed (so that we have to pull the repo)
changed_git = True
changed_setup = False
if self.id:
old = SubProject.objects.get(pk=self.id)
changed_git = (
......@@ -1150,6 +1151,10 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
or (old.branch != self.branch)
or (old.filemask != self.filemask)
)
changed_setup = (
(old.file_format != self.file_format)
or (old.template != self.template)
)
# Detect slug changes and rename git repo
self.check_rename(old)
......@@ -1170,7 +1175,9 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
# Rescan for possibly new translations if there were changes, needs to
# be done after actual creating the object above
if changed_git:
if changed_setup:
self.create_translations(force=True)
elif changed_git:
self.create_translations()
def _get_percents(self):
......@@ -1208,7 +1215,8 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
'''
Returns file format object.
'''
if self._file_format is None:
if (self._file_format is None
or self._file_format.name != self.file_format):
self._file_format = FILE_FORMATS[self.file_format]
return self._file_format
......
......@@ -662,6 +662,18 @@ class SubProjectTest(RepoTestCase):
# With correct format it should validate
subproject.full_clean()
def test_change_to_mono(self):
"""Test swtiching to monolingual format on the fly."""
component = self._create_subproject(
'po',
'po-mono/*.po',
)
self.assertEqual(component.translation_set.count(), 4)
component.file_format = 'po-mono'
component.template = 'po-mono/en.po'
component.save()
self.assertEqual(component.translation_set.count(), 3)
class TranslationTest(RepoTestCase):
"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment