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,7 +52,13 @@ class BaseExporter(object):
name = ''
has_lang = False
def __init__(self, project, language, url):
def __init__(self, project=None, language=None, url=None,
translation=None):
if translation is not None:
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
......@@ -72,6 +78,10 @@ class BaseExporter(object):
unit.target = word.target
self.storage.addunit(unit)
def add_units(self, translation):
for unit intranslation .unit_set.iterator():
self.add_unit(unit)
def add_unit(self, unit):
if unit.is_plural():
output = self.storage.UnitClass(
......
......@@ -41,16 +41,11 @@ def download_translation_format(request, project, subproject, lang, fmt):
obj = get_translation(request, project, subproject, lang)
try:
exporter = get_exporter(fmt)(
obj.subproject.project,
obj.language,
obj.get_absolute_url()
)
exporter = get_exporter(fmt)(translation=obj)
except KeyError:
raise Http404('File format not supported')
for unit in obj.unit_set.iterator():
exporter.add_unit(unit)
exporter.add_units(obj)
# Save to 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