def test_notify_new_translation(self): unit = self.get_unit() unit2 = self.get_translation().unit_set.get(source="Thank you for using Weblate.") notify_new_translation(unit, unit2, self.second_user()) # Check mail self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].subject, "[Weblate] New translation in Test/Test - Czech")
def save_backend(self, request, propagate=True, gen_change=True, change_action=None, user=None): """ Stores unit to backend. Optional user parameters defines authorship of a change. """ # Update lock timestamp self.translation.update_lock(request) # For case when authorship specified, use user from request if user is None: user = request.user # Store to backend try: (saved, pounit) = self.translation.update_unit(self, request, user) except FileLockException: weblate.logger.error('failed to lock backend for %s!', self) messages.error( request, _( 'Failed to store message in the backend, ' 'lock timeout occurred!' ) ) return False # Handle situation when backend did not find the message if pounit is None: weblate.logger.error('message %s disappeared!', self) messages.error( request, _( 'Message not found in backend storage, ' 'it is probably corrupted.' ) ) # Try reloading from backend self.translation.check_sync(True) return False # Get old unit from database (for notifications) oldunit = Unit.objects.get(id=self.id) # Return if there was no change # We have to explicitly check for fuzzy flag change on monolingual # files, where we handle it ourselves without storing to backend if (not saved and oldunit.fuzzy == self.fuzzy and oldunit.target == self.target): # Propagate if we should if propagate: self.propagate(request, change_action) return False # Update translated flag self.translated = pounit.is_translated() # Update comments as they might have been changed (eg, fuzzy flag # removed) self.flags = pounit.get_flags() # Save updated unit to database self.save(backend=True) # Update translation stats old_translated = self.translation.translated self.translation.update_stats() # Notify subscribed users about new translation notify_new_translation(self, oldunit, request.user) # Update user stats user.profile.translated += 1 user.profile.save() # Generate Change object for this change if gen_change: self.generate_change(request, user, oldunit, change_action) # Force commiting on completing translation if (old_translated < self.translation.translated and self.translation.translated == self.translation.total): self.translation.commit_pending(request) Change.objects.create( translation=self.translation, action=Change.ACTION_COMPLETE, user=request.user, author=user ) # Update related source strings if working on a template if self.translation.is_template(): self.update_source_units() # Propagate to other projects if propagate: self.propagate(request, change_action) return True
def save_backend(self, request, propagate=True, gen_change=True, change_action=None, user=None): """ Stores unit to backend. Optional user parameters defines authorship of a change. """ # Update lock timestamp self.translation.update_lock(request) # For case when authorship specified, use user from request if user is None: user = request.user # Store to backend try: (saved, pounit) = self.translation.update_unit(self, request, user) except FileLockException: self.log_error('failed to lock backend for %s!', self) messages.error( request, _('Failed to store message in the backend, ' 'lock timeout occurred!')) return False # Handle situation when backend did not find the message if pounit is None: self.log_error('message %s disappeared!', self) messages.error( request, _('Message not found in backend storage, ' 'it is probably corrupted.')) # Try reloading from backend self.translation.check_sync(True) return False # Get old unit from database (for notifications) oldunit = Unit.objects.get(id=self.id) # Return if there was no change # We have to explicitly check for fuzzy flag change on monolingual # files, where we handle it ourselves without storing to backend if (not saved and oldunit.fuzzy == self.fuzzy and oldunit.target == self.target): # Propagate if we should if propagate: self.propagate(request, change_action) return False # Update translated flag self.translated = pounit.is_translated() # Update comments as they might have been changed (eg, fuzzy flag # removed) self.flags = pounit.get_flags() # Save updated unit to database self.save(backend=True) # Update translation stats old_translated = self.translation.translated self.translation.update_stats() # Notify subscribed users about new translation notify_new_translation(self, oldunit, request.user) # Update user stats user.profile.translated += 1 user.profile.save() # Generate Change object for this change if gen_change: self.generate_change(request, user, oldunit, change_action) # Force commiting on completing translation if (old_translated < self.translation.translated and self.translation.translated == self.translation.total): self.translation.commit_pending(request) Change.objects.create(translation=self.translation, action=Change.ACTION_COMPLETE, user=request.user, author=user) # Update related source strings if working on a template if self.translation.is_template(): self.update_source_units() # Propagate to other projects if propagate: self.propagate(request, change_action) return True