def auto_translation(request, project, subproject, lang): translation = get_translation(request, project, subproject, lang) project = translation.subproject.project if not can_automatic_translation(request.user, project): raise PermissionDenied() autoform = AutoForm(translation, request.user, request.POST) if translation.subproject.locked or not autoform.is_valid(): messages.error(request, _('Failed to process form!')) return redirect(translation) updated = auto_translate(request.user, translation, autoform.cleaned_data['subproject'], autoform.cleaned_data['inconsistent'], autoform.cleaned_data['overwrite']) import_message( request, updated, _('Automatic translation completed, no strings were updated.'), ungettext('Automatic translation completed, %d string was updated.', 'Automatic translation completed, %d strings were updated.', updated)) return redirect(translation)
def handle(self, *args, **options): # Get translation object translation = self.get_translation(**options) # Get user try: user = User.objects.get(username=options['user']) Profile.objects.get_or_create(user=user) except User.DoesNotExist: raise CommandError('User does not exist!') if options['source']: parts = options['source'].split('/') if len(parts) != 2: raise CommandError('Invalid source component specified!') try: subproject = SubProject.objects.get( project__slug=parts[0], slug=parts[1], ) except SubProject.DoesNotExist: raise CommandError('No matching source component found!') source = subproject.id else: source = '' result = auto_translate( user, translation, source, options['inconsistent'], options['overwrite'] ) self.stdout.write('Updated {0} units'.format(result))
def auto_translation(request, project, subproject, lang): translation = get_translation(request, project, subproject, lang) project = translation.subproject.project if not can_automatic_translation(request.user, project): raise PermissionDenied() autoform = AutoForm(translation, request.user, request.POST) if translation.subproject.locked or not autoform.is_valid(): messages.error(request, _('Failed to process form!')) return redirect(translation) updated = auto_translate( request.user, translation, autoform.cleaned_data['subproject'], autoform.cleaned_data['inconsistent'], autoform.cleaned_data['overwrite'] ) import_message( request, updated, _('Automatic translation completed, no strings were updated.'), ungettext( 'Automatic translation completed, %d string was updated.', 'Automatic translation completed, %d strings were updated.', updated ) ) return redirect(translation)
def handle(self, *args, **options): # Check params if len(args) != 3: raise CommandError('Invalid number of parameters!') # Get translation object translation = self.get_translation(args) # Get user try: user = User.objects.get(username=options['user']) except User.DoesNotExist: raise CommandError('User does not exist!') if options['source']: parts = options['source'].split('/') if len(parts) != 2: raise CommandError('Invalid source component specified!') try: subproject = SubProject.objects.get( project__slug=parts[0], slug=parts[1], ) except SubProject.DoesNotExist: raise CommandError('No matching source component found!') source = subproject.id else: source = '' result = auto_translate(user, translation, source, options['inconsistent'], options['overwrite']) self.stdout.write('Updated {0} units'.format(result))