def new(request, from_host=False): """ View to Create a new host. (eventualy copied from an existing one) """ POST = HostForm.filter_querydict(request.user, request.POST) add_fields = None remote_addr = get_request_remote_addr(request) if POST: form = HostForm(request.user, remote_addr, POST) if form.is_valid(): host, add_fields = form.save(POST=POST) redir = POST.get('submit_button', False) if redir == 'new': form = HostForm(request.user, remote_addr) elif redir == 'save': return redirect(host) elif redir == 'return': return redirect('list_hosts') else: if from_host: from_host = get_host_or_404(request.user, pk=from_host) inst, comp = from_host.copy_instance() form = HostForm(request.user, remote_addr, instance=inst) form.log_action(u"consulté", from_host) add_fields = AdditionnalFieldForm(comp, host=inst) else: form = HostForm(request.user, remote_addr) return render_to_response('clariadmin/host.html', { 'form': form, 'prefix': '8', 'additionnal_fields': add_fields}, context_instance=RequestContext(request))
def modify(request, host_id): """ View to modify a Host. """ POST = HostForm.filter_querydict(request.user, request.POST) host = get_host_or_404(request.user, pk=host_id) prefix = str(host_id) if request.is_ajax(): template = "clariadmin/ajax_host.html" else: template = "clariadmin/host.html" remote_addr = get_request_remote_addr(request) add_fields = AdditionnalFieldForm(host=host, prefix=prefix) if POST: form = HostForm(request.user, remote_addr, POST, instance=host, prefix=prefix) if POST.get("delete", False): form.delete() return redirect('list_hosts') if form.is_valid(): host, add_fields = form.save(POST=POST, prefix=prefix) redir = POST.get('submit_button', False) if redir == 'new': return redirect('new_host') elif redir == 'save': pass elif redir == 'return': return redirect('list_hosts') else: form = HostForm(request.user, remote_addr, instance=host, prefix=prefix) form.log_action(u"consulté") return render_to_response(template, { "form": form, 'additionnal_fields': add_fields, 'prefix': prefix, 'ajax': request.is_ajax(), "host": host}, context_instance=RequestContext(request))