Exemplo n.º 1
0
def fpcommand_edit(request, uuid=None):
    if uuid:
        fpcommand = get_object_or_404(fprmodels.FPCommand, uuid=uuid)
        title = _('Replace command %(name)s') % {'name': fpcommand.description}
    else:
        fpcommand = None
        title = _('Create format version')
    if request.method == 'POST':
        form = fprforms.FPCommandForm(request.POST, instance=fpcommand)
        if form.is_valid():
            # save command
            new_fpcommand = form.save(commit=False)
            new_fpcommand.command = new_fpcommand.command.replace('\r\n', '\n')
            # Handle replacing previous rule and setting enabled/disabled
            replaces = utils.determine_what_replaces_model_instance(
                fprmodels.FPCommand, fpcommand)
            new_fpcommand.save(replacing=replaces)
            utils.update_references_to_object(fprmodels.FPCommand, 'uuid',
                                              replaces, new_fpcommand)
            messages.info(request, _('Saved.'))
            return redirect('fpcommand_list', new_fpcommand.command_usage)
    else:
        # Set tool to parent if it exists
        initial = {}
        try:
            initial['tool'] = fprmodels.FPTool.objects.get(
                uuid=request.GET['parent'], enabled=True)
        except (KeyError, fprmodels.FPTool.DoesNotExist):
            initial['tool'] = None
        form = fprforms.FPCommandForm(instance=fpcommand, initial=initial)
        utils.warn_if_replacing_with_old_revision(request, fpcommand)

    return render(request, 'fpr/fpcommand/form.html', context(locals()))
Exemplo n.º 2
0
def fprule_edit(request, uuid=None):
    if uuid:
        fprule = get_object_or_404(fprmodels.FPRule, uuid=uuid)
        command = fprule.command
        title = _('Replace format policy rule %(uuid)s') % {
            'uuid': fprule.uuid
        }
    else:
        fprule = None
        command = None
        title = _('Create format policy rule')
    form = fprforms.FPRuleForm(request.POST or None,
                               instance=fprule,
                               prefix='f')
    fprule_command_form = fprforms.FPCommandForm(request.POST or None,
                                                 instance=command,
                                                 prefix='fc')
    if form.is_valid():
        replaces = utils.determine_what_replaces_model_instance(
            fprmodels.FPRule, fprule)
        if form.cleaned_data[
                'command'] == 'new' and fprule_command_form.is_valid():
            fprule = form.save(commit=False)
            command = fprule_command_form.save()
            fprule.command = command
            fprule.save(replacing=replaces)
            messages.info(request, _('Saved.'))
            return redirect('fprule_detail', fprule.uuid)
        elif form.cleaned_data['command'] != 'new':
            fprule = form.save(commit=False)
            command = fprmodels.FPCommand.objects.get(
                uuid=form.cleaned_data['command'])
            fprule.command = command
            fprule = form.save()
            fprule.save(replacing=replaces)
            messages.info(request, _('Saved.'))
            return redirect('fprule_list')
    else:
        utils.warn_if_replacing_with_old_revision(request, fprule)

    return render(request, 'fpr/fprule/form.html', context(locals()))
Exemplo n.º 3
0
def fprule_edit(request, uuid=None):
    if uuid:
        fprule = get_object_or_404(fprmodels.FPRule, uuid=uuid)
        command = fprule.command
        title = _("Replace format policy rule %(uuid)s") % {
            "uuid": fprule.uuid
        }
    else:
        fprule = None
        command = None
        title = _("Create format policy rule")
    form = fprforms.FPRuleForm(request.POST or None,
                               instance=fprule,
                               prefix="f")
    fprule_command_form = fprforms.FPCommandForm(request.POST or None,
                                                 instance=command,
                                                 prefix="fc")
    if form.is_valid():
        replaces = utils.determine_what_replaces_model_instance(
            fprmodels.FPRule, fprule)
        if form.cleaned_data[
                "command"] == "new" and fprule_command_form.is_valid():
            fprule = form.save(commit=False)
            command = fprule_command_form.save()
            fprule.command = command
            fprule.save(replacing=replaces)
            messages.info(request, _("Saved."))
            return redirect("fprule_detail", fprule.uuid)
        elif form.cleaned_data["command"] != "new":
            fprule = form.save(commit=False)
            command = fprmodels.FPCommand.objects.get(
                uuid=form.cleaned_data["command"])
            fprule.command = command
            fprule = form.save()
            fprule.save(replacing=replaces)
            messages.info(request, _("Saved."))
            return redirect("fprule_list")
    else:
        utils.warn_if_replacing_with_old_revision(request, fprule)

    return render(request, "fpr/fprule/form.html", context(locals()))