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

Provide more generic iterator all_units

Various filtering should be done at user place as these will be
different anyway for each purpose.
parent 5cb33347
......@@ -363,35 +363,23 @@ class FileFormat(object):
'''
self.store.save()
def translatable_units(self):
def all_units(self):
'''
Generator of translatable units.
Generator of all units.
'''
if not self.has_template:
for tt_unit in self.store.units:
# Create wrapper object
unit = FileUnit(tt_unit)
# We care only about translatable strings
if not unit.is_translatable():
continue
yield unit
yield FileUnit(tt_unit)
else:
for template_unit in self.template_store.units:
# Create wrapper object (not translated)
unit = FileUnit(None, template_unit)
# We care only about translatable strings
if not unit.is_translatable():
continue
# Get translated unit (if it exists)
unit.unit = self.store.findid(template_unit.getid())
yield unit
yield FileUnit(
self.store.findid(template_unit.getid()),
template_unit
)
@property
def mimetype(self):
......
......@@ -442,7 +442,10 @@ class Translation(models.Model):
# Position of current unit
pos = 1
for unit in self.store.translatable_units():
for unit in self.store.all_units():
if not unit.is_translatable():
continue
newunit, is_new = Unit.objects.update_from_unit(
self, unit, pos
)
......@@ -996,10 +999,10 @@ class Translation(models.Model):
'''
from trans.models.unitdata import Suggestion
ret = False
for unit in store.translatable_units():
for unit in store.all_units():
# Skip headers or not translated
if not unit.is_translated():
if not unit.is_translatable() or not unit.is_translated():
continue
# Indicate something new
......
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