Beispiel #1
0
def update(request, device):
    device_form = DeviceForm(request.POST)

    uid = device.uid

    if device_form.is_valid():

        try:
            device.name = device_form.cleaned_data['name']
            device.type = device_form.cleaned_data['type']
            device.uid = device_form.cleaned_data['uid'].replace(' ', '-')
            device.full_clean()
            device.save()
            messages.success(request, _('Device updated'))
            uid = device.uid  # accept the new UID after rest has succeeded

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

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

    return HttpResponseRedirect(reverse('device-edit', args=[uid]))
Beispiel #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('devices'))

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

    except ValidationError as e:
        messages.error(request, '; '.join(e.messages))
        return HttpResponseRedirect(reverse('devices'))

    except IntegrityError:
        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]))
Beispiel #3
0
def update(request, device):
    device_form = DeviceForm(request.POST)

    uid = device.uid

    if device_form.is_valid():

        try:
            device.name = device_form.cleaned_data['name']
            device.type = device_form.cleaned_data['type']
            device.uid = device_form.cleaned_data['uid'].replace(' ', '-')
            device.full_clean()
            device.save()
            messages.success(request, _('Device updated'))
            uid = device.uid  # accept the new UID after rest has succeeded

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

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

    return HttpResponseRedirect(reverse('device-edit', args=[uid]))
Beispiel #4
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"))

    try:
        device = Client()
        device.user = request.user
        device.id = uuid.uuid1()
        device.name = device_form.cleaned_data["name"]
        device.type = device_form.cleaned_data["type"]
        device.uid = device_form.cleaned_data["uid"].replace(" ", "-")
        device.full_clean()
        device.save()
        messages.success(request, _("Device saved"))

    except ValidationError as e:
        messages.error(request, "; ".join(e.messages))
        return HttpResponseRedirect(reverse("devices"))

    except IntegrityError:
        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]))
Beispiel #5
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]))
Beispiel #6
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]))
Beispiel #7
0
def update(request, device):
    device_form = DeviceForm(request.POST)

    uid = device.uid

    if device_form.is_valid():

        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 updated'))
            uid = device.uid  # accept the new UID after rest has succeeded

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

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

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