def save( self, same_content=False, same_state=False, force_insert=False, force_update=False, using=None, update_fields=None, ): """Wrapper around save to run checks or update fulltext.""" # Store number of words if not same_content or not self.num_words: self.num_words = len(self.get_source_plurals()[0].split()) if update_fields and "num_words" not in update_fields: update_fields.append('num_words') # Actually save the unit super().save( force_insert=force_insert, force_update=force_update, using=using, update_fields=update_fields, ) # Update checks if content or fuzzy flag has changed if not same_content or not same_state: self.run_checks(same_state, same_content) # Update fulltext index if content has changed or this is a new unit if force_insert or not same_content: Fulltext.update_index_unit(self)
def save(self, same_content=False, same_state=False, force_insert=False, backend=False, **kwargs): """ Wrapper around save to warn when save did not come from git backend (eg. commit or by parsing file). """ # Warn if request is not coming from backend if not backend: self.log_error('Unit.save called without backend sync: %s', ''.join(traceback.format_stack())) # Store number of words if not same_content or not self.num_words: self.num_words = len(self.get_source_plurals()[0].split()) # Actually save the unit super(Unit, self).save(**kwargs) # Update checks if content or fuzzy flag has changed if not same_content or not same_state: self.run_checks(same_state, same_content, force_insert) # Update fulltext index if content has changed or this is a new unit if force_insert or not same_content: Fulltext.update_index_unit(self)
def save(self, same_content=False, same_state=False, force_insert=False, backend=False, **kwargs): """ Wrapper around save to warn when save did not come from git backend (eg. commit or by parsing file). """ # Warn if request is not coming from backend if not backend: self.log_error( 'Unit.save called without backend sync: %s', ''.join(traceback.format_stack()) ) # Store number of words if not same_content or not self.num_words: self.num_words = len(self.get_source_plurals()[0].split()) # Actually save the unit super(Unit, self).save(**kwargs) # Update checks if content or fuzzy flag has changed if not same_content or not same_state: self.run_checks(same_state, same_content, force_insert) # Update fulltext index if content has changed or this is a new unit if force_insert or not same_content: Fulltext.update_index_unit(self)
def test_add(self): self.edit_unit( 'Hello, world!\n', 'Nazdar svete!\n' ) unit = self.get_translation().unit_set.get( source='Hello, world!\n', ) Fulltext.update_index_unit(unit) Fulltext.update_index_unit(unit)
def update_source_units(self, previous_source, user): """Update source for units withing same component. This is needed when editing template translation for monolingual formats. """ # Find relevant units same_source = Unit.objects.filter( translation__component=self.translation.component, id_hash=self.id_hash, ).exclude( id=self.id ) # Update source, number of words and content_hash same_source.update( source=self.source, num_words=self.num_words, content_hash=self.content_hash ) # Find reverted units reverted = same_source.filter( state=STATE_FUZZY, previous_source=self.source ) reverted_ids = set(reverted.values_list('id', flat=True)) reverted.update( state=STATE_TRANSLATED, previous_source='' ) # Set fuzzy on changed same_source.filter( state__gte=STATE_TRANSLATED ).exclude( id__in=reverted_ids ).update( state=STATE_FUZZY, previous_source=previous_source, ) # Update source index and stats for unit in same_source.iterator(): unit.update_has_comment() unit.update_has_suggestion() unit.run_checks(False, False) Fulltext.update_index_unit(unit) Change.objects.create( unit=unit, action=Change.ACTION_SOURCE_CHANGE, user=user, author=user, old=previous_source, target=self.source, ) unit.translation.invalidate_cache()
def update_source_units(self, previous_source, user): """Update source for units withing same component. This is needed when editing template translation for monolingual formats. """ # Find relevant units same_source = Unit.objects.filter( translation__component=self.translation.component, id_hash=self.id_hash, ).exclude( id=self.id ) # Update source, number of words and content_hash same_source.update( source=self.source, num_words=self.num_words, content_hash=self.content_hash ) # Find reverted units reverted = same_source.filter( state=STATE_FUZZY, previous_source=self.source ) reverted_ids = set(reverted.values_list('id', flat=True)) reverted.update( state=STATE_TRANSLATED, previous_source='' ) # Set fuzzy on changed same_source.filter( state=STATE_TRANSLATED ).exclude( id__in=reverted_ids ).update( state=STATE_FUZZY, previous_source=previous_source, ) # Update source index and stats for unit in same_source.iterator(): unit.update_has_comment() unit.update_has_suggestion() unit.run_checks(False, False) Fulltext.update_index_unit(unit) Change.objects.create( unit=unit, action=Change.ACTION_SOURCE_CHANGE, user=user, author=user, old=previous_source, target=self.source, ) unit.translation.invalidate_cache()
def save(self, same_content=False, same_state=False, force_insert=False, **kwargs): """Wrapper around save to run checks or update fulltext""" # Store number of words if not same_content or not self.num_words: self.num_words = len(self.get_source_plurals()[0].split()) # Actually save the unit super(Unit, self).save(**kwargs) # Update checks if content or fuzzy flag has changed if not same_content or not same_state: self.run_checks(same_state, same_content) # Update fulltext index if content has changed or this is a new unit if force_insert or not same_content: Fulltext.update_index_unit(self)
def update_source_units(self, previous_source, user, author): """Update source for units withing same component. This is needed when editing template translation for monolingual formats. """ # Find relevant units same_source = Unit.objects.filter( translation__component=self.translation.component, id_hash=self.id_hash).exclude(id=self.id) for unit in same_source.iterator(): # Update source, number of words and content_hash unit.source = self.source unit.num_words = self.num_words unit.content_hash = self.content_hash # Find reverted units if unit.state == STATE_FUZZY and unit.previous_source == self.source: # Unset fuzzy on reverted unit.original_state = unit.state = STATE_TRANSLATED unit.previous_source = '' elif (unit.original_state == STATE_FUZZY and unit.previous_source == self.source): # Unset fuzzy on reverted unit.original_state = STATE_TRANSLATED unit.previous_source = '' elif unit.state >= STATE_TRANSLATED: # Set fuzzy on changed unit.original_state = STATE_FUZZY if unit.state < STATE_READONLY: unit.state = STATE_FUZZY unit.previous_source = previous_source # Update source index and stats unit.update_has_comment() unit.update_has_suggestion() unit.save() Fulltext.update_index_unit(unit) Change.objects.create( unit=unit, action=Change.ACTION_SOURCE_CHANGE, user=user, author=author, old=previous_source, target=self.source, ) unit.translation.invalidate_cache()
def update_source_units(self, previous_source, user): """Update source for units withing same component. This is needed when editing template translation for monolingual formats. """ # Find relevant units same_source = Unit.objects.filter( translation__component=self.translation.component, id_hash=self.id_hash, ).exclude( id=self.id ) for unit in same_source.iterator(): # Update source, number of words and content_hash unit.source = self.source unit.num_words = self.num_words unit.content_hash = self.content_hash # Find reverted units if (unit.state == STATE_FUZZY and unit.previous_source == self.source): # Unset fuzzy on reverted unit.state = STATE_TRANSLATED unit.previous_source = '' elif unit.state >= STATE_TRANSLATED: # Set fuzzy on changed unit.state = STATE_FUZZY unit.previous_source = previous_source # Update source index and stats unit.update_has_comment() unit.update_has_suggestion() unit.save() Fulltext.update_index_unit(unit) Change.objects.create( unit=unit, action=Change.ACTION_SOURCE_CHANGE, user=user, author=user, old=previous_source, target=self.source, ) unit.translation.invalidate_cache()
def save(self, same_content=False, same_state=False, force_insert=False, **kwargs): """ Wrapper around save to warn when save did not come from git backend (eg. commit or by parsing file). """ # Store number of words if not same_content or not self.num_words: self.num_words = len(self.get_source_plurals()[0].split()) # Actually save the unit super(Unit, self).save(**kwargs) # Update checks if content or fuzzy flag has changed if not same_content or not same_state: self.run_checks(same_state, same_content) # Update fulltext index if content has changed or this is a new unit if force_insert or not same_content: Fulltext.update_index_unit(self)