2 from django.db import models
5 class Bookmark(models.Model):
6 uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
7 user = models.ForeignKey('auth.User', models.CASCADE)
8 book = models.ForeignKey('catalogue.Book', models.CASCADE)
9 anchor = models.CharField(max_length=100, blank=True)
10 created_at = models.DateTimeField(auto_now_add=True)
11 note = models.TextField(blank=True)
16 def get_for_json(self):
19 'anchor': self.anchor,
21 'created_at': self.created_at,
25 class Quote(models.Model):
26 uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
27 user = models.ForeignKey('auth.User', models.CASCADE)
28 book = models.ForeignKey('catalogue.Book', models.CASCADE)
29 created_at = models.DateTimeField(auto_now_add=True)
30 start_elem = models.CharField(max_length=100, blank=True)
31 end_elem = models.CharField(max_length=100, blank=True)
32 start_offset = models.IntegerField(null=True, blank=True)
33 end_offset = models.IntegerField(null=True, blank=True)
34 text = models.TextField(blank=True)
39 def get_for_json(self):
42 'startElem': self.start_elem,
43 'endElem': self.end_elem,
44 'startOffset': self.start_offset,
45 'startOffset': self.end_offset,
46 'created_at': self.created_at,
49 def from_path(elem, path):
51 if e.text: yield (e, 'text')
53 if child.attrib.get('id') != 'toc':
59 elem = list(child_nodes(elem))[n]