Ejemplo n.º 1
0
def create(request):
    device_form = DeviceForm(request.POST)

    if not device_form.is_valid():
        messages.error(request, _('Please fill out all fields.'))
        return HttpResponseRedirect(reverse('devices'))

    device = Device()
    device.name = device_form.cleaned_data['name']
    device.type = device_form.cleaned_data['type']
    device.uid  = device_form.cleaned_data['uid'].replace(' ', '-')
    try:
        set_device(request.user, device)
        messages.success(request, _('Device saved'))

    except DeviceUIDException as e:
        messages.error(request, _(unicode(e)))
        return HttpResponseRedirect(reverse('devices'))

    except Unauthorized:
        messages.error(request, _("You can't use the same Device "
                   "ID for two devices."))
        return HttpResponseRedirect(reverse('devices'))

    return HttpResponseRedirect(reverse('device-edit', args=[device.uid]))
Ejemplo n.º 2
0
def create(request):
    device_form = DeviceForm(request.POST)

    if not device_form.is_valid():

        messages.error(request, _('Please fill out all fields.'))

        return HttpResponseRedirect(reverse('device-edit-new'))


    device = Device()
    device.name = device_form.cleaned_data['name']
    device.type = device_form.cleaned_data['type']
    device.uid  = device_form.cleaned_data['uid'].replace(' ', '-')
    try:
        request.user.set_device(device)
        request.user.save()
        messages.success(request, _('Device saved'))

    except DeviceUIDException as e:
        messages.error(request, _(str(e)))

        return render(request, 'device-create.html', {
            'device': device,
            'device_form': device_form,
        })

    except:
        messages.error(request, _("You can't use the same Device "
                   "ID for two devices."))

        return render(request, 'device-create.html', {
            'device': device,
            'device_form': device_form,
        })


    return HttpResponseRedirect(reverse('device-edit', args=[device.uid]))