X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/32e632734c0a8390775bb8661edc78c2045cf5f3..4983ea69a6e6c266b0466a851fb4a1ddd27767b4:/src/bookmarks/models.py diff --git a/src/bookmarks/models.py b/src/bookmarks/models.py index 8747ffbd3..ef24e83dc 100644 --- a/src/bookmarks/models.py +++ b/src/bookmarks/models.py @@ -29,21 +29,14 @@ class Bookmark(Syncable, models.Model): return str(self.uuid) def save(self, *args, **kwargs): - # TODO: placeholder. - try: - audio_l = self.book.get_audio_length() - except: - audio_l = 60 - if self.anchor: - self.mode = 'text' - if audio_l: - self.audio_timestamp = audio_l * .4 - if self.audio_timestamp: - self.mode = 'audio' - if self.audio_timestamp > audio_l: - self.audio_timestamp = audio_l - if audio_l: - self.anchor = 'f20' + audio_l = self.book.get_audio_length() + if audio_l: + if self.anchor and self.audio_timestamp is None: + self.mode = 'text' + self.audio_timestamp = self.book.sync_elid(self.anchor) + elif not self.anchor and self.audio_timestamp is not None: + self.mode = 'audio' + self.anchor = self.book.sync_ts(self.audio_timestamp) or '' return super().save(*args, **kwargs) @classmethod @@ -118,7 +111,7 @@ class Bookmark(Syncable, models.Model): } -class Quote(models.Model): +class Quote(Syncable, models.Model): uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False) user = models.ForeignKey('auth.User', models.CASCADE) book = models.ForeignKey('catalogue.Book', models.CASCADE) @@ -128,10 +121,21 @@ class Quote(models.Model): start_offset = models.IntegerField(null=True, blank=True) end_offset = models.IntegerField(null=True, blank=True) text = models.TextField(blank=True) + updated_at = models.DateTimeField(auto_now=True) + reported_timestamp = models.DateTimeField(default=now) + deleted = models.BooleanField(default=False) + + syncable_fields = [ + 'deleted', + ] def __str__(self): return str(self.uuid) + @property + def timestamp(self): + return self.updated_at.timestamp() + def get_for_json(self): return { 'uuid': self.uuid, @@ -154,6 +158,3 @@ def from_path(elem, path): n = path.pop(0) elem = list(child_nodes(elem))[n] return elem - - -