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 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 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()))