Exemple #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'))

    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]))
Exemple #2
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]))
Exemple #3
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]))
Exemple #4
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]))
Exemple #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]))
Exemple #6
0
def edit(request, device):

    device_form = DeviceForm({
        'name': device.name,
        'type': device.type,
        'uid': device.uid
    })

    synced_with = device.synced_with()

    sync_targets = list(device.get_sync_targets())
    sync_form = SyncForm()
    sync_form.set_targets(sync_targets,
                          _('Synchronize with the following devices'))

    return render(
        request,
        'device-edit.html',
        {
            'device': device,
            'device_form': device_form,
            'sync_form': sync_form,
            'synced_with': synced_with,
            'has_sync_targets': len(sync_targets) > 0,
        },
    )
Exemple #7
0
def edit(request, device):

    device_form = DeviceForm({
        "name": device.name,
        "type": device.type,
        "uid": device.uid
    })

    synced_with = device.synced_with()

    sync_targets = list(device.get_sync_targets())
    sync_form = SyncForm()
    sync_form.set_targets(sync_targets,
                          _("Synchronize with the following devices"))

    return render(
        request,
        "device-edit.html",
        {
            "device": device,
            "device_form": device_form,
            "sync_form": sync_form,
            "synced_with": synced_with,
            "has_sync_targets": len(sync_targets) > 0,
        },
    )
Exemple #8
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]))
Exemple #9
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]))
Exemple #10
0
def overview(request):

    user = UserProxy.objects.from_user(request.user)
    device_groups = user.get_grouped_devices()
    deleted_devices = Client.objects.filter(user=request.user, deleted=True)

    # create a "default" device
    device = Client()
    device_form = DeviceForm({
        'name': device.name,
        'type': device.type,
        'uid': device.uid
        })

    return render(request, 'devicelist.html', {
        'device_groups': list(device_groups),
        'deleted_devices': list(deleted_devices),
        'device_form': device_form,
    })
Exemple #11
0
def overview(request):

    user = UserProxy.objects.from_user(request.user)
    device_groups = user.get_grouped_devices()
    deleted_devices = Client.objects.filter(user=request.user, deleted=True)

    # create a "default" device
    device = Client()
    device_form = DeviceForm(
        {"name": device.name, "type": device.type, "uid": device.uid}
    )

    return render(
        request,
        "devicelist.html",
        {
            "device_groups": list(device_groups),
            "deleted_devices": list(deleted_devices),
            "device_form": device_form,
        },
    )