def bulk_edit(request, project, component=None, lang=None): obj, unit_set, context = parse_url(request, project, component, lang) if not request.user.has_perm('translation.auto', obj): raise PermissionDenied() form = BulkEditForm(request.user, obj, request.POST, project=context['project']) if not form.is_valid(): messages.error(request, _('Failed to process form!')) show_form_errors(request, form) return redirect(obj) target_state = int(form.cleaned_data['state']) add_flags = Flags(form.cleaned_data['add_flags']) remove_flags = Flags(form.cleaned_data['remove_flags']) add_labels = form.cleaned_data['add_labels'] remove_labels = form.cleaned_data['remove_labels'] matching = unit_set.search(form.cleaned_data['q']) updated = 0 with transaction.atomic(): for unit in matching.select_for_update(): if not request.user.has_perm('unit.edit', unit): continue if target_state != -1 and unit.state: unit.translate( request.user, unit.target, target_state, change_action=Change.ACTION_MASS_STATE, ) updated += 1 if add_flags or remove_flags: flags = Flags(unit.source_info.extra_flags) flags.merge(add_flags) flags.remove(remove_flags) unit.source_info.extra_flags = flags.format() unit.source_info.save(update_fields=['extra_flags']) updated += 1 if add_labels: unit.source_info.labels.add(*add_labels) updated += 1 if remove_labels: unit.source_info.labels.remove(*remove_labels) updated += 1 import_message( request, updated, _('Bulk edit completed, no strings were updated.'), ungettext( 'Bulk edit completed, %d string was updated.', 'Bulk edit completed, %d strings were updated.', updated, ), ) return redirect(obj)
def bulk_edit(request, project, component=None, lang=None): obj, unit_set, context = parse_url(request, project, component, lang) if not request.user.has_perm("translation.auto", obj): raise PermissionDenied() form = BulkEditForm(request.user, obj, request.POST, project=context["project"]) if not form.is_valid(): messages.error(request, _("Failed to process form!")) show_form_errors(request, form) return redirect(obj) updated = bulk_perform( request.user, unit_set, query=form.cleaned_data["q"], target_state=form.cleaned_data["state"], add_flags=form.cleaned_data["add_flags"], remove_flags=form.cleaned_data["remove_flags"], add_labels=form.cleaned_data["add_labels"], remove_labels=form.cleaned_data["remove_labels"], project=context["project"], components=context["components"], ) import_message( request, updated, _("Bulk edit completed, no strings were updated."), ngettext( "Bulk edit completed, %d string was updated.", "Bulk edit completed, %d strings were updated.", updated, ), ) return redirect(obj)
def bulk_edit(request, project, component=None, lang=None): obj, unit_set, context = parse_url(request, project, component, lang) if not request.user.has_perm('translation.auto', obj): raise PermissionDenied() form = BulkEditForm(request.user, obj, request.POST, project=context['project']) if not form.is_valid(): messages.error(request, _('Failed to process form!')) show_form_errors(request, form) return redirect(obj) updated = bulk_perform( request.user, unit_set, query=form.cleaned_data['q'], target_state=form.cleaned_data['state'], add_flags=form.cleaned_data['add_flags'], remove_flags=form.cleaned_data['remove_flags'], add_labels=form.cleaned_data['add_labels'], remove_labels=form.cleaned_data['remove_labels'], ) import_message( request, updated, _('Bulk edit completed, no strings were updated.'), ngettext( 'Bulk edit completed, %d string was updated.', 'Bulk edit completed, %d strings were updated.', updated, ), ) return redirect(obj)