Example #1
0
def device_add(request):
    if request.method == "POST":
        form = DeviceForm(request.POST)
        if form.is_valid():
            device = form.save()
            return HttpResponseRedirect(
                "%s?new" % reverse("devices:device_data_object_list", kwargs={"device_slug": device.slug})
            )
    else:
        form = DeviceForm()

    return direct_to_template(request, "devices/device_add.html", {"form": form})
Example #2
0
def device_add(request):
    if request.method == 'POST':
        form = DeviceForm(request.POST)
        if form.is_valid():
            device = form.save()
            return HttpResponseRedirect(
                '%s?new' % reverse('devices:device_data_object_list',
                                   kwargs={
                                       'device_slug': device.slug,
                                   }))
    else:
        form = DeviceForm()

    return direct_to_template(request, 'devices/device_add.html',
                              {'form': form})
Example #3
0
def device_edit(request, device_slug=None):
    device = None
    if device_slug is not None:
        device = get_object_or_404(Device, slug=device_slug)

    if request.method == "POST":
        form = DeviceForm(request.POST, instance=device)
        if form.is_valid():
            # Note "device" will be None if creating a new Device
            saved_device = form.save()
            return HttpResponseRedirect(reverse("devices:device_detail", kwargs={"device_slug": saved_device.slug}))
    else:
        form = DeviceForm(instance=device)

    return direct_to_template(request, "devices/device_edit.html", {"form": form})
Example #4
0
def device_edit(request, device_slug=None):
    device = None
    if device_slug is not None:
        device = get_object_or_404(Device, slug=device_slug)

    if request.method == 'POST':
        form = DeviceForm(request.POST, instance=device)
        if form.is_valid():
            # Note "device" will be None if creating a new Device
            saved_device = form.save()
            return HttpResponseRedirect(
                reverse('devices:device_detail',
                        kwargs={
                            'device_slug': saved_device.slug,
                        }))
    else:
        form = DeviceForm(instance=device)

    return direct_to_template(request, 'devices/device_edit.html', {
        'form': form,
    })