From 51c1b6e43721497c36f2a7e78a3a889dabd68f82 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stefan=20K=C3=B6gl?= Date: Fri, 12 Sep 2014 22:21:20 +0200 Subject: [PATCH] [Sync] fix subscription sync between clients --- mygpo/users/models.py | 13 +++++++------ mygpo/users/tasks.py | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/mygpo/users/models.py b/mygpo/users/models.py index a3123a5e..33ba63e0 100644 --- a/mygpo/users/models.py +++ b/mygpo/users/models.py @@ -318,6 +318,7 @@ class SyncGroup(models.Model): def sync(self): """ Sync the group, ie bring all members up-to-date """ + from mygpo.subscriptions import subscribe # get all subscribed podcasts podcasts = set(self.get_subscribed_podcasts()) @@ -329,7 +330,7 @@ class SyncGroup(models.Model): subscribe(podcast, self.user, client) def get_subscribed_podcasts(self): - return Podcast.objects.filter(subscription__device__sync_group=self) + return Podcast.objects.filter(subscription__client__sync_group=self) def get_missing_podcasts(self, client, all_podcasts): """ the podcasts required to bring the device to the group's state """ @@ -411,13 +412,13 @@ class Client(UUIDModel, DeleteableModel): self.save() elif self.sync_group is not None: - self.sync_group = other.sync_group - self.save() - - elif other.sync_group is not None: other.sync_group = self.sync_group other.save() + elif other.sync_group is not None: + self.sync_group = other.sync_group + self.save() + def stop_sync(self): """ Stop synchronisation with other clients """ sg = self.sync_group @@ -447,7 +448,7 @@ class Client(UUIDModel, DeleteableModel): user = UserProxy.objects.from_user(self.user) for group in user.get_grouped_devices(): - if self in group.devices: + if self in group.devices and group.is_synced: # the device's group can't be a sync-target continue diff --git a/mygpo/users/tasks.py b/mygpo/users/tasks.py index bb397b85..9a2e251f 100644 --- a/mygpo/users/tasks.py +++ b/mygpo/users/tasks.py @@ -7,6 +7,7 @@ from django.contrib.auth import get_user_model from django.conf import settings from mygpo.celery import celery +from mygpo.users.models import SyncGroup from celery.utils.log import get_task_logger logger = get_task_logger(__name__) -- 2.11.4.GIT