class Book(models.Model):
""" A document edited on the wiki """
- title = models.CharField(_('title'), max_length=255)
- slug = models.SlugField(_('slug'), max_length=128, unique=True)
+ title = models.CharField(_('title'), max_length=255, db_index=True)
+ slug = models.SlugField(_('slug'), max_length=128, unique=True, db_index=True)
gallery = models.CharField(_('scan gallery name'), max_length=255, blank=True)
parent = models.ForeignKey('self', null=True, blank=True, verbose_name=_('parent'), related_name="children")
parent_number = models.IntegerField(_('parent number'), null=True, blank=True, db_index=True)
- last_published = models.DateTimeField(null=True, editable=False)
-
- _list_html = models.TextField(editable=False, null=True)
+ last_published = models.DateTimeField(null=True, editable=False, db_index=True)
class NoTextError(BaseException):
pass
def get_absolute_url(self):
return reverse("wiki_book", args=[self.slug])
- def save(self, reset_list_html=True, *args, **kwargs):
- if reset_list_html:
- self._list_html = None
- return super(Book, self).save(*args, **kwargs)
-
@classmethod
def create(cls, creator=None, text=u'', *args, **kwargs):
"""
def __getitem__(self, chunk):
return self.chunk_set.all()[chunk]
- def __len__(self):
- return self.chunk_set.count()
-
- def list_html(self):
- if self._list_html is None:
- print 'rendering', self.title
- self._list_html = render_to_string('wiki/document_list_item.html',
- {'book': self})
- self.save(reset_list_html=False)
- return mark_safe(self._list_html)
-
def materialize(self, publishable=True):
"""
Get full text of the document compiled from chunks.
book = models.ForeignKey(Book, editable=False)
number = models.IntegerField()
slug = models.SlugField()
- comment = models.CharField(max_length=255)
+ comment = models.CharField(max_length=255, blank=True)
class Meta:
unique_together = [['book', 'number'], ['book', 'slug']]
else:
return cls.objects.get(book__slug=slug, slug=chunk)
- def pretty_name(self):
- return "%s, %s (%d/%d)" % (self.book.title, self.comment,
- self.number, len(self.book))
+ def pretty_name(self, book_length=None):
+ title = self.book.title
+ if self.comment:
+ title += ", %s" % self.comment
+ if book_length > 1:
+ title += " (%d/%d)" % (self.number, book_length)
+ return title
def split(self, slug, comment='', creator=None):
""" Create an empty chunk after this one """
creator=creator, slug=slug, comment=comment)
return new_chunk
+ def list_html(self):
+ _list_html = render_to_string('wiki/chunk_list_item.html',
+ {'chunk': self})
+ return mark_safe(_list_html)
+
@staticmethod
def listener_saved(sender, instance, created, **kwargs):
if instance.book: