X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/044ee915f89f30b2935dbbcb4a5d5e4a91cbfca9..078017198692badda854eb70f7a5431112aed007:/src/social/models.py diff --git a/src/social/models.py b/src/social/models.py index 0b366fc29..2692538be 100644 --- a/src/social/models.py +++ b/src/social/models.py @@ -16,6 +16,7 @@ from django.utils.timezone import now from catalogue.models import Book from catalogue.utils import get_random_hash from wolnelektury.utils import cached_render, clear_cached_renders +from .syncable import Syncable class BannerGroup(models.Model): @@ -207,44 +208,6 @@ class UserConfirmation(models.Model): ).send() - -class Syncable: - @classmethod - def sync(cls, user, instance, data): - ts = data.get('timestamp') - if ts is None: - ts = now() - else: - ts = datetime.fromtimestamp(ts, tz=utc) - - if instance is not None: - if ts and ts < instance.reported_timestamp: - return - - if instance is None: - if data.get('deleted'): - return - instance = cls.create_from_data(user, data) - if instance is None: - return - - instance.reported_timestamp = ts - for f in cls.syncable_fields: - if f in data: - setattr(instance, f, data[f]) - - instance.save() - return instance - - @property - def timestamp(self): - return self.updated_at.timestamp() - - @classmethod - def create_from_data(cls, user, data): - raise NotImplementedError - - class Progress(Syncable, models.Model): user = models.ForeignKey(User, models.CASCADE) book = models.ForeignKey('catalogue.Book', models.CASCADE)