def test_notify_new_string(self): notify_new_string(self.get_translation()) # Check mail self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox[0].subject, '[Weblate] New string to translate in Test/Test - Czech')
def test_notify_new_string(self): notify_new_string(self.get_translation()) # Check mail self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox[0].subject, '[Weblate] New string to translate in Test/Test - Czech' )
def update_from_blob(self, force=False, request=None): ''' Updates translation data from blob. ''' from trans.models.unit import Unit from trans.models.changes import Change # Check if we're not already up to date if self.revision != self.get_git_blob_hash(): weblate.logger.info( 'processing %s in %s, revision has changed', self.filename, self.subproject.__unicode__() ) elif force: weblate.logger.info( 'processing %s in %s, check forced', self.filename, self.subproject.__unicode__() ) else: return # List of created units (used for cleanup and duplicates detection) created_units = set() # Was there change? was_new = False # Position of current unit pos = 1 for unit in self.store.all_units(): if not unit.is_translatable(): continue newunit, is_new = Unit.objects.update_from_unit( self, unit, pos ) # Check if unit is new and untranslated was_new = was_new or (is_new and not newunit.translated) # Update position pos += 1 # Check for possible duplicate units if newunit.id in created_units: weblate.logger.error( 'Duplicate string to translate in %s: %s', self, newunit ) # Store current unit ID created_units.add(newunit.id) # Get lists of stale units to delete units_to_delete = self.unit_set.exclude( id__in=created_units ) # We need to resolve this now as otherwise list will become empty after # delete deleted_checksums = list( units_to_delete.values_list('checksum', flat=True) ) # Actually delete units units_to_delete.delete() # Cleanup checks for deleted units self.cleanup_deleted(deleted_checksums) # Update revision and stats self.update_stats() # Cleanup checks cache if there were some deleted units if len(deleted_checksums) > 0: self.invalidate_cache() # Store change entry if request is None: user = None else: user = request.user Change.objects.create( translation=self, action=Change.ACTION_UPDATE, user=user ) # Notify subscribed users if was_new: from accounts.models import notify_new_string notify_new_string(self)
def update_from_blob(self, force=False, request=None): ''' Updates translation data from blob. ''' from trans.models.unit import Unit from trans.models.changes import Change # Check if we're not already up to date if self.revision != self.get_git_blob_hash(): weblate.logger.info('processing %s in %s, revision has changed', self.filename, self.subproject.__unicode__()) elif force: weblate.logger.info('processing %s in %s, check forced', self.filename, self.subproject.__unicode__()) else: return # List of created units (used for cleanup and duplicates detection) created_units = set() # Was there change? was_new = False # Position of current unit pos = 1 for unit in self.store.all_units(): if not unit.is_translatable(): continue newunit, is_new = Unit.objects.update_from_unit(self, unit, pos) # Check if unit is new and untranslated was_new = was_new or (is_new and not newunit.translated) # Update position pos += 1 # Check for possible duplicate units if newunit.id in created_units: weblate.logger.error('Duplicite string to translate in %s: %s', self, newunit) # Store current unit ID created_units.add(newunit.id) # Get lists of stale units to delete units_to_delete = self.unit_set.exclude(id__in=created_units) # We need to resolve this now as otherwise list will become empty after # delete deleted_checksums = list( units_to_delete.values_list('checksum', flat=True)) # Actually delete units units_to_delete.delete() # Cleanup checks for deleted units self.cleanup_deleted(deleted_checksums) # Update revision and stats self.update_stats() # Cleanup checks cache if there were some deleted units if len(deleted_checksums) > 0: self.invalidate_cache() # Store change entry if request is None: user = None else: user = request.user Change.objects.create(translation=self, action=Change.ACTION_UPDATE, user=user) # Notify subscribed users if was_new: from accounts.models import notify_new_string notify_new_string(self)