Get default template extracted to new method.

This commit refs #24068.
This commit is contained in:
José Antonio Díaz Miralles 2022-08-30 18:29:58 +02:00
parent 56ef2316e4
commit ab5555e144
1 changed files with 5 additions and 2 deletions

View File

@ -238,6 +238,10 @@ class EdocumentFileManager(object):
class EdocumentExportMixin(object):
def _default_template_path(self, message_type):
return os.path.join(os.path.dirname(__file__),
'template', message_type.lower() + '.txt')
def _write_file(self, file_path, file, encoding='utf-8'):
edi_file = open(file_path, 'w+', encoding=encoding)
edi_file.write(file)
@ -253,8 +257,7 @@ class EdocumentExportMixin(object):
if templates:
return templates[0].template, templates[0].encoding
else:
template_path = os.path.join(os.path.dirname(__file__),
'template', message_type.lower() + '.txt')
template_path = self._default_template_path(message_type)
with open(template_path) as file:
template = file.read()
return template, 'utf-8'