コード例 #1
0
def add_network_equipment(request):

    if request.method == 'POST':
        request.POST = request.POST.copy()
        request.POST.update({
            'DEV-device_id': request.POST.get('uuid'),
            'DEV-is_dynamic': request.POST.get('is_dynamic'),
            'DEV-is_deleted': request.POST.get('is_deleted'),
            'DEV-type': '1',
        })

        form = NetworkEquipmentForm(model=NetworkEquipment, data=request.POST)
        ex_form = DeviceForm(model=Device, prefix='DEV', data=request.POST)
        if form.is_valid() and ex_form.is_valid():
            try:
                new_device = ex_form.save()
            except IntegrityError, e:
                pass
            new_network_equipment = form.save()
            return HttpResponseRedirect(reverse('cmdb:list_network_equipment'))
コード例 #2
0
ファイル: physical_server.py プロジェクト: znavy/django-aops
def add_physical_server(request):

    if request.method == 'POST':
        print 'Request.Post:', request.POST
        request.POST = request.POST.copy()
        request.POST.update({
            'DEV-device_id':request.POST.get('uuid'),
            'DEV-is_dynamic':request.POST.get('is_dynamic'),
            'DEV-is_deleted':request.POST.get('is_deleted'),
            'DEV-type':0,
        })

        form = PhysicalServerForm(model=PhysicalServer, data=request.POST)
        ex_form = DeviceForm(model=Device, prefix='DEV', data=request.POST)
        if form.is_valid() and ex_form.is_valid():
            try :
                new_device = ex_form.save()
            except IntegrityError,e:
                pass
            new_physical_server = form.save()
            return HttpResponseRedirect(reverse('cmdb:list_physical_server'))
コード例 #3
0
def edit_network_equipment(request, network_equipment_id):
    network_equipment = get_object_or_404(NetworkEquipment,
                                          pk=network_equipment_id)
    if network_equipment:
        device_qset = Device.objects.filter(type=1,
                                            device_id=network_equipment.uuid)
        device = device_qset[0] if len(device_qset) >= 1 else None
    if request.method == 'POST':
        request.POST = request.POST.copy()
        request.POST.update({
            'DEV-device_id': request.POST.get('uuid'),
            'DEV-is_dynamic': request.POST.get('is_dynamic'),
            'DEV-is_deleted': request.POST.get('is_deleted'),
            'DEV-type': 1,
        })

        form = NetworkEquipmentForm(model=NetworkEquipment,
                                    instance=network_equipment,
                                    data=request.POST)
        if device:
            ex_form = DeviceForm(model=Device,
                                 prefix='DEV',
                                 instance=device,
                                 data=request.POST)
        else:
            ex_form = DeviceForm(model=Device, prefix='DEV', data=request.POST)

        if form.is_valid() and ex_form.is_valid():
            try:
                new_device = ex_form.save()
            except IntegrityError, e:
                pass
            new_network_equipment = form.save()
            return HttpResponseRedirect(reverse('cmdb:list_network_equipment'))
コード例 #4
0
ファイル: physical_server.py プロジェクト: znavy/django-aops
def edit_physical_server(request, physical_server_id):
    physical_server = get_object_or_404(PhysicalServer, pk=physical_server_id)
    if physical_server:
        device_qset = Device.objects.filter(type=0, device_id=physical_server.uuid)
        device = device_qset[0] if len(device_qset) >=1 else None
    if request.method == 'POST':
        request.POST = request.POST.copy()
        request.POST.update({
            'DEV-device_id':request.POST.get('uuid'),
            'DEV-is_dynamic':request.POST.get('is_dynamic'),
            'DEV-is_deleted':request.POST.get('is_deleted'),
            'DEV-type':'0',
        })

        form = PhysicalServerForm(model=PhysicalServer, instance=physical_server, data=request.POST)
        if device:
            ex_form = DeviceForm(model=Device, prefix='DEV', instance=device, data=request.POST)
        else:
            ex_form = DeviceForm(model=Device, prefix='DEV', data=request.POST)

        if form.is_valid() and ex_form.is_valid():
            try :
                new_device = ex_form.save()
            except IntegrityError,e:
                pass
            new_physical_server = form.save()
            return HttpResponseRedirect(reverse('cmdb:list_physical_server'))
コード例 #5
0
ファイル: device.py プロジェクト: znavy/django-aops
def add_device(request):
    if request.method == 'POST':
        form = DeviceForm(model=Device, data=request.POST)
        if form.is_valid():
            new_device = form.save()
            return HttpResponseRedirect(reverse('cmdb:list_device'))
    else:
        form = DeviceForm(model=Device)
    app = app_info()
    app['location'] = 'add'
    return render_to_response('add_data.html', {
        'form': form,
        'app': app
    },
                              context_instance=RequestContext(request))
コード例 #6
0
        })

        form = NetworkEquipmentForm(model=NetworkEquipment, data=request.POST)
        ex_form = DeviceForm(model=Device, prefix='DEV', data=request.POST)
        if form.is_valid() and ex_form.is_valid():
            try:
                new_device = ex_form.save()
            except IntegrityError, e:
                pass
            new_network_equipment = form.save()
            return HttpResponseRedirect(reverse('cmdb:list_network_equipment'))

    else:
        form = NetworkEquipmentForm(model=NetworkEquipment)
        ex_form = DeviceForm(model=Device,
                             prefix='DEV',
                             initial={'type': 'physical server'})

    app = app_info()
    app['location'] = 'add'
    m2m_fs = NetworkEquipment._meta.many_to_many
    m2m_list = []
    for m2m_f in m2m_fs:
        if m2m_f.name in form.fields.keys():
            m2m_list.append(m2m_f.name)
    return render_to_response('add_data.html', {
        'form': form,
        'ex_form': ex_form,
        'app': app,
        'm2m_list': m2m_list
    },