Esempio n. 1
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,
        },
    )
Esempio n. 2
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,
        },
    )
Esempio n. 3
0
def show(request, device):

    subscriptions = list(device.get_subscribed_podcasts())
    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.html', {
        'device': device,
        'sync_form': sync_form,
        'subscriptions': subscriptions,
        'synced_with': synced_with,
        'has_sync_targets': len(sync_targets) > 0,
    })
Esempio n. 4
0
def sync(request, device):

    form = SyncForm(request.POST)
    if not form.is_valid():
        return HttpResponseBadRequest('invalid')

    try:
        target_uid = form.get_target()
        sync_target = request.user.client_set.get(uid=target_uid)
        device.sync_with(sync_target)

    except Client.DoesNotExist as e:
        messages.error(request, str(e))

    sync_user.delay(request.user)

    return HttpResponseRedirect(reverse('device', args=[device.uid]))
Esempio n. 5
0
def show(request, device):

    subscriptions = list(device.get_subscribed_podcasts().prefetch_related("slugs"))
    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.html",
        {
            "device": device,
            "sync_form": sync_form,
            "subscriptions": subscriptions,
            "synced_with": synced_with,
            "has_sync_targets": len(sync_targets) > 0,
        },
    )