Commit 6ce12151 authored by Michal Čihař's avatar Michal Čihař

Share logic for loading template with class validation

parent d738075b
...@@ -792,10 +792,9 @@ class SubProject(models.Model): ...@@ -792,10 +792,9 @@ class SubProject(models.Model):
)) ))
# Validate template # Validate template
if self.template != '': if self.has_template():
template = self.get_template_filename()
try: try:
self.file_format_cls.load(template) self.load_template_store()
except ValueError: except ValueError:
raise ValidationError(_('Format of translation template could not be recognized.')) raise ValidationError(_('Format of translation template could not be recognized.'))
except Exception as e: except Exception as e:
...@@ -807,6 +806,9 @@ class SubProject(models.Model): ...@@ -807,6 +806,9 @@ class SubProject(models.Model):
pass pass
def get_template_filename(self): def get_template_filename(self):
'''
Creates absolute filename for template.
'''
return os.path.join(self.get_path(), self.template) return os.path.join(self.get_path(), self.template)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
...@@ -911,6 +913,14 @@ class SubProject(models.Model): ...@@ -911,6 +913,14 @@ class SubProject(models.Model):
''' '''
return self.file_format_cls.mark_fuzzy return self.file_format_cls.mark_fuzzy
def load_template_store(self):
'''
Loads translate-toolkit store for template.
'''
return self.file_format_cls.load(
self.get_template_filename(),
)
def get_template_store(self): def get_template_store(self):
''' '''
Gets translate-toolkit store for template. Gets translate-toolkit store for template.
...@@ -920,9 +930,7 @@ class SubProject(models.Model): ...@@ -920,9 +930,7 @@ class SubProject(models.Model):
return None return None
if self._template_store is None: if self._template_store is None:
self._template_store = self.file_format_cls.load( self._template_store = self.load_template_store()
self.get_template_filename(),
)
return self._template_store return self._template_store
......
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