Commit b9e95a3f authored by Michal Čihař's avatar Michal Čihař

Move more exporter logic to the exporter class

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent b1a7a745
...@@ -52,10 +52,16 @@ class BaseExporter(object): ...@@ -52,10 +52,16 @@ class BaseExporter(object):
name = '' name = ''
has_lang = False has_lang = False
def __init__(self, project, language, url): def __init__(self, project=None, language=None, url=None,
self.project = project translation=None):
self.language = language if translation is not None:
self.url = url self.project = translation.subproject.project
self.langauge = obj.language
self.url = obj.get_absolute_url()
else:
self.project = project
self.language = language
self.url = url
self.storage = self.get_storage() self.storage = self.get_storage()
self.storage.setsourcelanguage(project.source_language.code) self.storage.setsourcelanguage(project.source_language.code)
self.storage.settargetlanguage(language.code) self.storage.settargetlanguage(language.code)
...@@ -72,6 +78,10 @@ class BaseExporter(object): ...@@ -72,6 +78,10 @@ class BaseExporter(object):
unit.target = word.target unit.target = word.target
self.storage.addunit(unit) self.storage.addunit(unit)
def add_units(self, translation):
for unit intranslation .unit_set.iterator():
self.add_unit(unit)
def add_unit(self, unit): def add_unit(self, unit):
if unit.is_plural(): if unit.is_plural():
output = self.storage.UnitClass( output = self.storage.UnitClass(
......
...@@ -41,16 +41,11 @@ def download_translation_format(request, project, subproject, lang, fmt): ...@@ -41,16 +41,11 @@ def download_translation_format(request, project, subproject, lang, fmt):
obj = get_translation(request, project, subproject, lang) obj = get_translation(request, project, subproject, lang)
try: try:
exporter = get_exporter(fmt)( exporter = get_exporter(fmt)(translation=obj)
obj.subproject.project,
obj.language,
obj.get_absolute_url()
)
except KeyError: except KeyError:
raise Http404('File format not supported') raise Http404('File format not supported')
for unit in obj.unit_set.iterator(): exporter.add_units(obj)
exporter.add_unit(unit)
# Save to response # Save to response
return exporter.get_response( return exporter.get_response(
......
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