Exemple #1
0
def update_sync_status(user, synclist, stopsync):
    """ Updates the current Device Sync status

    Synchronisation between devices can be set up and stopped.  Devices are
    identified by their UIDs. Unknown UIDs cause errors, no new devices are
    created. """

    for devlist in synclist:

        if len(devlist) <= 1:
            raise ValueError("at least two devices are needed to sync")

        # Setup all devices to sync with the first in the list
        uid = devlist[0]
        dev = user.client_set.get(uid=uid)

        for other_uid in devlist[1:]:
            other = user.get_device_by_uid(other_uid)
            dev.sync_with(other)

    for uid in stopsync:
        dev = user.get_device_by_uid(uid)
        try:
            dev.stop_sync()
        except ValueError:
            # if all devices of a sync-group are un-synced,
            # the last one will raise a ValueError, because it is no longer
            # being synced -- we just ignore it
            pass

    user.save()

    sync_user.delay(user)
def update_sync_status(user, synclist, stopsync):
    """Updates the current Device Sync status

    Synchronisation between devices can be set up and stopped.  Devices are
    identified by their UIDs. Unknown UIDs cause errors, no new devices are
    created."""

    for devlist in synclist:

        if len(devlist) <= 1:
            raise ValueError("at least two devices are needed to sync")

        # Setup all devices to sync with the first in the list
        uid = devlist[0]
        dev = user.client_set.get(uid=uid)

        for other_uid in devlist[1:]:
            other = user.client_set.get(uid=other_uid)
            dev.sync_with(other)

    for uid in stopsync:
        dev = user.client_set.get(uid=uid)
        try:
            dev.stop_sync()
        except ValueError:
            # if all devices of a sync-group are un-synced,
            # the last one will raise a ValueError, because it is no longer
            # being synced -- we just ignore it
            pass

    user.save()

    sync_user.delay(user)
Exemple #3
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]))
Exemple #4
0
def sync(request, device):

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


    @repeat_on_conflict(['user'])
    def do_sync(user, device, sync_target):
        user.sync_devices(device, sync_target)
        user.save()


    try:
        target_uid = form.get_target()
        sync_target = request.user.get_device_by_uid(target_uid)
        do_sync(user=request.user, device=device, sync_target=sync_target)

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

    sync_user.delay(request.user)

    return HttpResponseRedirect(reverse('device', args=[device.uid]))
Exemple #5
0
def sync_user_on_subscription(sender, **kwargs):
    """ synchronizes the user after one of his subscriptions has changed """
    user = kwargs['user']
    sync_user.delay(user)
Exemple #6
0
def resync(request, device):
    """ Manually triggers a re-sync of a client """
    sync_user.delay(request.user)
    messages.success(request,
                     _('Your subscription will be updated in a moment.'))
    return HttpResponseRedirect(reverse('device', args=[device.uid]))