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()))
def idcommand_edit(request, uuid=None): if uuid: idcommand = get_object_or_404(fprmodels.IDCommand, uuid=uuid) title = _('Replace identification command %(name)s') % { 'name': idcommand.description } else: idcommand = None title = _('Create identification command') # Set tool to parent if it exists initial = {} try: initial['tool'] = fprmodels.IDTool.objects.get( uuid=request.GET['parent'], enabled=True) except (KeyError, fprmodels.IDTool.DoesNotExist): initial['tool'] = None form = fprforms.IDCommandForm(request.POST or None, instance=idcommand, initial=initial) if form.is_valid(): new_idcommand = form.save(commit=False) replaces = utils.determine_what_replaces_model_instance( fprmodels.IDCommand, idcommand) new_idcommand.save(replacing=replaces) utils.update_references_to_object(fprmodels.IDCommand, 'uuid', replaces, new_idcommand) messages.info(request, _('Saved.')) return redirect('idcommand_list') else: utils.warn_if_replacing_with_old_revision(request, idcommand) return render(request, 'fpr/idcommand/form.html', context(locals()))
def formatversion_edit(request, format_slug, slug=None): format = get_object_or_404(fprmodels.Format, slug=format_slug) if slug: version = get_object_or_404(fprmodels.FormatVersion, slug=slug, format=format) title = _('Replace format version %(name)s') % { 'name': version.description } else: version = None title = _('Create format version') form = fprforms.FormatVersionForm(request.POST or None, instance=version) if form.is_valid(): # If replacing, disable old one and set replaces info for new one new_version = form.save(commit=False) new_version.format = format replaces = utils.determine_what_replaces_model_instance( fprmodels.FormatVersion, version) new_version.save(replacing=replaces) utils.update_references_to_object(fprmodels.FormatVersion, 'uuid', replaces, new_version) messages.info(request, _('Saved.')) return redirect('format_detail', format.slug) else: utils.warn_if_replacing_with_old_revision(request, version) return render(request, 'fpr/format/version/form.html', context(locals()))
def idrule_edit(request, uuid=None): if uuid: idrule = get_object_or_404(fprmodels.IDRule, uuid=uuid) title = _("Replace identification rule %(uuid)s") % {"uuid": idrule.uuid} else: idrule = None title = _("Create identification rule") form = fprforms.IDRuleForm(request.POST or None, instance=idrule) if form.is_valid(): new_idrule = form.save(commit=False) replaces = utils.determine_what_replaces_model_instance( fprmodels.IDRule, idrule ) new_idrule.save(replacing=replaces) messages.info(request, _("Saved.")) return redirect("idrule_list") else: utils.warn_if_replacing_with_old_revision(request, idrule) return render(request, "fpr/idrule/form.html", context(locals()))
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()))
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()))