def edit_router(request, handle_id): # Get needed data from node nh, router = helpers.get_nh_node(handle_id) location = router.get_location() if request.POST: form = forms.EditRouterForm(request.POST) ports_form = forms.BulkPortsForm(request.POST) if form.is_valid() and ports_form.is_valid(): # Generic node update helpers.form_update_node(request.user, router.handle_id, form) # Router specific updates _handle_location(request.user, router, form.cleaned_data['relationship_location']) _handle_ports(router, form.cleaned_data['relationship_ports'], request.user) if not ports_form.cleaned_data['no_ports']: data = ports_form.cleaned_data helpers.bulk_create_ports(nh.get_node(), request.user, **data) if 'saveanddone' in request.POST: return redirect(nh.get_absolute_url()) else: return redirect('%sedit' % nh.get_absolute_url()) else: form = forms.EditRouterForm(router.data) ports_form = forms.BulkPortsForm({'port_type': 'LC', 'offset': 1, 'num_ports': '0'}) return render(request, 'noclook/edit/edit_router.html', {'node_handle': nh, 'node': router, 'form': form, 'location': location, 'ports_form': ports_form})
def new_patch_panel(request, **kwargs): if request.POST: form = forms.NewPatchPannelForm(request.POST) ports_form = forms.BulkPortsForm(request.POST) if form.is_valid() and ports_form.is_valid(): nh = helpers.form_to_generic_node_handle(request, form, 'patch-panel', 'Physical') helpers.form_update_node(request.user, nh.handle_id, form) data = form.cleaned_data node = nh.get_node() if data['relationship_location']: location = NodeHandle.objects.get( pk=data['relationship_location']) helpers.set_location(request.user, node, location.handle_id) if not ports_form.cleaned_data['no_ports']: data = ports_form.cleaned_data helpers.bulk_create_ports(nh.get_node(), request.user, **data) return redirect(nh.get_absolute_url()) else: form = forms.NewPatchPannelForm() ports_form = forms.BulkPortsForm({ 'port_type': 'RJ45', 'offset': 1, 'num_ports': '0' }) return render(request, 'noclook/create/create_patch_panel.html', { 'form': form, 'ports_form': ports_form })
def new_optical_node(request, slug=None): form = forms.OpticalNodeForm(request.POST or None) bulk_ports = forms.BulkPortsForm(request.POST or None) if request.POST and form.is_valid() and bulk_ports.is_valid(): try: name = form.cleaned_data['name'] nh = helpers.create_unique_node_handle(request.user, name, 'optical-node', 'Physical') helpers.form_update_node(request.user, nh.handle_id, form) node = nh.get_node() user = request.user if form.cleaned_data['relationship_location']: location = NodeHandle.objects.get( pk=form.cleaned_data['relationship_location']) helpers.set_location(user, node, location.handle_id) # create ports if needed if not bulk_ports.cleaned_data['no_ports']: data = bulk_ports.cleaned_data helpers.bulk_create_ports(nh.get_node(), request.user, **data) return redirect(nh.get_absolute_url()) except UniqueNodeError: form.add_error('name', 'An Optical Node with that name already exists.') return render(request, 'noclook/create/create_optical_node.html', { 'form': form, 'bulk_ports': bulk_ports })
def edit_pdu(request, handle_id): # Get needed data from node nh, pdu = helpers.get_nh_node(handle_id) location = pdu.get_location() relations = pdu.get_relations() depends_on = pdu.get_dependencies() host_services = pdu.get_host_services() ports = pdu.get_ports() dependency_categories = 'service' ports_form = forms.BulkPortsForm(request.POST or None) if request.POST: form = forms.EditPDUForm(request.POST) if form.is_valid(): # Generic node update helpers.form_update_node(request.user, pdu.handle_id, form) # Host specific updates if form.cleaned_data['relationship_user']: user_nh = NodeHandle.objects.get(pk=form.cleaned_data['relationship_user']) helpers.set_user(request.user, pdu, user_nh.handle_id) if form.cleaned_data['relationship_owner']: owner_nh = NodeHandle.objects.get(pk=form.cleaned_data['relationship_owner']) helpers.set_owner(request.user, pdu, owner_nh.handle_id) # You can not set location and depends on at the same time if form.cleaned_data['relationship_depends_on']: depends_on_nh = NodeHandle.objects.get(pk=form.cleaned_data['relationship_depends_on']) helpers.set_depends_on(request.user, pdu, depends_on_nh.handle_id) elif form.cleaned_data['relationship_location']: _handle_location(request.user, pdu, form.cleaned_data['relationship_location']) if form.cleaned_data['services_locked'] and form.cleaned_data['services_checked']: helpers.remove_rogue_service_marker(request.user, pdu.handle_id) if ports_form.is_valid() and not ports_form.cleaned_data['no_ports']: data = ports_form.cleaned_data helpers.bulk_create_ports(pdu, request.user, **data) _handle_ports(pdu, form.cleaned_data['relationship_ports'], request.user) if 'saveanddone' in request.POST: return redirect(nh.get_absolute_url()) else: return redirect('%sedit' % nh.get_absolute_url()) else: form = forms.EditPDUForm(pdu.data) return render(request, 'noclook/edit/edit_pdu.html', {'node_handle': nh, 'node': pdu, 'form': form, 'location': location, 'relations': relations, 'depends_on': depends_on, 'ports': ports, 'host_services': host_services, 'dependency_categories': dependency_categories, 'ports_form': ports_form})
def new_optical_filter(request, **kwargs): form = forms.NewOpticalFilter(request.POST or None) ports_form = forms.BulkPortsForm(request.POST or None) if request.POST: if form.is_valid() and ports_form.is_valid(): nh = helpers.form_to_generic_node_handle(request, form, 'optical-filter', 'Physical') helpers.form_update_node(request.user, nh.handle_id, form) if not ports_form.cleaned_data['no_ports']: data = ports_form.cleaned_data helpers.bulk_create_ports(nh.get_node(), request.user, **data) return redirect(nh.get_absolute_url()) return render(request, 'noclook/create/create_optical_filter.html', {'form': form, 'ports_form': ports_form})